mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 05:20:56 +01:00
Add a "Token" Credential type
Summary: Ref T9456. This is just a convenience type for things like API tokens, to make it harder for users to make mistakes and keep SSH keys out of the dropdown for "choose your API token". Test Plan: {F879820} Reviewers: chad Reviewed By: chad Subscribers: joshuaspence Maniphest Tasks: T9456 Differential Revision: https://secure.phabricator.com/D14284
This commit is contained in:
parent
86720b4595
commit
63d755723b
7 changed files with 67 additions and 11 deletions
|
@ -1645,6 +1645,7 @@ phutil_register_library_map(array(
|
|||
'PassphraseSSHPrivateKeyTextCredentialType' => 'applications/passphrase/credentialtype/PassphraseSSHPrivateKeyTextCredentialType.php',
|
||||
'PassphraseSchemaSpec' => 'applications/passphrase/storage/PassphraseSchemaSpec.php',
|
||||
'PassphraseSecret' => 'applications/passphrase/storage/PassphraseSecret.php',
|
||||
'PassphraseTokenCredentialType' => 'applications/passphrase/credentialtype/PassphraseTokenCredentialType.php',
|
||||
'PasteConduitAPIMethod' => 'applications/paste/conduit/PasteConduitAPIMethod.php',
|
||||
'PasteCreateConduitAPIMethod' => 'applications/paste/conduit/PasteCreateConduitAPIMethod.php',
|
||||
'PasteCreateMailReceiver' => 'applications/paste/mail/PasteCreateMailReceiver.php',
|
||||
|
@ -5949,6 +5950,7 @@ phutil_register_library_map(array(
|
|||
'PassphraseSSHPrivateKeyTextCredentialType' => 'PassphraseSSHPrivateKeyCredentialType',
|
||||
'PassphraseSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||
'PassphraseSecret' => 'PassphraseDAO',
|
||||
'PassphraseTokenCredentialType' => 'PassphraseCredentialType',
|
||||
'PasteConduitAPIMethod' => 'ConduitAPIMethod',
|
||||
'PasteCreateConduitAPIMethod' => 'PasteConduitAPIMethod',
|
||||
'PasteCreateMailReceiver' => 'PhabricatorMailReceiver',
|
||||
|
|
|
@ -14,20 +14,16 @@ final class PassphraseCredentialViewController extends PassphraseController {
|
|||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$type = PassphraseCredentialType::getTypeByConstant(
|
||||
$credential->getCredentialType());
|
||||
if (!$type) {
|
||||
throw new Exception(pht('Credential has invalid type "%s"!', $type));
|
||||
}
|
||||
$type = $credential->getImplementation();
|
||||
|
||||
$timeline = $this->buildTransactionTimeline(
|
||||
$credential,
|
||||
new PassphraseCredentialTransactionQuery());
|
||||
$timeline->setShouldTerminate(true);
|
||||
|
||||
$title = pht('%s %s', 'K'.$credential->getID(), $credential->getName());
|
||||
$title = pht('%s %s', $credential->getMonogram(), $credential->getName());
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->addTextCrumb('K'.$credential->getID());
|
||||
$crumbs->addTextCrumb($credential->getMonogram());
|
||||
$crumbs->setBorder(true);
|
||||
|
||||
$header = $this->buildHeaderView($credential);
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
final class PassphraseTokenCredentialType
|
||||
extends PassphraseCredentialType {
|
||||
|
||||
const CREDENTIAL_TYPE = 'token';
|
||||
const PROVIDES_TYPE = 'provides/token';
|
||||
|
||||
public function getCredentialType() {
|
||||
return self::CREDENTIAL_TYPE;
|
||||
}
|
||||
|
||||
public function getProvidesType() {
|
||||
return self::PROVIDES_TYPE;
|
||||
}
|
||||
|
||||
public function getCredentialTypeName() {
|
||||
return pht('Token');
|
||||
}
|
||||
|
||||
public function getCredentialTypeDescription() {
|
||||
return pht('Store an API token.');
|
||||
}
|
||||
|
||||
public function getSecretLabel() {
|
||||
return pht('Token');
|
||||
}
|
||||
|
||||
public function newSecretControl() {
|
||||
return id(new AphrontFormTextControl());
|
||||
}
|
||||
|
||||
public function shouldRequireUsername() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -174,7 +174,7 @@ final class PassphraseCredentialTransactionEditor
|
|||
}
|
||||
break;
|
||||
case PassphraseCredentialTransaction::TYPE_USERNAME:
|
||||
$credential_type = $object->getCredentialTypeImplementation();
|
||||
$credential_type = $object->getImplementation();
|
||||
if (!$credential_type->shouldRequireUsername()) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -32,13 +32,13 @@ abstract class PassphraseAbstractKey extends Phobject {
|
|||
PassphraseCredential $credential,
|
||||
$provides_type) {
|
||||
|
||||
$type = $credential->getCredentialTypeImplementation();
|
||||
$type = $credential->getImplementation();
|
||||
|
||||
if (!$type) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Credential "%s" is of unknown type "%s"!',
|
||||
'K'.$credential->getID(),
|
||||
$credential->getMonogram(),
|
||||
$credential->getCredentialType()));
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ abstract class PassphraseAbstractKey extends Phobject {
|
|||
throw new Exception(
|
||||
pht(
|
||||
'Credential "%s" must provide "%s", but provides "%s"!',
|
||||
'K'.$credential->getID(),
|
||||
$credential->getMonogram(),
|
||||
$provides_type,
|
||||
$type->getProvidesType()));
|
||||
}
|
||||
|
|
|
@ -89,6 +89,17 @@ final class PassphraseCredentialQuery
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($page as $key => $credential) {
|
||||
$type = PassphraseCredentialType::getTypeByConstant(
|
||||
$credential->getCredentialType());
|
||||
if (!$type) {
|
||||
unset($page[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$credential->attachImplementation(clone $type);
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ final class PassphraseCredential extends PassphraseDAO
|
|||
protected $spacePHID;
|
||||
|
||||
private $secret = self::ATTACHABLE;
|
||||
private $implementation = self::ATTACHABLE;
|
||||
|
||||
public static function initializeNewCredential(PhabricatorUser $actor) {
|
||||
$app = id(new PhabricatorApplicationQuery())
|
||||
|
@ -98,6 +99,15 @@ final class PassphraseCredential extends PassphraseDAO
|
|||
return PassphraseCredentialType::getTypeByConstant($type);
|
||||
}
|
||||
|
||||
public function attachImplementation(PassphraseCredentialType $impl) {
|
||||
$this->implementation = $impl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getImplementation() {
|
||||
return $this->assertAttached($this->implementation);
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
||||
|
||||
|
|
Loading…
Reference in a new issue