Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F84597451
DrydockSSHCommandInterface.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Sep 23, 20:06
Size
1 KB
Mime Type
text/x-php
Expires
Wed, Sep 25, 20:06 (2 d)
Engine
blob
Format
Raw Data
Handle
21056359
Attached To
rPH Phabricator
DrydockSSHCommandInterface.php
View Options
<?php
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
// end of the connection, which isn't the case for Windows machines.
if
(
$this
->
getConfig
(
'platform'
)
!==
'windows'
)
{
$argv
=
$this
->
applyWorkingDirectoryToArgv
(
$argv
);
}
$full_command
=
call_user_func_array
(
'csprintf'
,
$argv
);
if
(
$this
->
getConfig
(
'platform'
)
===
'windows'
)
{
// On Windows platforms we need to execute cmd.exe explicitly since
// most commands are not really executables.
$full_command
=
'C:
\\
Windows
\\
system32
\\
cmd.exe /C '
.
$full_command
;
}
// NOTE: The "-t -t" is for psuedo-tty allocation so we can "sudo" on some
// systems, but maybe more trouble than it's worth?
return
new
ExecFuture
(
'ssh -t -t -o StrictHostKeyChecking=no -p %s -i %P %P@%s -- %s'
,
$this
->
getConfig
(
'port'
),
$this
->
passphraseSSHKey
->
getKeyfileEnvelope
(),
$this
->
passphraseSSHKey
->
getUsernameEnvelope
(),
$this
->
getConfig
(
'host'
),
$full_command
);
}
}
Event Timeline
Log In to Comment