Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/query/DiffusionQuery.php
| Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | final public static function callConduitWithDiffusionRequest( | ||||
| $core_params = array( | $core_params = array( | ||||
| 'callsign' => $repository->getCallsign(), | 'callsign' => $repository->getCallsign(), | ||||
| ); | ); | ||||
| if ($drequest->getBranch() !== null) { | if ($drequest->getBranch() !== null) { | ||||
| $core_params['branch'] = $drequest->getBranch(); | $core_params['branch'] = $drequest->getBranch(); | ||||
| } | } | ||||
| // If the method we're calling doesn't actually take some of the implicit | |||||
| // parameters we derive from the DiffusionRequest, omit them. | |||||
| $method_object = ConduitAPIMethod::getConduitMethod($method); | |||||
| $method_params = $method_object->defineParamTypes(); | |||||
| foreach ($core_params as $key => $value) { | |||||
| if (empty($method_params[$key])) { | |||||
| unset($core_params[$key]); | |||||
| } | |||||
| } | |||||
| $params = $params + $core_params; | $params = $params + $core_params; | ||||
| $service_phid = $repository->getAlmanacServicePHID(); | $service_phid = $repository->getAlmanacServicePHID(); | ||||
| if ($service_phid === null) { | if ($service_phid === null) { | ||||
| return id(new ConduitCall($method, $params)) | return id(new ConduitCall($method, $params)) | ||||
| ->setUser($user) | ->setUser($user) | ||||
| ->execute(); | ->execute(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | final public static function callConduitWithDiffusionRequest( | ||||
| shuffle($uris); | shuffle($uris); | ||||
| $uri = head($uris); | $uri = head($uris); | ||||
| $domain = id(new PhutilURI(PhabricatorEnv::getURI('/')))->getDomain(); | $domain = id(new PhutilURI(PhabricatorEnv::getURI('/')))->getDomain(); | ||||
| $client = id(new ConduitClient($uri)) | $client = id(new ConduitClient($uri)) | ||||
| ->setHost($domain); | ->setHost($domain); | ||||
| if ($user->isOmnipotent()) { | |||||
| // If the caller is the omnipotent user (normally, a daemon), we will | |||||
| // sign the request with this host's asymmetric keypair. | |||||
| $public_path = AlmanacKeys::getKeyPath('device.pub'); | |||||
| try { | |||||
| $public_key = Filesystem::readFile($public_path); | |||||
| } catch (Exception $ex) { | |||||
| throw new PhutilAggregateException( | |||||
| pht( | |||||
| 'Unable to read device public key while attempting to make '. | |||||
| 'authenticated method call within the Phabricator cluster. '. | |||||
| 'Use `bin/almanac register` to register keys for this device. '. | |||||
| 'Exception: %s', | |||||
| $ex->getMessage()), | |||||
| array($ex)); | |||||
| } | |||||
| $private_path = AlmanacKeys::getKeyPath('device.key'); | |||||
| try { | |||||
| $private_key = Filesystem::readFile($private_path); | |||||
| $private_key = new PhutilOpaqueEnvelope($private_key); | |||||
| } catch (Exception $ex) { | |||||
| throw new PhutilAggregateException( | |||||
| pht( | |||||
| 'Unable to read device private key while attempting to make '. | |||||
| 'authenticated method call within the Phabricator cluster. '. | |||||
| 'Use `bin/almanac register` to register keys for this device. '. | |||||
| 'Exception: %s', | |||||
| $ex->getMessage()), | |||||
| array($ex)); | |||||
| } | |||||
| $client->setSigningKeys($public_key, $private_key); | |||||
| } else { | |||||
| // If the caller is a normal user, we generate or retrieve a cluster | |||||
| // API token. | |||||
| $token = PhabricatorConduitToken::loadClusterTokenForUser($user); | $token = PhabricatorConduitToken::loadClusterTokenForUser($user); | ||||
| if ($token) { | if ($token) { | ||||
| $client->setConduitToken($token->getToken()); | $client->setConduitToken($token->getToken()); | ||||
| } | } | ||||
| } | |||||
| return $client->callMethodSynchronous($method, $params); | return $client->callMethodSynchronous($method, $params); | ||||
| } | } | ||||
| public function execute() { | public function execute() { | ||||
| return $this->executeQuery(); | return $this->executeQuery(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 127 Lines • Show Last 20 Lines | |||||