Page MenuHomePhabricator

D7700.id.diff
No OneTemporary

D7700.id.diff

Index: src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
===================================================================
--- src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
+++ src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
@@ -2,7 +2,32 @@
final class DrydockSSHCommandInterface extends DrydockCommandInterface {
+ private $passphraseSSHKey;
+
+ private function openCredentialsIfNotOpen() {
+ if ($this->passphraseSSHKey !== null) {
+ return;
+ }
+
+ $credential = id(new PassphraseCredentialQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->withIDs(array($this->getConfig('credential')))
+ ->needSecrets(true)
+ ->executeOne();
+
+ 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 getExecFuture($command) {
+ $this->openCredentialsIfNotOpen();
+
$argv = func_get_args();
// This assumes there's a UNIX shell living at the other
@@ -21,32 +46,12 @@
// NOTE: The "-t -t" is for psuedo-tty allocation so we can "sudo" on some
// systems, but maybe more trouble than it's worth?
-
- $credential = id(new PassphraseCredentialQuery())
- ->setViewer(PhabricatorUser::getOmnipotentUser())
- ->withIDs(array($this->getConfig('credential')))
- ->needSecrets(true)
- ->executeOne();
-
- // FIXME: We can't use text-based SSH files here because the TempFile goes
- // out of scope after this function ends and thus the file gets removed
- // before it can be used.
- if ($credential->getCredentialType() !==
- PassphraseCredentialTypeSSHPrivateKeyFile::CREDENTIAL_TYPE) {
- throw new Exception("Only private key file credentials are supported.");
- }
-
- $ssh_key = PassphraseSSHKey::loadFromPHID(
- $credential->getPHID(),
- PhabricatorUser::getOmnipotentUser());
-
return new ExecFuture(
- 'ssh -t -t -o StrictHostKeyChecking=no -p %s -i %s %s@%s -- %s',
+ 'ssh -t -t -o StrictHostKeyChecking=no -p %s -i %P %P@%s -- %s',
$this->getConfig('port'),
- $ssh_key->getKeyfileEnvelope()->openEnvelope(),
- $credential->getUsername(),
+ $this->passphraseSSHKey->getKeyfileEnvelope(),
+ $this->passphraseSSHKey->getUsernameEnvelope(),
$this->getConfig('host'),
$full_command);
}
-
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 9:34 AM (4 d, 4 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6733930
Default Alt Text
D7700.id.diff (2 KB)

Event Timeline