Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/storage/DrydockLease.php
<?php | <?php | ||||
final class DrydockLease extends DrydockDAO | final class DrydockLease extends DrydockDAO | ||||
implements PhabricatorPolicyInterface { | implements | ||||
PhabricatorPolicyInterface, | |||||
PhabricatorConduitResultInterface { | |||||
protected $resourcePHID; | protected $resourcePHID; | ||||
protected $resourceType; | protected $resourceType; | ||||
protected $until; | protected $until; | ||||
protected $ownerPHID; | protected $ownerPHID; | ||||
protected $authorizingPHID; | protected $authorizingPHID; | ||||
protected $attributes = array(); | protected $attributes = array(); | ||||
protected $status = DrydockLeaseStatus::STATUS_PENDING; | protected $status = DrydockLeaseStatus::STATUS_PENDING; | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | return array( | ||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_resource' => array( | 'key_resource' => array( | ||||
'columns' => array('resourcePHID', 'status'), | 'columns' => array('resourcePHID', 'status'), | ||||
), | ), | ||||
'key_status' => array( | 'key_status' => array( | ||||
'columns' => array('status'), | 'columns' => array('status'), | ||||
), | ), | ||||
'key_owner' => array( | |||||
'columns' => array('ownerPHID'), | |||||
), | |||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function setAttribute($key, $value) { | public function setAttribute($key, $value) { | ||||
$this->attributes[$key] = $value; | $this->attributes[$key] = $value; | ||||
return $this; | return $this; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 413 Lines • ▼ Show 20 Lines | public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
public function describeAutomaticCapability($capability) { | public function describeAutomaticCapability($capability) { | ||||
return pht('Leases inherit policies from the resources they lease.'); | return pht('Leases inherit policies from the resources they lease.'); | ||||
} | } | ||||
/* -( PhabricatorConduitResultInterface )---------------------------------- */ | |||||
public function getFieldSpecificationsForConduit() { | |||||
return array( | |||||
id(new PhabricatorConduitSearchFieldSpecification()) | |||||
->setKey('resourcePHID') | |||||
->setType('phid?') | |||||
->setDescription(pht('PHID of the leased resource, if any.')), | |||||
id(new PhabricatorConduitSearchFieldSpecification()) | |||||
->setKey('resourceType') | |||||
->setType('string') | |||||
->setDescription(pht('Type of resource being leased.')), | |||||
id(new PhabricatorConduitSearchFieldSpecification()) | |||||
->setKey('until') | |||||
->setType('int?') | |||||
->setDescription(pht('Epoch at which this lease expires, if any.')), | |||||
id(new PhabricatorConduitSearchFieldSpecification()) | |||||
->setKey('ownerPHID') | |||||
->setType('phid?') | |||||
->setDescription(pht('The PHID of the object that owns this lease.')), | |||||
id(new PhabricatorConduitSearchFieldSpecification()) | |||||
->setKey('authorizingPHID') | |||||
->setType('phid') | |||||
->setDescription(pht( | |||||
'The PHID of the object that authorized this lease.')), | |||||
id(new PhabricatorConduitSearchFieldSpecification()) | |||||
->setKey('status') | |||||
->setType('map<string, wild>') | |||||
->setDescription(pht( | |||||
"The string constant and name of this lease's status.")), | |||||
); | |||||
} | |||||
public function getFieldValuesForConduit() { | |||||
$status = $this->getStatus(); | |||||
$until = $this->getUntil(); | |||||
if ($until) { | |||||
$until = (int)$until; | |||||
} else { | |||||
$until = null; | |||||
} | |||||
return array( | |||||
'resourcePHID' => $this->getResourcePHID(), | |||||
'resourceType' => $this->getResourceType(), | |||||
'until' => $until, | |||||
epriestley: What's your use case for reading `attributes`? I'm not sure we should dump them verbatim… | |||||
Not Done Inline ActionsInternally we display like, what version of the workspace you have checked out from the CLI when you're looking at your leases, or the hostname of the machine if you have a machine lease. We can just implement it as a search attachment when reintegrating with upstream, probably would tend to agree with you more that it needs some work before being exposed over the API. yelirekim: Internally we display like, what version of the workspace you have checked out from the CLI… | |||||
'ownerPHID' => $this->getOwnerPHID(), | |||||
'authorizingPHID' => $this->getAuthorizingPHID(), | |||||
'status' => array( | |||||
'value' => $status, | |||||
'name' => DrydockLeaseStatus::getNameForStatus($status), | |||||
), | |||||
); | |||||
} | |||||
public function getConduitSearchAttachments() { | |||||
return array(); | |||||
} | |||||
} | } |
What's your use case for reading attributes? I'm not sure we should dump them verbatim -- they may conceivably contain internal data or keys, and I think their structure is somewhat in flux, and they're probably not the most-preferred format for consumption. If possible, clients probably shouldn't be relying on raw attributes.
If this is for completeness, maybe omit it?
If this is for a particular purpose, maybe we can find a better way to expose the data that's more client-consumable?