Differential D13985 Diff 33747 src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
<?php | <?php | ||||
final class DrydockSSHCommandInterface extends DrydockCommandInterface { | final class DrydockSSHCommandInterface extends DrydockCommandInterface { | ||||
private $passphraseSSHKey; | private $passphraseSSHKey; | ||||
private $connectTimeout; | private $connectTimeout; | ||||
private $execTimeout; | |||||
private function openCredentialsIfNotOpen() { | private function openCredentialsIfNotOpen() { | ||||
if ($this->passphraseSSHKey !== null) { | if ($this->passphraseSSHKey !== null) { | ||||
return; | return; | ||||
} | } | ||||
$credential = id(new PassphraseCredentialQuery()) | $credential = id(new PassphraseCredentialQuery()) | ||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
Show All 18 Lines | $this->passphraseSSHKey = PassphraseSSHKey::loadFromPHID( | ||||
PhabricatorUser::getOmnipotentUser()); | PhabricatorUser::getOmnipotentUser()); | ||||
} | } | ||||
public function setConnectTimeout($timeout) { | public function setConnectTimeout($timeout) { | ||||
$this->connectTimeout = $timeout; | $this->connectTimeout = $timeout; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setExecTimeout($timeout) { | |||||
$this->execTimeout = $timeout; | |||||
return $this; | |||||
} | |||||
public function getExecFuture($command) { | public function getExecFuture($command) { | ||||
$this->openCredentialsIfNotOpen(); | $this->openCredentialsIfNotOpen(); | ||||
$argv = func_get_args(); | $argv = func_get_args(); | ||||
$argv = $this->applyWorkingDirectoryToArgv($argv); | $argv = $this->applyWorkingDirectoryToArgv($argv); | ||||
$full_command = call_user_func_array('csprintf', $argv); | $full_command = call_user_func_array('csprintf', $argv); | ||||
$command_timeout = ''; | $command_timeout = ''; | ||||
if ($this->connectTimeout !== null) { | if ($this->connectTimeout !== null) { | ||||
$command_timeout = csprintf( | $command_timeout = csprintf( | ||||
'-o %s', | '-o %s', | ||||
'ConnectTimeout='.$this->connectTimeout); | 'ConnectTimeout='.$this->connectTimeout); | ||||
} | } | ||||
return new ExecFuture( | $future = new ExecFuture( | ||||
'ssh '. | 'ssh '. | ||||
'-o LogLevel=quiet '. | '-o LogLevel=quiet '. | ||||
'-o StrictHostKeyChecking=no '. | '-o StrictHostKeyChecking=no '. | ||||
'-o UserKnownHostsFile=/dev/null '. | '-o UserKnownHostsFile=/dev/null '. | ||||
'-o BatchMode=yes '. | '-o BatchMode=yes '. | ||||
'%C -p %s -i %P %P@%s -- %s', | '%C -p %s -i %P %P@%s -- %s', | ||||
epriestley: Much of this can now be rewritten to use `%Ls` more clearly and safely, see… | |||||
$command_timeout, | $command_timeout, | ||||
$this->getConfig('port'), | $this->getConfig('port'), | ||||
$this->passphraseSSHKey->getKeyfileEnvelope(), | $this->passphraseSSHKey->getKeyfileEnvelope(), | ||||
$this->passphraseSSHKey->getUsernameEnvelope(), | $this->passphraseSSHKey->getUsernameEnvelope(), | ||||
$this->getConfig('host'), | $this->getConfig('host'), | ||||
$full_command); | $full_command); | ||||
$future->setTimeout($this->execTimeout); | |||||
return $future; | |||||
} | } | ||||
} | } |
Much of this can now be rewritten to use %Ls more clearly and safely, see DiffusionSSHWorkflow for an example construction which does not require %C.