@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
at recaptime-dev/main 62 lines 1.6 kB view raw
1<?php 2 3final class DrydockSSHCommandInterface extends DrydockCommandInterface { 4 5 private $credential; 6 private $connectTimeout; 7 8 private function loadCredential() { 9 if ($this->credential === null) { 10 $credential_phid = $this->getConfig('credentialPHID'); 11 12 $this->credential = PassphraseSSHKey::loadFromPHID( 13 $credential_phid, 14 PhabricatorUser::getOmnipotentUser()); 15 } 16 17 return $this->credential; 18 } 19 20 public function setConnectTimeout($timeout) { 21 $this->connectTimeout = $timeout; 22 return $this; 23 } 24 25 public function getExecFuture($command) { 26 $credential = $this->loadCredential(); 27 28 $argv = func_get_args(); 29 $argv = $this->applyWorkingDirectoryToArgv($argv); 30 $full_command = call_user_func_array('csprintf', $argv); 31 32 $flags = array(); 33 34 // See T13121. Attempt to suppress the "Permanently added X to list of 35 // known hosts" message without suppressing anything important. 36 $flags[] = '-o'; 37 $flags[] = 'LogLevel=ERROR'; 38 39 $flags[] = '-o'; 40 $flags[] = 'StrictHostKeyChecking=no'; 41 42 $flags[] = '-o'; 43 $flags[] = 'UserKnownHostsFile=/dev/null'; 44 45 $flags[] = '-o'; 46 $flags[] = 'BatchMode=yes'; 47 48 if ($this->connectTimeout) { 49 $flags[] = '-o'; 50 $flags[] = 'ConnectTimeout='.$this->connectTimeout; 51 } 52 53 return new ExecFuture( 54 'ssh %Ls -l %P -p %s -i %P %s -- %s', 55 $flags, 56 $credential->getUsernameEnvelope(), 57 $this->getConfig('port'), 58 $credential->getKeyfileEnvelope(), 59 $this->getConfig('host'), 60 $full_command); 61 } 62}