mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +01:00
Allow Almanac devices to have SSH keys
Summary: Ref T5833. Expose a key management interface for Almanac devices. Test Plan: {F231962} Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5833 Differential Revision: https://secure.phabricator.com/D10825
This commit is contained in:
parent
32cdc23efc
commit
af6ffd8c7b
5 changed files with 161 additions and 45 deletions
|
@ -1323,6 +1323,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorAuthSSHKeyEditController' => 'applications/auth/controller/PhabricatorAuthSSHKeyEditController.php',
|
||||
'PhabricatorAuthSSHKeyGenerateController' => 'applications/auth/controller/PhabricatorAuthSSHKeyGenerateController.php',
|
||||
'PhabricatorAuthSSHKeyQuery' => 'applications/auth/query/PhabricatorAuthSSHKeyQuery.php',
|
||||
'PhabricatorAuthSSHKeyTableView' => 'applications/auth/view/PhabricatorAuthSSHKeyTableView.php',
|
||||
'PhabricatorAuthSSHPublicKey' => 'applications/auth/sshkey/PhabricatorAuthSSHPublicKey.php',
|
||||
'PhabricatorAuthSession' => 'applications/auth/storage/PhabricatorAuthSession.php',
|
||||
'PhabricatorAuthSessionEngine' => 'applications/auth/engine/PhabricatorAuthSessionEngine.php',
|
||||
|
@ -3011,6 +3012,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCustomFieldInterface',
|
||||
'PhabricatorApplicationTransactionInterface',
|
||||
'PhabricatorProjectInterface',
|
||||
'PhabricatorSSHPublicKeyInterface',
|
||||
'AlmanacPropertyInterface',
|
||||
),
|
||||
'AlmanacDeviceController' => 'AlmanacController',
|
||||
|
@ -4396,6 +4398,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorAuthSSHKeyEditController' => 'PhabricatorAuthSSHKeyController',
|
||||
'PhabricatorAuthSSHKeyGenerateController' => 'PhabricatorAuthSSHKeyController',
|
||||
'PhabricatorAuthSSHKeyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorAuthSSHKeyTableView' => 'AphrontView',
|
||||
'PhabricatorAuthSSHPublicKey' => 'Phobject',
|
||||
'PhabricatorAuthSession' => array(
|
||||
'PhabricatorAuthDAO',
|
||||
|
|
|
@ -57,6 +57,7 @@ final class AlmanacDeviceViewController
|
|||
$box,
|
||||
$interfaces,
|
||||
$this->buildAlmanacPropertiesTable($device),
|
||||
$this->buildSSHKeysTable($device),
|
||||
$xaction_view,
|
||||
),
|
||||
array(
|
||||
|
@ -141,4 +142,65 @@ final class AlmanacDeviceViewController
|
|||
->appendChild($table);
|
||||
}
|
||||
|
||||
private function buildSSHKeysTable(AlmanacDevice $device) {
|
||||
$viewer = $this->getViewer();
|
||||
$id = $device->getID();
|
||||
$device_phid = $device->getPHID();
|
||||
|
||||
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
||||
$viewer,
|
||||
$device,
|
||||
PhabricatorPolicyCapability::CAN_EDIT);
|
||||
|
||||
$keys = id(new PhabricatorAuthSSHKeyQuery())
|
||||
->setViewer($viewer)
|
||||
->withObjectPHIDs(array($device_phid))
|
||||
->execute();
|
||||
|
||||
$table = id(new PhabricatorAuthSSHKeyTableView())
|
||||
->setUser($viewer)
|
||||
->setKeys($keys)
|
||||
->setCanEdit($can_edit)
|
||||
->setNoDataString(pht('This device has no associated SSH public keys.'));
|
||||
|
||||
try {
|
||||
PhabricatorSSHKeyGenerator::assertCanGenerateKeypair();
|
||||
$can_generate = true;
|
||||
} catch (Exception $ex) {
|
||||
$can_generate = false;
|
||||
}
|
||||
|
||||
$generate_uri = '/auth/sshkey/generate/?objectPHID='.$device_phid;
|
||||
$upload_uri = '/auth/sshkey/upload/?objectPHID='.$device_phid;
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setHeader(pht('SSH Public Keys'))
|
||||
->addActionLink(
|
||||
id(new PHUIButtonView())
|
||||
->setTag('a')
|
||||
->setHref($generate_uri)
|
||||
->setWorkflow(true)
|
||||
->setDisabled(!$can_edit || !$can_generate)
|
||||
->setText(pht('Generate Keypair'))
|
||||
->setIcon(
|
||||
id(new PHUIIconView())
|
||||
->setIconFont('fa-lock')))
|
||||
->addActionLink(
|
||||
id(new PHUIButtonView())
|
||||
->setTag('a')
|
||||
->setHref($upload_uri)
|
||||
->setWorkflow(true)
|
||||
->setDisabled(!$can_edit)
|
||||
->setText(pht('Upload Public Key'))
|
||||
->setIcon(
|
||||
id(new PHUIIconView())
|
||||
->setIconFont('fa-upload')));
|
||||
|
||||
return id(new PHUIObjectBoxView())
|
||||
->setHeader($header)
|
||||
->appendChild($table);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ final class AlmanacDevice
|
|||
PhabricatorCustomFieldInterface,
|
||||
PhabricatorApplicationTransactionInterface,
|
||||
PhabricatorProjectInterface,
|
||||
PhabricatorSSHPublicKeyInterface,
|
||||
AlmanacPropertyInterface {
|
||||
|
||||
protected $name;
|
||||
|
@ -160,4 +161,13 @@ final class AlmanacDevice
|
|||
return new AlmanacDeviceTransaction();
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorSSHPublicKeyInterface )----------------------------------- */
|
||||
|
||||
|
||||
public function getSSHPublicKeyManagementURI(PhabricatorUser $viewer) {
|
||||
return $this->getURI();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorAuthSSHKeyTableView extends AphrontView {
|
||||
|
||||
private $keys;
|
||||
private $canEdit;
|
||||
private $noDataString;
|
||||
|
||||
public function setNoDataString($no_data_string) {
|
||||
$this->noDataString = $no_data_string;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCanEdit($can_edit) {
|
||||
$this->canEdit = $can_edit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setKeys(array $keys) {
|
||||
assert_instances_of($keys, 'PhabricatorAuthSSHKey');
|
||||
$this->keys = $keys;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$keys = $this->keys;
|
||||
$viewer = $this->getUser();
|
||||
|
||||
if ($this->canEdit) {
|
||||
$delete_class = 'small grey button';
|
||||
} else {
|
||||
$delete_class = 'small grey button disabled';
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($keys as $key) {
|
||||
$rows[] = array(
|
||||
javelin_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/auth/sshkey/edit/'.$key->getID().'/',
|
||||
'sigil' => 'workflow',
|
||||
),
|
||||
$key->getName()),
|
||||
$key->getKeyComment(),
|
||||
$key->getKeyType(),
|
||||
phabricator_datetime($key->getDateCreated(), $viewer),
|
||||
javelin_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/auth/sshkey/delete/'.$key->getID().'/',
|
||||
'class' => $delete_class,
|
||||
'sigil' => 'workflow',
|
||||
),
|
||||
pht('Delete')),
|
||||
);
|
||||
}
|
||||
|
||||
$table = id(new AphrontTableView($rows))
|
||||
->setNoDataString($this->noDataString)
|
||||
->setHeaders(
|
||||
array(
|
||||
pht('Name'),
|
||||
pht('Comment'),
|
||||
pht('Type'),
|
||||
pht('Added'),
|
||||
null,
|
||||
))
|
||||
->setColumnClasses(
|
||||
array(
|
||||
'wide pri',
|
||||
'',
|
||||
'',
|
||||
'right',
|
||||
'action',
|
||||
));
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
}
|
|
@ -32,51 +32,11 @@ final class PhabricatorSettingsPanelSSHKeys
|
|||
->withObjectPHIDs(array($user->getPHID()))
|
||||
->execute();
|
||||
|
||||
$rows = array();
|
||||
foreach ($keys as $key) {
|
||||
$rows[] = array(
|
||||
javelin_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/auth/sshkey/edit/'.$key->getID().'/',
|
||||
'sigil' => 'workflow',
|
||||
),
|
||||
$key->getName()),
|
||||
$key->getKeyComment(),
|
||||
$key->getKeyType(),
|
||||
phabricator_date($key->getDateCreated(), $viewer),
|
||||
phabricator_time($key->getDateCreated(), $viewer),
|
||||
javelin_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/auth/sshkey/delete/'.$key->getID().'/',
|
||||
'class' => 'small grey button',
|
||||
'sigil' => 'workflow',
|
||||
),
|
||||
pht('Delete')),
|
||||
);
|
||||
}
|
||||
|
||||
$table = new AphrontTableView($rows);
|
||||
$table->setNoDataString(pht("You haven't added any SSH Public Keys."));
|
||||
$table->setHeaders(
|
||||
array(
|
||||
pht('Name'),
|
||||
pht('Comment'),
|
||||
pht('Type'),
|
||||
pht('Created'),
|
||||
pht('Time'),
|
||||
'',
|
||||
));
|
||||
$table->setColumnClasses(
|
||||
array(
|
||||
'wide pri',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'right',
|
||||
'action',
|
||||
));
|
||||
$table = id(new PhabricatorAuthSSHKeyTableView())
|
||||
->setUser($viewer)
|
||||
->setKeys($keys)
|
||||
->setCanEdit(true)
|
||||
->setNoDataString("You haven't added any SSH Public Keys.");
|
||||
|
||||
$panel = new PHUIObjectBoxView();
|
||||
$header = new PHUIHeaderView();
|
||||
|
|
Loading…
Reference in a new issue