Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/protocol/DiffusionCommandEngine.php
| <?php | <?php | ||||
| abstract class DiffusionCommandEngine extends Phobject { | abstract class DiffusionCommandEngine extends Phobject { | ||||
| private $repository; | private $repository; | ||||
| private $protocol; | private $protocol; | ||||
| private $credentialPHID; | private $credentialPHID; | ||||
| private $argv; | private $argv; | ||||
| private $passthru; | private $passthru; | ||||
| private $connectAsDevice; | |||||
| public static function newCommandEngine(PhabricatorRepository $repository) { | public static function newCommandEngine(PhabricatorRepository $repository) { | ||||
| $engines = self::newCommandEngines(); | $engines = self::newCommandEngines(); | ||||
| foreach ($engines as $engine) { | foreach ($engines as $engine) { | ||||
| if ($engine->canBuildForRepository($repository)) { | if ($engine->canBuildForRepository($repository)) { | ||||
| return id(clone $engine) | return id(clone $engine) | ||||
| ->setRepository($repository); | ->setRepository($repository); | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public function setPassthru($passthru) { | ||||
| $this->passthru = $passthru; | $this->passthru = $passthru; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getPassthru() { | public function getPassthru() { | ||||
| return $this->passthru; | return $this->passthru; | ||||
| } | } | ||||
| public function setConnectAsDevice($connect_as_device) { | |||||
| $this->connectAsDevice = $connect_as_device; | |||||
| return $this; | |||||
| } | |||||
| public function getConnectAsDevice() { | |||||
| return $this->connectAsDevice; | |||||
| } | |||||
| public function newFuture() { | public function newFuture() { | ||||
| $argv = $this->newCommandArgv(); | $argv = $this->newCommandArgv(); | ||||
| $env = $this->newCommandEnvironment(); | $env = $this->newCommandEnvironment(); | ||||
| if ($this->getPassthru()) { | if ($this->getPassthru()) { | ||||
| $future = newv('PhutilExecPassthru', $argv); | $future = newv('PhutilExecPassthru', $argv); | ||||
| } else { | } else { | ||||
| $future = newv('ExecFuture', $argv); | $future = newv('ExecFuture', $argv); | ||||
| Show All 20 Lines | foreach ($env as $key => $value) { | ||||
| if ($value === null) { | if ($value === null) { | ||||
| unset($env[$key]); | unset($env[$key]); | ||||
| } | } | ||||
| } | } | ||||
| return $env; | return $env; | ||||
| } | } | ||||
| private function newCommonEnvironment() { | private function newCommonEnvironment() { | ||||
| $repository = $this->getRepository(); | |||||
| $env = array(); | $env = array(); | ||||
| // NOTE: Force the language to "en_US.UTF-8", which overrides locale | // NOTE: Force the language to "en_US.UTF-8", which overrides locale | ||||
| // settings. This makes stuff print in English instead of, e.g., French, | // settings. This makes stuff print in English instead of, e.g., French, | ||||
| // so we can parse the output of some commands, error messages, etc. | // so we can parse the output of some commands, error messages, etc. | ||||
| $env['LANG'] = 'en_US.UTF-8'; | $env['LANG'] = 'en_US.UTF-8'; | ||||
| // Propagate PHABRICATOR_ENV explicitly. For discussion, see T4155. | // Propagate PHABRICATOR_ENV explicitly. For discussion, see T4155. | ||||
| $env['PHABRICATOR_ENV'] = PhabricatorEnv::getSelectedEnvironmentName(); | $env['PHABRICATOR_ENV'] = PhabricatorEnv::getSelectedEnvironmentName(); | ||||
| if ($this->isAnySSHProtocol()) { | $as_device = $this->getConnectAsDevice(); | ||||
| $credential_phid = $this->getCredentialPHID(); | $credential_phid = $this->getCredentialPHID(); | ||||
| if ($as_device) { | |||||
| $device = AlmanacKeys::getLiveDevice(); | |||||
| if (!$device) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Attempting to build a reposiory command (for repository "%s") '. | |||||
| 'as device, but this host ("%s") is not configured as a cluster '. | |||||
| 'device.', | |||||
| $repository->getDisplayName(), | |||||
| php_uname('n'))); | |||||
| } | |||||
| if ($credential_phid) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Attempting to build a repository command (for repository "%s"), '. | |||||
| 'but the CommandEngine is configured to connect as both the '. | |||||
| 'current cluster device ("%s") and with a specific credential '. | |||||
| '("%s"). These options are mutually exclusive. Connections must '. | |||||
| 'authenticate as one or the other, not both.', | |||||
| $repository->getDisplayName(), | |||||
| $device->getName(), | |||||
| $credential_phid)); | |||||
| } | |||||
| } | |||||
| if ($this->isAnySSHProtocol()) { | |||||
| if ($credential_phid) { | if ($credential_phid) { | ||||
| $env['PHABRICATOR_CREDENTIAL'] = $credential_phid; | $env['PHABRICATOR_CREDENTIAL'] = $credential_phid; | ||||
| } | } | ||||
| if ($as_device) { | |||||
| $env['PHABRICATOR_AS_DEVICE'] = 1; | |||||
| } | |||||
| } | } | ||||
| return $env; | return $env; | ||||
| } | } | ||||
| protected function isSSHProtocol() { | protected function isSSHProtocol() { | ||||
| return ($this->getProtocol() == 'ssh'); | return ($this->getProtocol() == 'ssh'); | ||||
| } | } | ||||
| Show All 31 Lines | |||||