Page MenuHomePhabricator

D11883.id28633.diff
No OneTemporary

D11883.id28633.diff

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
@@ -77,6 +77,7 @@
'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 @@
'AlmanacPropertyEditController' => 'AlmanacDeviceController',
'AlmanacPropertyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'AlmanacQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'AlmanacQueryDevicesConduitAPIMethod' => 'AlmanacConduitAPIMethod',
'AlmanacQueryServicesConduitAPIMethod' => 'AlmanacConduitAPIMethod',
'AlmanacSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'AlmanacService' => array(
diff --git a/src/applications/almanac/conduit/AlmanacConduitAPIMethod.php b/src/applications/almanac/conduit/AlmanacConduitAPIMethod.php
--- a/src/applications/almanac/conduit/AlmanacConduitAPIMethod.php
+++ b/src/applications/almanac/conduit/AlmanacConduitAPIMethod.php
@@ -17,4 +17,57 @@
'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(),
+ );
+ }
+
}
diff --git a/src/applications/almanac/conduit/AlmanacQueryDevicesConduitAPIMethod.php b/src/applications/almanac/conduit/AlmanacQueryDevicesConduitAPIMethod.php
new file mode 100644
--- /dev/null
+++ b/src/applications/almanac/conduit/AlmanacQueryDevicesConduitAPIMethod.php
@@ -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);
+ }
+
+}
diff --git a/src/applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php b/src/applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php
--- a/src/applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php
+++ b/src/applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php
@@ -69,9 +69,6 @@
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 @@
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(),
- );
- }
-
}

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 21, 1:28 AM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7678238
Default Alt Text
D11883.id28633.diff (7 KB)

Event Timeline