3 final class AlmanacManagementTrustKeyWorkflow
4 extends AlmanacManagementWorkflow
{
6 protected function didConstruct() {
9 ->setSynopsis(pht('Mark a public key as trusted.'))
15 'help' => pht('ID of the key to trust.'),
20 public function execute(PhutilArgumentParser
$args) {
21 $console = PhutilConsole
::getConsole();
23 $id = $args->getArg('id');
25 throw new PhutilArgumentUsageException(
26 pht('Specify a public key to trust with --id.'));
29 $key = id(new PhabricatorAuthSSHKeyQuery())
30 ->setViewer($this->getViewer())
34 throw new PhutilArgumentUsageException(
35 pht('No public key exists with ID "%s".', $id));
38 if (!$key->getIsActive()) {
39 throw new PhutilArgumentUsageException(
40 pht('Public key "%s" is not an active key.', $id));
43 if ($key->getIsTrusted()) {
44 throw new PhutilArgumentUsageException(
45 pht('Public key with ID %s is already trusted.', $id));
48 if (!($key->getObject() instanceof AlmanacDevice
)) {
49 throw new PhutilArgumentUsageException(
50 pht('You can only trust keys associated with Almanac devices.'));
53 $handle = id(new PhabricatorHandleQuery())
54 ->setViewer($this->getViewer())
55 ->withPHIDs(array($key->getObject()->getPHID()))
59 "**<bg:red> %s </bg>**\n\n%s\n\n%s\n\n%s",
63 'Trusting a public key gives anyone holding the corresponding '.
64 'private key complete, unrestricted access to all data. The '.
65 'private key will be able to sign requests that bypass policy and '.
69 'This is an advanced feature which should normally be used only '.
70 'when building a cluster. This feature is very dangerous if '.
72 pht('This key is associated with device "%s".', $handle->getName()));
75 'Really trust this key?');
76 if (!phutil_console_confirm($prompt)) {
77 throw new PhutilArgumentUsageException(
78 pht('User aborted workflow.'));
81 $key->setIsTrusted(1);
84 PhabricatorAuthSSHKeyQuery
::deleteSSHKeyCache();
87 "**<bg:green> %s </bg>** %s\n",
89 pht('Key %s has been marked as trusted.', $id));