Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15464904
D14284.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D14284.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1645,6 +1645,7 @@
'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 @@
'PassphraseSSHPrivateKeyTextCredentialType' => 'PassphraseSSHPrivateKeyCredentialType',
'PassphraseSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'PassphraseSecret' => 'PassphraseDAO',
+ 'PassphraseTokenCredentialType' => 'PassphraseCredentialType',
'PasteConduitAPIMethod' => 'ConduitAPIMethod',
'PasteCreateConduitAPIMethod' => 'PasteConduitAPIMethod',
'PasteCreateMailReceiver' => 'PhabricatorMailReceiver',
diff --git a/src/applications/passphrase/controller/PassphraseCredentialViewController.php b/src/applications/passphrase/controller/PassphraseCredentialViewController.php
--- a/src/applications/passphrase/controller/PassphraseCredentialViewController.php
+++ b/src/applications/passphrase/controller/PassphraseCredentialViewController.php
@@ -14,20 +14,16 @@
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);
diff --git a/src/applications/passphrase/credentialtype/PassphraseTokenCredentialType.php b/src/applications/passphrase/credentialtype/PassphraseTokenCredentialType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/passphrase/credentialtype/PassphraseTokenCredentialType.php
@@ -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;
+ }
+
+}
diff --git a/src/applications/passphrase/editor/PassphraseCredentialTransactionEditor.php b/src/applications/passphrase/editor/PassphraseCredentialTransactionEditor.php
--- a/src/applications/passphrase/editor/PassphraseCredentialTransactionEditor.php
+++ b/src/applications/passphrase/editor/PassphraseCredentialTransactionEditor.php
@@ -174,7 +174,7 @@
}
break;
case PassphraseCredentialTransaction::TYPE_USERNAME:
- $credential_type = $object->getCredentialTypeImplementation();
+ $credential_type = $object->getImplementation();
if (!$credential_type->shouldRequireUsername()) {
break;
}
diff --git a/src/applications/passphrase/keys/PassphraseAbstractKey.php b/src/applications/passphrase/keys/PassphraseAbstractKey.php
--- a/src/applications/passphrase/keys/PassphraseAbstractKey.php
+++ b/src/applications/passphrase/keys/PassphraseAbstractKey.php
@@ -32,13 +32,13 @@
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 @@
throw new Exception(
pht(
'Credential "%s" must provide "%s", but provides "%s"!',
- 'K'.$credential->getID(),
+ $credential->getMonogram(),
$provides_type,
$type->getProvidesType()));
}
diff --git a/src/applications/passphrase/query/PassphraseCredentialQuery.php b/src/applications/passphrase/query/PassphraseCredentialQuery.php
--- a/src/applications/passphrase/query/PassphraseCredentialQuery.php
+++ b/src/applications/passphrase/query/PassphraseCredentialQuery.php
@@ -89,6 +89,17 @@
}
}
+ foreach ($page as $key => $credential) {
+ $type = PassphraseCredentialType::getTypeByConstant(
+ $credential->getCredentialType());
+ if (!$type) {
+ unset($page[$key]);
+ continue;
+ }
+
+ $credential->attachImplementation(clone $type);
+ }
+
return $page;
}
diff --git a/src/applications/passphrase/storage/PassphraseCredential.php b/src/applications/passphrase/storage/PassphraseCredential.php
--- a/src/applications/passphrase/storage/PassphraseCredential.php
+++ b/src/applications/passphrase/storage/PassphraseCredential.php
@@ -25,6 +25,7 @@
protected $spacePHID;
private $secret = self::ATTACHABLE;
+ private $implementation = self::ATTACHABLE;
public static function initializeNewCredential(PhabricatorUser $actor) {
$app = id(new PhabricatorApplicationQuery())
@@ -98,6 +99,15 @@
return PassphraseCredentialType::getTypeByConstant($type);
}
+ public function attachImplementation(PassphraseCredentialType $impl) {
+ $this->implementation = $impl;
+ return $this;
+ }
+
+ public function getImplementation() {
+ return $this->assertAttached($this->implementation);
+ }
+
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 3, 1:03 PM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7326838
Default Alt Text
D14284.diff (6 KB)
Attached To
Mode
D14284: Add a "Token" Credential type
Attached
Detach File
Event Timeline
Log In to Comment