mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-02 18:08:26 +01:00
Add almanac.queryservices Conduit API method
Summary: Ref T5833. Just building one query for now which returns the whole binding + interface + network + device tree. Maybe this will get split up in the future. This will allow web hosts to call the central Almanac and pull instance configuration, authenticating with SSH. Test Plan: {F234443} Reviewers: btrahan Reviewed By: btrahan Subscribers: chad, epriestley Maniphest Tasks: T5833 Differential Revision: https://secure.phabricator.com/D10862
This commit is contained in:
parent
1edcabe539
commit
2ac987714b
6 changed files with 168 additions and 3 deletions
|
@ -19,6 +19,7 @@ phutil_register_library_map(array(
|
||||||
'AlmanacBindingTransaction' => 'applications/almanac/storage/AlmanacBindingTransaction.php',
|
'AlmanacBindingTransaction' => 'applications/almanac/storage/AlmanacBindingTransaction.php',
|
||||||
'AlmanacBindingTransactionQuery' => 'applications/almanac/query/AlmanacBindingTransactionQuery.php',
|
'AlmanacBindingTransactionQuery' => 'applications/almanac/query/AlmanacBindingTransactionQuery.php',
|
||||||
'AlmanacBindingViewController' => 'applications/almanac/controller/AlmanacBindingViewController.php',
|
'AlmanacBindingViewController' => 'applications/almanac/controller/AlmanacBindingViewController.php',
|
||||||
|
'AlmanacConduitAPIMethod' => 'applications/almanac/conduit/AlmanacConduitAPIMethod.php',
|
||||||
'AlmanacConduitUtil' => 'applications/almanac/util/AlmanacConduitUtil.php',
|
'AlmanacConduitUtil' => 'applications/almanac/util/AlmanacConduitUtil.php',
|
||||||
'AlmanacConsoleController' => 'applications/almanac/controller/AlmanacConsoleController.php',
|
'AlmanacConsoleController' => 'applications/almanac/controller/AlmanacConsoleController.php',
|
||||||
'AlmanacController' => 'applications/almanac/controller/AlmanacController.php',
|
'AlmanacController' => 'applications/almanac/controller/AlmanacController.php',
|
||||||
|
@ -66,6 +67,7 @@ phutil_register_library_map(array(
|
||||||
'AlmanacPropertyInterface' => 'applications/almanac/property/AlmanacPropertyInterface.php',
|
'AlmanacPropertyInterface' => 'applications/almanac/property/AlmanacPropertyInterface.php',
|
||||||
'AlmanacPropertyQuery' => 'applications/almanac/query/AlmanacPropertyQuery.php',
|
'AlmanacPropertyQuery' => 'applications/almanac/query/AlmanacPropertyQuery.php',
|
||||||
'AlmanacQuery' => 'applications/almanac/query/AlmanacQuery.php',
|
'AlmanacQuery' => 'applications/almanac/query/AlmanacQuery.php',
|
||||||
|
'AlmanacQueryServicesConduitAPIMethod' => 'applications/almanac/conduit/AlmanacQueryServicesConduitAPIMethod.php',
|
||||||
'AlmanacSchemaSpec' => 'applications/almanac/storage/AlmanacSchemaSpec.php',
|
'AlmanacSchemaSpec' => 'applications/almanac/storage/AlmanacSchemaSpec.php',
|
||||||
'AlmanacService' => 'applications/almanac/storage/AlmanacService.php',
|
'AlmanacService' => 'applications/almanac/storage/AlmanacService.php',
|
||||||
'AlmanacServiceController' => 'applications/almanac/controller/AlmanacServiceController.php',
|
'AlmanacServiceController' => 'applications/almanac/controller/AlmanacServiceController.php',
|
||||||
|
@ -2996,6 +2998,7 @@ phutil_register_library_map(array(
|
||||||
'AlmanacBindingTransaction' => 'PhabricatorApplicationTransaction',
|
'AlmanacBindingTransaction' => 'PhabricatorApplicationTransaction',
|
||||||
'AlmanacBindingTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
'AlmanacBindingTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||||
'AlmanacBindingViewController' => 'AlmanacServiceController',
|
'AlmanacBindingViewController' => 'AlmanacServiceController',
|
||||||
|
'AlmanacConduitAPIMethod' => 'ConduitAPIMethod',
|
||||||
'AlmanacConduitUtil' => 'Phobject',
|
'AlmanacConduitUtil' => 'Phobject',
|
||||||
'AlmanacConsoleController' => 'AlmanacController',
|
'AlmanacConsoleController' => 'AlmanacController',
|
||||||
'AlmanacController' => 'PhabricatorController',
|
'AlmanacController' => 'PhabricatorController',
|
||||||
|
@ -3062,6 +3065,7 @@ phutil_register_library_map(array(
|
||||||
'AlmanacPropertyEditController' => 'AlmanacDeviceController',
|
'AlmanacPropertyEditController' => 'AlmanacDeviceController',
|
||||||
'AlmanacPropertyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'AlmanacPropertyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'AlmanacQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'AlmanacQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
|
'AlmanacQueryServicesConduitAPIMethod' => 'AlmanacConduitAPIMethod',
|
||||||
'AlmanacSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
'AlmanacSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||||
'AlmanacService' => array(
|
'AlmanacService' => array(
|
||||||
'AlmanacDAO',
|
'AlmanacDAO',
|
||||||
|
|
20
src/applications/almanac/conduit/AlmanacConduitAPIMethod.php
Normal file
20
src/applications/almanac/conduit/AlmanacConduitAPIMethod.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class AlmanacConduitAPIMethod extends ConduitAPIMethod {
|
||||||
|
|
||||||
|
final public function getApplication() {
|
||||||
|
return PhabricatorApplication::getByClass(
|
||||||
|
'PhabricatorAlmanacApplication');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMethodStatus() {
|
||||||
|
return self::METHOD_STATUS_UNSTABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMethodStatusDescription() {
|
||||||
|
return pht(
|
||||||
|
'Almanac is a prototype application and its APIs are '.
|
||||||
|
'subject to change.');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,138 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class AlmanacQueryServicesConduitAPIMethod
|
||||||
|
extends AlmanacConduitAPIMethod {
|
||||||
|
|
||||||
|
public function getAPIMethodName() {
|
||||||
|
return 'almanac.queryservices';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMethodDescription() {
|
||||||
|
return pht('Query Almanac services.');
|
||||||
|
}
|
||||||
|
|
||||||
|
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 AlmanacServiceQuery())
|
||||||
|
->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);
|
||||||
|
|
||||||
|
$services = $query->executeWithCursorPager($pager);
|
||||||
|
|
||||||
|
$bindings = id(new AlmanacBindingQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withServicePHIDs(mpull($services, 'getPHID'))
|
||||||
|
->execute();
|
||||||
|
$bindings = mgroup($bindings, 'getServicePHID');
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
foreach ($services as $service) {
|
||||||
|
$phid = $service->getPHID();
|
||||||
|
|
||||||
|
$properties = $service->getAlmanacProperties();
|
||||||
|
$properties = mpull($properties, 'getFieldValue', 'getFieldName');
|
||||||
|
|
||||||
|
$service_bindings = idx($bindings, $phid, array());
|
||||||
|
$service_bindings = array_values($service_bindings);
|
||||||
|
foreach ($service_bindings as $key => $service_binding) {
|
||||||
|
$service_bindings[$key] = $this->getBindingDictionary($service_binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data[] = $this->getServiceDictionary($service) + array(
|
||||||
|
'bindings' => $service_bindings,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$results = array(
|
||||||
|
'data' => $data,
|
||||||
|
);
|
||||||
|
|
||||||
|
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()),
|
||||||
|
'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(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -21,7 +21,8 @@ final class AlmanacBinding
|
||||||
|
|
||||||
public static function initializeNewBinding(AlmanacService $service) {
|
public static function initializeNewBinding(AlmanacService $service) {
|
||||||
return id(new AlmanacBinding())
|
return id(new AlmanacBinding())
|
||||||
->setServicePHID($service->getPHID());
|
->setServicePHID($service->getPHID())
|
||||||
|
->attachAlmanacProperties(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
|
|
|
@ -22,7 +22,8 @@ final class AlmanacDevice
|
||||||
public static function initializeNewDevice() {
|
public static function initializeNewDevice() {
|
||||||
return id(new AlmanacDevice())
|
return id(new AlmanacDevice())
|
||||||
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
|
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
|
||||||
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN);
|
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN)
|
||||||
|
->attachAlmanacProperties(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
|
|
|
@ -21,7 +21,8 @@ final class AlmanacService
|
||||||
public static function initializeNewService() {
|
public static function initializeNewService() {
|
||||||
return id(new AlmanacService())
|
return id(new AlmanacService())
|
||||||
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
|
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
|
||||||
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN);
|
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN)
|
||||||
|
->attachAlmanacProperties(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue