Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/storage/PhabricatorAuthSSHKey.php
| <?php | <?php | ||||
| final class PhabricatorAuthSSHKey | final class PhabricatorAuthSSHKey | ||||
| extends PhabricatorAuthDAO | extends PhabricatorAuthDAO | ||||
| implements | implements | ||||
| PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
| PhabricatorDestructibleInterface { | PhabricatorDestructibleInterface { | ||||
| protected $objectPHID; | protected $objectPHID; | ||||
| protected $name; | protected $name; | ||||
| protected $keyType; | protected $keyType; | ||||
| protected $keyIndex; | protected $keyIndex; | ||||
| protected $keyBody; | protected $keyBody; | ||||
| protected $keyComment = ''; | protected $keyComment = ''; | ||||
| protected $isTrusted = 0; | protected $isTrusted = 0; | ||||
| protected $isActive; | |||||
| private $object = self::ATTACHABLE; | private $object = self::ATTACHABLE; | ||||
| public static function initializeNewSSHKey( | |||||
| PhabricatorUser $viewer, | |||||
| PhabricatorSSHPublicKeyInterface $object) { | |||||
| // You must be able to edit an object to create a new key on it. | |||||
| PhabricatorPolicyFilter::requireCapability( | |||||
| $viewer, | |||||
| $object, | |||||
| PhabricatorPolicyCapability::CAN_EDIT); | |||||
| $object_phid = $object->getPHID(); | |||||
| return id(new self()) | |||||
| ->setIsActive(1) | |||||
| ->setObjectPHID($object_phid) | |||||
| ->attachObject($object); | |||||
| } | |||||
| protected function getConfiguration() { | protected function getConfiguration() { | ||||
| return array( | return array( | ||||
| self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
| self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
| 'name' => 'text255', | 'name' => 'text255', | ||||
| 'keyType' => 'text255', | 'keyType' => 'text255', | ||||
| 'keyIndex' => 'bytes12', | 'keyIndex' => 'bytes12', | ||||
| 'keyBody' => 'text', | 'keyBody' => 'text', | ||||
| 'keyComment' => 'text255', | 'keyComment' => 'text255', | ||||
| 'isTrusted' => 'bool', | 'isTrusted' => 'bool', | ||||
| 'isActive' => 'bool?', | |||||
| ), | ), | ||||
| self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
| 'key_object' => array( | 'key_object' => array( | ||||
| 'columns' => array('objectPHID'), | 'columns' => array('objectPHID'), | ||||
| ), | ), | ||||
| 'key_unique' => array( | 'key_active' => array( | ||||
| 'columns' => array('keyIndex'), | 'columns' => array('isActive', 'objectPHID'), | ||||
| ), | |||||
| // NOTE: This unique key includes a nullable column, effectively | |||||
| // constraining uniqueness on active keys only. | |||||
| 'key_activeunique' => array( | |||||
| 'columns' => array('keyIndex', 'isActive'), | |||||
| 'unique' => true, | 'unique' => true, | ||||
| ), | ), | ||||
| ), | ), | ||||
| ) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
| } | } | ||||
| public function save() { | public function save() { | ||||
| $this->setKeyIndex($this->toPublicKey()->getHash()); | $this->setKeyIndex($this->toPublicKey()->getHash()); | ||||
| ▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines | |||||