Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F94236898
DrydockSFTPFilesystemInterface.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
Thu, Dec 5, 00:33
Size
1 KB
Mime Type
text/x-php
Expires
Sat, Dec 7, 00:33 (1 d, 4 h)
Engine
blob
Format
Raw Data
Handle
22741715
Attached To
rPH Phabricator
DrydockSFTPFilesystemInterface.php
View Options
<?php
final
class
DrydockSFTPFilesystemInterface
extends
DrydockFilesystemInterface
{
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
());
}
private
function
getExecFuture
(
$path
)
{
$this
->
openCredentialsIfNotOpen
();
return
new
ExecFuture
(
'sftp -o "StrictHostKeyChecking no" -P %s -i %P %P@%s'
,
$this
->
getConfig
(
'port'
),
$this
->
passphraseSSHKey
->
getKeyfileEnvelope
(),
$this
->
passphraseSSHKey
->
getUsernameEnvelope
(),
$this
->
getConfig
(
'host'
));
}
public
function
readFile
(
$path
)
{
$target
=
new
TempFile
();
$future
=
$this
->
getExecFuture
(
$path
);
$future
->
write
(
csprintf
(
"get %s %s"
,
$path
,
$target
));
$future
->
resolvex
();
return
Filesystem
::
readFile
(
$target
);
}
public
function
saveFile
(
$path
,
$name
)
{
$data
=
$this
->
readFile
(
$path
);
$file
=
PhabricatorFile
::
newFromFileData
(
$data
);
$file
->
setName
(
$name
);
$file
->
save
();
return
$file
;
}
public
function
writeFile
(
$path
,
$data
)
{
$source
=
new
TempFile
();
Filesystem
::
writeFile
(
$source
,
$data
);
$future
=
$this
->
getExecFuture
(
$path
);
$future
->
write
(
csprintf
(
"put %s %s"
,
$source
,
$path
));
$future
->
resolvex
();
}
}
Event Timeline
Log In to Comment