1
0
Fork 0
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:
epriestley 2014-11-11 08:20:08 -08:00
parent 32cdc23efc
commit af6ffd8c7b
5 changed files with 161 additions and 45 deletions

View file

@ -1323,6 +1323,7 @@ phutil_register_library_map(array(
'PhabricatorAuthSSHKeyEditController' => 'applications/auth/controller/PhabricatorAuthSSHKeyEditController.php', 'PhabricatorAuthSSHKeyEditController' => 'applications/auth/controller/PhabricatorAuthSSHKeyEditController.php',
'PhabricatorAuthSSHKeyGenerateController' => 'applications/auth/controller/PhabricatorAuthSSHKeyGenerateController.php', 'PhabricatorAuthSSHKeyGenerateController' => 'applications/auth/controller/PhabricatorAuthSSHKeyGenerateController.php',
'PhabricatorAuthSSHKeyQuery' => 'applications/auth/query/PhabricatorAuthSSHKeyQuery.php', 'PhabricatorAuthSSHKeyQuery' => 'applications/auth/query/PhabricatorAuthSSHKeyQuery.php',
'PhabricatorAuthSSHKeyTableView' => 'applications/auth/view/PhabricatorAuthSSHKeyTableView.php',
'PhabricatorAuthSSHPublicKey' => 'applications/auth/sshkey/PhabricatorAuthSSHPublicKey.php', 'PhabricatorAuthSSHPublicKey' => 'applications/auth/sshkey/PhabricatorAuthSSHPublicKey.php',
'PhabricatorAuthSession' => 'applications/auth/storage/PhabricatorAuthSession.php', 'PhabricatorAuthSession' => 'applications/auth/storage/PhabricatorAuthSession.php',
'PhabricatorAuthSessionEngine' => 'applications/auth/engine/PhabricatorAuthSessionEngine.php', 'PhabricatorAuthSessionEngine' => 'applications/auth/engine/PhabricatorAuthSessionEngine.php',
@ -3011,6 +3012,7 @@ phutil_register_library_map(array(
'PhabricatorCustomFieldInterface', 'PhabricatorCustomFieldInterface',
'PhabricatorApplicationTransactionInterface', 'PhabricatorApplicationTransactionInterface',
'PhabricatorProjectInterface', 'PhabricatorProjectInterface',
'PhabricatorSSHPublicKeyInterface',
'AlmanacPropertyInterface', 'AlmanacPropertyInterface',
), ),
'AlmanacDeviceController' => 'AlmanacController', 'AlmanacDeviceController' => 'AlmanacController',
@ -4396,6 +4398,7 @@ phutil_register_library_map(array(
'PhabricatorAuthSSHKeyEditController' => 'PhabricatorAuthSSHKeyController', 'PhabricatorAuthSSHKeyEditController' => 'PhabricatorAuthSSHKeyController',
'PhabricatorAuthSSHKeyGenerateController' => 'PhabricatorAuthSSHKeyController', 'PhabricatorAuthSSHKeyGenerateController' => 'PhabricatorAuthSSHKeyController',
'PhabricatorAuthSSHKeyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorAuthSSHKeyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorAuthSSHKeyTableView' => 'AphrontView',
'PhabricatorAuthSSHPublicKey' => 'Phobject', 'PhabricatorAuthSSHPublicKey' => 'Phobject',
'PhabricatorAuthSession' => array( 'PhabricatorAuthSession' => array(
'PhabricatorAuthDAO', 'PhabricatorAuthDAO',

View file

@ -57,6 +57,7 @@ final class AlmanacDeviceViewController
$box, $box,
$interfaces, $interfaces,
$this->buildAlmanacPropertiesTable($device), $this->buildAlmanacPropertiesTable($device),
$this->buildSSHKeysTable($device),
$xaction_view, $xaction_view,
), ),
array( array(
@ -141,4 +142,65 @@ final class AlmanacDeviceViewController
->appendChild($table); ->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);
}
} }

View file

@ -7,6 +7,7 @@ final class AlmanacDevice
PhabricatorCustomFieldInterface, PhabricatorCustomFieldInterface,
PhabricatorApplicationTransactionInterface, PhabricatorApplicationTransactionInterface,
PhabricatorProjectInterface, PhabricatorProjectInterface,
PhabricatorSSHPublicKeyInterface,
AlmanacPropertyInterface { AlmanacPropertyInterface {
protected $name; protected $name;
@ -160,4 +161,13 @@ final class AlmanacDevice
return new AlmanacDeviceTransaction(); return new AlmanacDeviceTransaction();
} }
/* -( PhabricatorSSHPublicKeyInterface )----------------------------------- */
public function getSSHPublicKeyManagementURI(PhabricatorUser $viewer) {
return $this->getURI();
}
} }

View file

@ -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;
}
}

View file

@ -32,51 +32,11 @@ final class PhabricatorSettingsPanelSSHKeys
->withObjectPHIDs(array($user->getPHID())) ->withObjectPHIDs(array($user->getPHID()))
->execute(); ->execute();
$rows = array(); $table = id(new PhabricatorAuthSSHKeyTableView())
foreach ($keys as $key) { ->setUser($viewer)
$rows[] = array( ->setKeys($keys)
javelin_tag( ->setCanEdit(true)
'a', ->setNoDataString("You haven't added any SSH Public Keys.");
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',
));
$panel = new PHUIObjectBoxView(); $panel = new PHUIObjectBoxView();
$header = new PHUIHeaderView(); $header = new PHUIHeaderView();