2015-02-10 15:44:21 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorAuthQueryPublicKeysConduitAPIMethod
|
|
|
|
extends PhabricatorAuthConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'auth.querypublickeys';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMethodDescription() {
|
|
|
|
return pht('Query public keys.');
|
|
|
|
}
|
|
|
|
|
2015-04-12 15:59:07 -07:00
|
|
|
protected function defineParamTypes() {
|
2015-02-10 15:44:21 -08:00
|
|
|
return array(
|
|
|
|
'ids' => 'optional list<id>',
|
2015-12-19 11:48:24 -08:00
|
|
|
'phids' => 'optional list<phid>',
|
2015-02-10 15:44:21 -08:00
|
|
|
'objectPHIDs' => 'optional list<phid>',
|
|
|
|
'keys' => 'optional list<string>',
|
|
|
|
) + self::getPagerParamTypes();
|
|
|
|
}
|
|
|
|
|
2015-04-12 15:59:07 -07:00
|
|
|
protected function defineReturnType() {
|
2015-02-10 15:44:21 -08:00
|
|
|
return 'result-set';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$query = id(new PhabricatorAuthSSHKeyQuery())
|
|
|
|
->setViewer($viewer);
|
|
|
|
|
|
|
|
$ids = $request->getValue('ids');
|
|
|
|
if ($ids !== null) {
|
|
|
|
$query->withIDs($ids);
|
|
|
|
}
|
|
|
|
|
2015-12-19 11:48:24 -08:00
|
|
|
$phids = $request->getValue('phids');
|
|
|
|
if ($phids !== null) {
|
|
|
|
$query->withPHIDs($phids);
|
|
|
|
}
|
|
|
|
|
2015-02-10 15:44:21 -08:00
|
|
|
$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(),
|
2015-12-19 11:48:24 -08:00
|
|
|
'phid' => $public_key->getPHID(),
|
2015-02-10 15:44:21 -08:00
|
|
|
'objectPHID' => $public_key->getObjectPHID(),
|
|
|
|
'isTrusted' => (bool)$public_key->getIsTrusted(),
|
|
|
|
'key' => $public_key->getEntireKey(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = array(
|
|
|
|
'data' => $data,
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->addPagerResults($results, $pager);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|