Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/management/AlmanacManagementUntrustKeyWorkflow.php
12256 views
1
<?php
2
3
final class AlmanacManagementUntrustKeyWorkflow
4
extends AlmanacManagementWorkflow {
5
6
protected function didConstruct() {
7
$this
8
->setName('untrust-key')
9
->setSynopsis(pht('Revoke trust of a public key.'))
10
->setArguments(
11
array(
12
array(
13
'name' => 'id',
14
'param' => 'id',
15
'help' => pht('ID of the key to revoke trust for.'),
16
),
17
));
18
}
19
20
public function execute(PhutilArgumentParser $args) {
21
$console = PhutilConsole::getConsole();
22
23
$id = $args->getArg('id');
24
if (!$id) {
25
throw new PhutilArgumentUsageException(
26
pht('Specify a public key to revoke trust for with --id.'));
27
}
28
29
$key = id(new PhabricatorAuthSSHKeyQuery())
30
->setViewer($this->getViewer())
31
->withIDs(array($id))
32
->executeOne();
33
if (!$key) {
34
throw new PhutilArgumentUsageException(
35
pht('No public key exists with ID "%s".', $id));
36
}
37
38
if (!$key->getIsTrusted()) {
39
throw new PhutilArgumentUsageException(
40
pht('Public key with ID %s is not trusted.', $id));
41
}
42
43
$key->setIsTrusted(0);
44
$key->save();
45
46
PhabricatorAuthSSHKeyQuery::deleteSSHKeyCache();
47
48
$console->writeOut(
49
"**<bg:green> %s </bg>** %s\n",
50
pht('TRUST REVOKED'),
51
pht('Trust has been revoked for public key %s.', $id));
52
}
53
54
}
55
56