mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +01:00
Add alamanc.querydevices
Conduit API method
Summary: See D11882 for context and rationale. Test Plan: - Ran `almanac.querydevices`. - Ran `almanac.queryserices`. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D11883
This commit is contained in:
parent
7294512411
commit
d306765da4
4 changed files with 122 additions and 56 deletions
|
@ -77,6 +77,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacPropertyInterface' => 'applications/almanac/property/AlmanacPropertyInterface.php',
|
||||
'AlmanacPropertyQuery' => 'applications/almanac/query/AlmanacPropertyQuery.php',
|
||||
'AlmanacQuery' => 'applications/almanac/query/AlmanacQuery.php',
|
||||
'AlmanacQueryDevicesConduitAPIMethod' => 'applications/almanac/conduit/AlmanacQueryDevicesConduitAPIMethod.php',
|
||||
'AlmanacQueryServicesConduitAPIMethod' => 'applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php',
|
||||
'AlmanacSchemaSpec' => 'applications/almanac/storage/AlmanacSchemaSpec.php',
|
||||
'AlmanacService' => 'applications/almanac/storage/AlmanacService.php',
|
||||
|
@ -3218,6 +3219,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacPropertyEditController' => 'AlmanacDeviceController',
|
||||
'AlmanacPropertyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'AlmanacQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'AlmanacQueryDevicesConduitAPIMethod' => 'AlmanacConduitAPIMethod',
|
||||
'AlmanacQueryServicesConduitAPIMethod' => 'AlmanacConduitAPIMethod',
|
||||
'AlmanacSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||
'AlmanacService' => array(
|
||||
|
|
|
@ -17,4 +17,57 @@ abstract class AlmanacConduitAPIMethod extends ConduitAPIMethod {
|
|||
'subject to change.');
|
||||
}
|
||||
|
||||
protected function getServiceDictionary(AlmanacService $service) {
|
||||
return array(
|
||||
'id' => (int)$service->getID(),
|
||||
'phid' => $service->getPHID(),
|
||||
'name' => $service->getName(),
|
||||
'uri' => PhabricatorEnv::getProductionURI($service->getURI()),
|
||||
'serviceClass' => $service->getServiceClass(),
|
||||
'properties' => $this->getPropertiesDictionary($service),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getBindingDictionary(AlmanacBinding $binding) {
|
||||
return array(
|
||||
'id' => (int)$binding->getID(),
|
||||
'phid' => $binding->getPHID(),
|
||||
'properties' => $this->getPropertiesDictionary($binding),
|
||||
'interface' => $this->getInterfaceDictionary($binding->getInterface()),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getPropertiesDictionary(AlmanacPropertyInterface $obj) {
|
||||
$properties = $obj->getAlmanacProperties();
|
||||
return (object)mpull($properties, 'getFieldValue', 'getFieldName');
|
||||
}
|
||||
|
||||
protected function getInterfaceDictionary(AlmanacInterface $interface) {
|
||||
return array(
|
||||
'id' => (int)$interface->getID(),
|
||||
'phid' => $interface->getPHID(),
|
||||
'address' => $interface->getAddress(),
|
||||
'port' => (int)$interface->getPort(),
|
||||
'device' => $this->getDeviceDictionary($interface->getDevice()),
|
||||
'network' => $this->getNetworkDictionary($interface->getNetwork()),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDeviceDictionary(AlmanacDevice $device) {
|
||||
return array(
|
||||
'id' => (int)$device->getID(),
|
||||
'phid' => $device->getPHID(),
|
||||
'name' => $device->getName(),
|
||||
'properties' => $this->getPropertiesDictionary($device),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getNetworkDictionary(AlmanacNetwork $network) {
|
||||
return array(
|
||||
'id' => (int)$network->getID(),
|
||||
'phid' => $network->getPHID(),
|
||||
'name' => $network->getName(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacQueryDevicesConduitAPIMethod
|
||||
extends AlmanacConduitAPIMethod {
|
||||
|
||||
public function getAPIMethodName() {
|
||||
return 'almanac.querydevices';
|
||||
}
|
||||
|
||||
public function getMethodDescription() {
|
||||
return pht('Query Almanac devices.');
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'ids' => 'optional list<id>',
|
||||
'phids' => 'optional list<phid>',
|
||||
'names' => 'optional list<phid>',
|
||||
) + self::getPagerParamTypes();
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'list<wild>';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
$viewer = $request->getUser();
|
||||
|
||||
$query = id(new AlmanacDeviceQuery())
|
||||
->setViewer($viewer);
|
||||
|
||||
$ids = $request->getValue('ids');
|
||||
if ($ids !== null) {
|
||||
$query->withIDs($ids);
|
||||
}
|
||||
|
||||
$phids = $request->getValue('phids');
|
||||
if ($phids !== null) {
|
||||
$query->withPHIDs($phids);
|
||||
}
|
||||
|
||||
$names = $request->getValue('names');
|
||||
if ($names !== null) {
|
||||
$query->withNames($names);
|
||||
}
|
||||
|
||||
$pager = $this->newPager($request);
|
||||
|
||||
$devices = $query->executeWithCursorPager($pager);
|
||||
|
||||
$data = array();
|
||||
foreach ($devices as $device) {
|
||||
$data[] = $this->getDeviceDictionary($device);
|
||||
}
|
||||
|
||||
$results = array(
|
||||
'data' => $data,
|
||||
);
|
||||
|
||||
return $this->addPagerResults($results, $pager);
|
||||
}
|
||||
|
||||
}
|
|
@ -69,9 +69,6 @@ final class AlmanacQueryServicesConduitAPIMethod
|
|||
foreach ($services as $service) {
|
||||
$phid = $service->getPHID();
|
||||
|
||||
$properties = $service->getAlmanacProperties();
|
||||
$properties = mpull($properties, 'getFieldValue', 'getFieldName');
|
||||
|
||||
$service_bindings = $service->getBindings();
|
||||
$service_bindings = array_values($service_bindings);
|
||||
foreach ($service_bindings as $key => $service_binding) {
|
||||
|
@ -90,57 +87,4 @@ final class AlmanacQueryServicesConduitAPIMethod
|
|||
return $this->addPagerResults($results, $pager);
|
||||
}
|
||||
|
||||
private function getServiceDictionary(AlmanacService $service) {
|
||||
return array(
|
||||
'id' => (int)$service->getID(),
|
||||
'phid' => $service->getPHID(),
|
||||
'name' => $service->getName(),
|
||||
'uri' => PhabricatorEnv::getProductionURI($service->getURI()),
|
||||
'serviceClass' => $service->getServiceClass(),
|
||||
'properties' => $this->getPropertiesDictionary($service),
|
||||
);
|
||||
}
|
||||
|
||||
private function getBindingDictionary(AlmanacBinding $binding) {
|
||||
return array(
|
||||
'id' => (int)$binding->getID(),
|
||||
'phid' => $binding->getPHID(),
|
||||
'properties' => $this->getPropertiesDictionary($binding),
|
||||
'interface' => $this->getInterfaceDictionary($binding->getInterface()),
|
||||
);
|
||||
}
|
||||
|
||||
private function getPropertiesDictionary(AlmanacPropertyInterface $obj) {
|
||||
$properties = $obj->getAlmanacProperties();
|
||||
return (object)mpull($properties, 'getFieldValue', 'getFieldName');
|
||||
}
|
||||
|
||||
private function getInterfaceDictionary(AlmanacInterface $interface) {
|
||||
return array(
|
||||
'id' => (int)$interface->getID(),
|
||||
'phid' => $interface->getPHID(),
|
||||
'address' => $interface->getAddress(),
|
||||
'port' => (int)$interface->getPort(),
|
||||
'device' => $this->getDeviceDictionary($interface->getDevice()),
|
||||
'network' => $this->getNetworkDictionary($interface->getNetwork()),
|
||||
);
|
||||
}
|
||||
|
||||
private function getDeviceDictionary(AlmanacDevice $device) {
|
||||
return array(
|
||||
'id' => (int)$device->getID(),
|
||||
'phid' => $device->getPHID(),
|
||||
'name' => $device->getName(),
|
||||
'properties' => $this->getPropertiesDictionary($device),
|
||||
);
|
||||
}
|
||||
|
||||
private function getNetworkDictionary(AlmanacNetwork $network) {
|
||||
return array(
|
||||
'id' => (int)$network->getID(),
|
||||
'phid' => $network->getPHID(),
|
||||
'name' => $network->getName(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue