diff --git a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php index cde5f4a4ee..1ec2c124f5 100644 --- a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php +++ b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php @@ -1,100 +1,106 @@ passphraseSSHKey !== null) { return; } $credential = id(new PassphraseCredentialQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withIDs(array($this->getConfig('credential'))) ->needSecrets(true) ->executeOne(); + if ($credential === null) { + throw new Exception(pht( + 'There is no credential with ID %d.', + $this->getConfig('credential'))); + } + if ($credential->getProvidesType() !== PassphraseCredentialTypeSSHPrivateKey::PROVIDES_TYPE) { throw new Exception('Only private key credentials are supported.'); } $this->passphraseSSHKey = PassphraseSSHKey::loadFromPHID( $credential->getPHID(), PhabricatorUser::getOmnipotentUser()); } public function setConnectTimeout($timeout) { $this->connectTimeout = $timeout; return $this; } public function getExecFuture($command) { $this->openCredentialsIfNotOpen(); $argv = func_get_args(); if ($this->getConfig('platform') === 'windows') { // Handle Windows by executing the command under PowerShell. $command = id(new PhutilCommandString($argv)) ->setEscapingMode(PhutilCommandString::MODE_POWERSHELL); $change_directory = ''; if ($this->getWorkingDirectory() !== null) { $change_directory .= 'cd '.$this->getWorkingDirectory(); } $script = <<applyWorkingDirectoryToArgv($argv); $full_command = call_user_func_array('csprintf', $argv); } $command_timeout = ''; if ($this->connectTimeout !== null) { $command_timeout = csprintf( '-o %s', 'ConnectTimeout='.$this->connectTimeout); } return new ExecFuture( 'ssh '. '-o LogLevel=quiet '. '-o StrictHostKeyChecking=no '. '-o UserKnownHostsFile=/dev/null '. '-o BatchMode=yes '. '%C -p %s -i %P %P@%s -- %s', $command_timeout, $this->getConfig('port'), $this->passphraseSSHKey->getKeyfileEnvelope(), $this->passphraseSSHKey->getUsernameEnvelope(), $this->getConfig('host'), $full_command); } }