@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make ConduitCall always local/in-process

Summary:
Ref T2783. ConduitCall currently has logic to pick a random remote server, but this is ultimately not appropriate: we always want to send requests to a specific server. For example, we want to send repository requests to a server which has that repository locally. The repository tier is not homogenous, so we can't do this below the call level.

Make ConduitCall always-local; logic above it will select ConduitCall for an in-process request or do service selection for an off-host request via ConduitClient.

Test Plan:
- Browsed some pages using ConduitCall, everything worked.
- Grepped for removed stuff.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2783

Differential Revision: https://secure.phabricator.com/D10959

+1 -89
-2
src/__phutil_library_map__.php
··· 1419 1419 'PhabricatorConduitAPIController' => 'applications/conduit/controller/PhabricatorConduitAPIController.php', 1420 1420 'PhabricatorConduitApplication' => 'applications/conduit/application/PhabricatorConduitApplication.php', 1421 1421 'PhabricatorConduitCertificateToken' => 'applications/conduit/storage/PhabricatorConduitCertificateToken.php', 1422 - 'PhabricatorConduitConfigOptions' => 'applications/conduit/config/PhabricatorConduitConfigOptions.php', 1423 1422 'PhabricatorConduitConnectionLog' => 'applications/conduit/storage/PhabricatorConduitConnectionLog.php', 1424 1423 'PhabricatorConduitConsoleController' => 'applications/conduit/controller/PhabricatorConduitConsoleController.php', 1425 1424 'PhabricatorConduitController' => 'applications/conduit/controller/PhabricatorConduitController.php', ··· 4530 4529 'PhabricatorConduitAPIController' => 'PhabricatorConduitController', 4531 4530 'PhabricatorConduitApplication' => 'PhabricatorApplication', 4532 4531 'PhabricatorConduitCertificateToken' => 'PhabricatorConduitDAO', 4533 - 'PhabricatorConduitConfigOptions' => 'PhabricatorApplicationConfigOptions', 4534 4532 'PhabricatorConduitConnectionLog' => 'PhabricatorConduitDAO', 4535 4533 'PhabricatorConduitConsoleController' => 'PhabricatorConduitController', 4536 4534 'PhabricatorConduitController' => 'PhabricatorController',
-2
src/aphront/configuration/AphrontApplicationConfiguration.php
··· 107 107 $prod_uri = PhabricatorEnv::getEnvConfig('phabricator.production-uri'); 108 108 $file_uri = PhabricatorEnv::getEnvConfig( 109 109 'security.alternate-file-domain'); 110 - $conduit_uris = PhabricatorEnv::getEnvConfig('conduit.servers'); 111 110 $allowed_uris = PhabricatorEnv::getEnvConfig('phabricator.allowed-uris'); 112 111 113 112 $uris = array_merge( ··· 115 114 $base_uri, 116 115 $prod_uri, 117 116 ), 118 - $conduit_uris, 119 117 $allowed_uris); 120 118 121 119 $cdn_routes = array(
+1 -52
src/applications/conduit/call/ConduitCall.php
··· 13 13 private $method; 14 14 private $request; 15 15 private $user; 16 - private $servers; 17 - private $forceLocal; 18 16 19 17 public function __construct($method, array $params) { 20 18 $this->method = $method; 21 19 $this->handler = $this->buildMethodHandler($method); 22 - $this->servers = PhabricatorEnv::getEnvConfig('conduit.servers'); 23 - $this->forceLocal = false; 24 20 25 21 $invalid_params = array_diff_key( 26 22 $params, ··· 31 27 implode("', '", array_keys($invalid_params))."'."); 32 28 } 33 29 34 - if ($this->servers) { 35 - $current_host = AphrontRequest::getHTTPHeader('HOST'); 36 - foreach ($this->servers as $server) { 37 - if ($current_host === id(new PhutilURI($server))->getDomain()) { 38 - $this->forceLocal = true; 39 - break; 40 - } 41 - } 42 - } 43 - 44 30 $this->request = new ConduitAPIRequest($params); 45 31 } 46 32 ··· 51 37 52 38 public function getUser() { 53 39 return $this->user; 54 - } 55 - 56 - public function setForceLocal($force_local) { 57 - $this->forceLocal = $force_local; 58 - return $this; 59 - } 60 - 61 - public function shouldForceLocal() { 62 - return $this->forceLocal; 63 40 } 64 41 65 42 public function shouldRequireAuthentication() { ··· 137 114 } 138 115 } 139 116 140 - if (!$this->shouldForceLocal() && $this->servers) { 141 - $server = $this->pickRandomServer($this->servers); 142 - $client = new ConduitClient($server); 143 - $params = $this->request->getAllParameters(); 144 - 145 - $params['__conduit__']['isProxied'] = true; 146 - 147 - if ($this->handler->shouldRequireAuthentication()) { 148 - $client->callMethodSynchronous( 149 - 'conduit.connect', 150 - array( 151 - 'client' => 'PhabricatorConduit', 152 - 'clientVersion' => '1.0', 153 - 'user' => $this->getUser()->getUserName(), 154 - 'certificate' => $this->getUser()->getConduitCertificate(), 155 - '__conduit__' => $params['__conduit__'], 156 - )); 157 - } 158 - 159 - return $client->callMethodSynchronous( 160 - $this->method, 161 - $params); 162 - } else { 163 - return $this->handler->executeMethod($this->request); 164 - } 165 - } 166 - 167 - protected function pickRandomServer($servers) { 168 - return $servers[array_rand($servers)]; 117 + return $this->handler->executeMethod($this->request); 169 118 } 170 119 171 120 protected function buildMethodHandler($method_name) {
-2
src/applications/conduit/call/__tests__/ConduitCallTestCase.php
··· 4 4 5 5 public function testConduitPing() { 6 6 $call = new ConduitCall('conduit.ping', array()); 7 - $call->setForceLocal(true); 8 7 $result = $call->execute(); 9 8 10 9 $this->assertFalse(empty($result)); ··· 12 11 13 12 public function testConduitAuth() { 14 13 $call = new ConduitCall('user.whoami', array(), true); 15 - $call->setForceLocal(true); 16 14 17 15 $caught = null; 18 16 try {
-31
src/applications/conduit/config/PhabricatorConduitConfigOptions.php
··· 1 - <?php 2 - 3 - final class PhabricatorConduitConfigOptions 4 - extends PhabricatorApplicationConfigOptions { 5 - 6 - public function getName() { 7 - return pht('Conduit'); 8 - } 9 - 10 - public function getDescription() { 11 - return pht('Configure conduit.'); 12 - } 13 - 14 - public function getOptions() { 15 - return array( 16 - $this->newOption('conduit.servers', 'list<string>', array()) 17 - ->setLocked(true) 18 - ->setSummary(pht('Servers that conduit can connect to.')) 19 - ->setDescription( 20 - pht( 21 - "Set an array of servers where conduit can connect to. This is ". 22 - "an advanced option. Don't touch this unless you know what you ". 23 - "are doing.")) 24 - ->addExample( 25 - '["http://phabricator2.example.com/", '. 26 - '"http://phabricator3.example.com/]"', 27 - pht('Valid Setting')), 28 - ); 29 - } 30 - 31 - }