1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +01:00

Use HTTPEngineExtension proxy for git HTTP operations

Summary: Ref T10227. When we perform `git` http operations (fetch, mirror) check if we should use a proxy; if we should, set `http_proxy` or `https_proxy` in the environment to make `git` have `curl` use it.

Test Plan:
  - Configured a proxy extension to run stuff through a local instance of Charles.
  - Ran `repository pull` and `repository mirror`.
  - Saw `git` HTTP requests route through the proxy.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10227

Differential Revision: https://secure.phabricator.com/D16092
This commit is contained in:
epriestley 2016-06-09 11:19:16 -07:00
parent a88329fc38
commit 55a698a28a
5 changed files with 30 additions and 5 deletions

View file

@ -9,6 +9,7 @@ abstract class DiffusionCommandEngine extends Phobject {
private $passthru;
private $connectAsDevice;
private $sudoAsDaemon;
private $uri;
public static function newCommandEngine(PhabricatorRepository $repository) {
$engines = self::newCommandEngines();
@ -48,6 +49,16 @@ abstract class DiffusionCommandEngine extends Phobject {
return $this->repository;
}
public function setURI(PhutilURI $uri) {
$this->uri = $uri;
$this->setProtocol($uri->getProtocol());
return $this;
}
public function getURI() {
return $this->uri;
}
public function setProtocol($protocol) {
$this->protocol = $protocol;
return $this;

View file

@ -30,6 +30,21 @@ final class DiffusionGitCommandEngine
$env['GIT_SSH'] = $this->getSSHWrapper();
}
if ($this->isAnyHTTPProtocol()) {
$uri = $this->getURI();
if ($uri) {
$proxy = PhutilHTTPEngineExtension::buildHTTPProxyURI($uri);
if ($proxy) {
if ($this->isHTTPSProtocol()) {
$env_key = 'https_proxy';
} else {
$env_key = 'http_proxy';
}
$env[$env_key] = (string)$proxy;
}
}
}
return $env;
}

View file

@ -598,7 +598,7 @@ final class DiffusionRepositoryClusterEngine extends Phobject {
->setArgv($argv)
->setSudoAsDaemon(true)
->setCredentialPHID($repository->getCredentialPHID())
->setProtocol($repository->getRemoteProtocol())
->setURI($repository->getRemoteURI())
->newFuture();
$future->setCWD($local_path);
@ -704,7 +704,7 @@ final class DiffusionRepositoryClusterEngine extends Phobject {
->setArgv($argv)
->setConnectAsDevice(true)
->setSudoAsDaemon(true)
->setProtocol($fetch_uri->getProtocol())
->setURI($fetch_uri)
->newFuture();
$future->setCWD($local_path);

View file

@ -508,7 +508,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
return DiffusionCommandEngine::newCommandEngine($this)
->setArgv($argv)
->setCredentialPHID($this->getCredentialPHID())
->setProtocol($this->getRemoteProtocol());
->setURI($this->getRemoteURIObject());
}
/* -( Local Command Execution )-------------------------------------------- */

View file

@ -587,11 +587,10 @@ final class PhabricatorRepositoryURI
public function newCommandEngine() {
$repository = $this->getRepository();
$protocol = $this->getEffectiveURI()->getProtocol();
return DiffusionCommandEngine::newCommandEngine($repository)
->setCredentialPHID($this->getCredentialPHID())
->setProtocol($protocol);
->setURI($this->getEffectiveURI());
}
public function getURIScore() {