1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 17:30:59 +01:00

Improve passphrase.query

Summary: Fixes T8070. Fixes T8071. Modernizes passphrase.query to support "order".

Test Plan:
  - Saw description in results.
  - Queried for destroyed credentials with "needSecrets=true".
  - Used "order".

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: mikn, epriestley

Maniphest Tasks: T8070, T8071

Differential Revision: https://secure.phabricator.com/D12715
This commit is contained in:
epriestley 2015-05-05 15:59:44 -07:00
parent 84d0f1c41f
commit a5402c46b2

View file

@ -11,13 +11,17 @@ final class PassphraseQueryConduitAPIMethod
return pht('Query credentials.');
}
public function newQueryObject() {
return new PassphraseCredentialQuery();
}
protected function defineParamTypes() {
return array(
'ids' => 'optional list<int>',
'phids' => 'optional list<phid>',
'needSecrets' => 'optional bool',
'needPublicKeys' => 'optional bool',
) + $this->getPagerParamTypes();
);
}
protected function defineReturnType() {
@ -25,8 +29,7 @@ final class PassphraseQueryConduitAPIMethod
}
protected function execute(ConduitAPIRequest $request) {
$query = id(new PassphraseCredentialQuery())
->setViewer($request->getUser());
$query = $this->newQueryForRequest($request);
if ($request->getValue('ids')) {
$query->withIDs($request->getValue('ids'));
@ -58,14 +61,22 @@ final class PassphraseQueryConduitAPIMethod
$credential);
}
$material = array();
$secret = null;
if ($request->getValue('needSecrets')) {
if ($credential->getAllowConduit()) {
$secret = $credential->getSecret()->openEnvelope();
$secret = $credential->getSecret();
if ($secret) {
$secret = $secret->openEnvelope();
} else {
$material['destroyed'] = pht(
'The private material for this credential has been '.
'destroyed.');
}
}
}
$material = array();
switch ($credential->getCredentialType()) {
case PassphraseCredentialTypeSSHPrivateKeyFile::CREDENTIAL_TYPE:
if ($secret) {
@ -93,8 +104,8 @@ final class PassphraseQueryConduitAPIMethod
if (!$credential->getAllowConduit()) {
$material['noAPIAccess'] = pht(
'This credential\'s private material '.
'is not accessible via API calls.');
'This private material for this credential is not accessible via '.
'API calls.');
}
$results[$credential->getPHID()] = array(
@ -102,6 +113,7 @@ final class PassphraseQueryConduitAPIMethod
'phid' => $credential->getPHID(),
'type' => $credential->getCredentialType(),
'name' => $credential->getName(),
'description' => $credential->getDescription(),
'uri' =>
PhabricatorEnv::getProductionURI('/'.$credential->getMonogram()),
'monogram' => $credential->getMonogram(),