mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-04 11:51:02 +01:00
Add auth.querypublickeys to retrieve public keys
Summary: Fixes T6484. I primarily need this to synchronize device public keys in the Phabricator cluster so the new stuff in T2783 works. Although, actually, maybe I don't really need it. But I wrote it anyway and it's desirable to have sooner or later. Test Plan: Ran method. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6484 Differential Revision: https://secure.phabricator.com/D11163
This commit is contained in:
parent
b701313e0e
commit
a7814b071c
3 changed files with 100 additions and 0 deletions
|
@ -1333,6 +1333,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorAuthApplication' => 'applications/auth/application/PhabricatorAuthApplication.php',
|
'PhabricatorAuthApplication' => 'applications/auth/application/PhabricatorAuthApplication.php',
|
||||||
'PhabricatorAuthAuthFactorPHIDType' => 'applications/auth/phid/PhabricatorAuthAuthFactorPHIDType.php',
|
'PhabricatorAuthAuthFactorPHIDType' => 'applications/auth/phid/PhabricatorAuthAuthFactorPHIDType.php',
|
||||||
'PhabricatorAuthAuthProviderPHIDType' => 'applications/auth/phid/PhabricatorAuthAuthProviderPHIDType.php',
|
'PhabricatorAuthAuthProviderPHIDType' => 'applications/auth/phid/PhabricatorAuthAuthProviderPHIDType.php',
|
||||||
|
'PhabricatorAuthConduitAPIMethod' => 'applications/auth/conduit/PhabricatorAuthConduitAPIMethod.php',
|
||||||
'PhabricatorAuthConfirmLinkController' => 'applications/auth/controller/PhabricatorAuthConfirmLinkController.php',
|
'PhabricatorAuthConfirmLinkController' => 'applications/auth/controller/PhabricatorAuthConfirmLinkController.php',
|
||||||
'PhabricatorAuthController' => 'applications/auth/controller/PhabricatorAuthController.php',
|
'PhabricatorAuthController' => 'applications/auth/controller/PhabricatorAuthController.php',
|
||||||
'PhabricatorAuthDAO' => 'applications/auth/storage/PhabricatorAuthDAO.php',
|
'PhabricatorAuthDAO' => 'applications/auth/storage/PhabricatorAuthDAO.php',
|
||||||
|
@ -1379,6 +1380,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorAuthProviderConfigQuery' => 'applications/auth/query/PhabricatorAuthProviderConfigQuery.php',
|
'PhabricatorAuthProviderConfigQuery' => 'applications/auth/query/PhabricatorAuthProviderConfigQuery.php',
|
||||||
'PhabricatorAuthProviderConfigTransaction' => 'applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php',
|
'PhabricatorAuthProviderConfigTransaction' => 'applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php',
|
||||||
'PhabricatorAuthProviderConfigTransactionQuery' => 'applications/auth/query/PhabricatorAuthProviderConfigTransactionQuery.php',
|
'PhabricatorAuthProviderConfigTransactionQuery' => 'applications/auth/query/PhabricatorAuthProviderConfigTransactionQuery.php',
|
||||||
|
'PhabricatorAuthQueryPublicKeysConduitAPIMethod' => 'applications/auth/conduit/PhabricatorAuthQueryPublicKeysConduitAPIMethod.php',
|
||||||
'PhabricatorAuthRegisterController' => 'applications/auth/controller/PhabricatorAuthRegisterController.php',
|
'PhabricatorAuthRegisterController' => 'applications/auth/controller/PhabricatorAuthRegisterController.php',
|
||||||
'PhabricatorAuthRevokeTokenController' => 'applications/auth/controller/PhabricatorAuthRevokeTokenController.php',
|
'PhabricatorAuthRevokeTokenController' => 'applications/auth/controller/PhabricatorAuthRevokeTokenController.php',
|
||||||
'PhabricatorAuthSSHKey' => 'applications/auth/storage/PhabricatorAuthSSHKey.php',
|
'PhabricatorAuthSSHKey' => 'applications/auth/storage/PhabricatorAuthSSHKey.php',
|
||||||
|
@ -4551,6 +4553,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorAuthApplication' => 'PhabricatorApplication',
|
'PhabricatorAuthApplication' => 'PhabricatorApplication',
|
||||||
'PhabricatorAuthAuthFactorPHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorAuthAuthFactorPHIDType' => 'PhabricatorPHIDType',
|
||||||
'PhabricatorAuthAuthProviderPHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorAuthAuthProviderPHIDType' => 'PhabricatorPHIDType',
|
||||||
|
'PhabricatorAuthConduitAPIMethod' => 'ConduitAPIMethod',
|
||||||
'PhabricatorAuthConfirmLinkController' => 'PhabricatorAuthController',
|
'PhabricatorAuthConfirmLinkController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorAuthController' => 'PhabricatorController',
|
'PhabricatorAuthController' => 'PhabricatorController',
|
||||||
'PhabricatorAuthDAO' => 'PhabricatorLiskDAO',
|
'PhabricatorAuthDAO' => 'PhabricatorLiskDAO',
|
||||||
|
@ -4599,6 +4602,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorAuthProviderConfigQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorAuthProviderConfigQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhabricatorAuthProviderConfigTransaction' => 'PhabricatorApplicationTransaction',
|
'PhabricatorAuthProviderConfigTransaction' => 'PhabricatorApplicationTransaction',
|
||||||
'PhabricatorAuthProviderConfigTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
'PhabricatorAuthProviderConfigTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||||
|
'PhabricatorAuthQueryPublicKeysConduitAPIMethod' => 'PhabricatorAuthConduitAPIMethod',
|
||||||
'PhabricatorAuthRegisterController' => 'PhabricatorAuthController',
|
'PhabricatorAuthRegisterController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorAuthRevokeTokenController' => 'PhabricatorAuthController',
|
'PhabricatorAuthRevokeTokenController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorAuthSSHKey' => array(
|
'PhabricatorAuthSSHKey' => array(
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class PhabricatorAuthConduitAPIMethod extends ConduitAPIMethod {
|
||||||
|
|
||||||
|
final public function getApplication() {
|
||||||
|
return PhabricatorApplication::getByClass(
|
||||||
|
'PhabricatorAuthApplication');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMethodStatus() {
|
||||||
|
return self::METHOD_STATUS_UNSTABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMethodStatusDescription() {
|
||||||
|
return pht(
|
||||||
|
'These methods are recently introduced and subject to change.');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorAuthQueryPublicKeysConduitAPIMethod
|
||||||
|
extends PhabricatorAuthConduitAPIMethod {
|
||||||
|
|
||||||
|
public function getAPIMethodName() {
|
||||||
|
return 'auth.querypublickeys';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMethodDescription() {
|
||||||
|
return pht('Query public keys.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineParamTypes() {
|
||||||
|
return array(
|
||||||
|
'ids' => 'optional list<id>',
|
||||||
|
'objectPHIDs' => 'optional list<phid>',
|
||||||
|
'keys' => 'optional list<string>',
|
||||||
|
) + self::getPagerParamTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineReturnType() {
|
||||||
|
return 'result-set';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineErrorTypes() {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(ConduitAPIRequest $request) {
|
||||||
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
|
$query = id(new PhabricatorAuthSSHKeyQuery())
|
||||||
|
->setViewer($viewer);
|
||||||
|
|
||||||
|
$ids = $request->getValue('ids');
|
||||||
|
if ($ids !== null) {
|
||||||
|
$query->withIDs($ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
$object_phids = $request->getValue('objectPHIDs');
|
||||||
|
if ($object_phids !== null) {
|
||||||
|
$query->withObjectPHIDs($object_phids);
|
||||||
|
}
|
||||||
|
|
||||||
|
$keys = $request->getValue('keys');
|
||||||
|
if ($keys !== null) {
|
||||||
|
$key_objects = array();
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
$key_objects[] = PhabricatorAuthSSHPublicKey::newFromRawKey($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->withKeys($key_objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pager = $this->newPager($request);
|
||||||
|
$public_keys = $query->executeWithCursorPager($pager);
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
foreach ($public_keys as $public_key) {
|
||||||
|
$data[] = array(
|
||||||
|
'id' => $public_key->getID(),
|
||||||
|
'name' => $public_key->getName(),
|
||||||
|
'objectPHID' => $public_key->getObjectPHID(),
|
||||||
|
'isTrusted' => (bool)$public_key->getIsTrusted(),
|
||||||
|
'key' => $public_key->getEntireKey(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$results = array(
|
||||||
|
'data' => $data,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->addPagerResults($results, $pager);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue