Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / auth / revoker / PhabricatorAuthSSHRevoker.php
blob3e6b8623704f91cecb51d08a12bf1e2706703cd6
1 <?php
3 final class PhabricatorAuthSSHRevoker
4 extends PhabricatorAuthRevoker {
6 const REVOKERKEY = 'ssh';
8 public function getRevokerName() {
9 return pht('SSH Keys');
12 public function getRevokerDescription() {
13 return pht(
14 "Revokes all SSH public keys.\n\n".
15 "SSH public keys are revoked, not just removed. Users will need to ".
16 "generate and upload new, unique keys before they can access ".
17 "repositories or other services over SSH.");
20 public function revokeAllCredentials() {
21 $query = new PhabricatorAuthSSHKeyQuery();
22 return $this->revokeWithQuery($query);
25 public function revokeCredentialsFrom($object) {
26 $query = id(new PhabricatorAuthSSHKeyQuery())
27 ->withObjectPHIDs(array($object->getPHID()));
29 return $this->revokeWithQuery($query);
32 private function revokeWithQuery(PhabricatorAuthSSHKeyQuery $query) {
33 $viewer = $this->getViewer();
35 // We're only going to revoke keys which have not already been revoked.
37 $ssh_keys = $query
38 ->setViewer($viewer)
39 ->withIsActive(true)
40 ->execute();
42 $content_source = PhabricatorContentSource::newForSource(
43 PhabricatorDaemonContentSource::SOURCECONST);
45 $auth_phid = id(new PhabricatorAuthApplication())->getPHID();
46 foreach ($ssh_keys as $ssh_key) {
47 $xactions = array();
48 $xactions[] = $ssh_key->getApplicationTransactionTemplate()
49 ->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_DEACTIVATE)
50 ->setNewValue(1);
52 $editor = $ssh_key->getApplicationTransactionEditor()
53 ->setActor($viewer)
54 ->setActingAsPHID($auth_phid)
55 ->setContinueOnNoEffect(true)
56 ->setContinueOnMissingFields(true)
57 ->setContentSource($content_source)
58 ->setIsAdministrativeEdit(true)
59 ->applyTransactions($ssh_key, $xactions);
62 return count($ssh_keys);