Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSHHelper #1405

Merged
merged 2 commits into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<Compile Include="VSSHelper.fs" />
<Compile Include="DynamicsNavHelper.fs" />
<Compile Include="DynamicsNavFile.fs" />
<Compile Include="SSHHelper.fs" />
<Compile Include="SCPHelper.fs" />
<Compile Include="RoboCopyHelper.fs" />
<Compile Include="XpkgHelper.fs" />
Expand Down
52 changes: 52 additions & 0 deletions src/app/FakeLib/SSHHelper.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[<AutoOpen>]
/// Conatins a task which allows to perform SSH operations
module Fake.SSHHelper

/// The SSH parameter type.
type SSHParams =
{ /// Path of the scp.exe
ToolPath : string
/// Path of the private key file (optional)
PrivateKeyPath : string
/// remote User
RemoteUser : string
RemoteHost : string
RemotePort : string
}


/// The SSH default parameters
let SSHDefaults : SSHParams =
{ ToolPath = if isMono then "ssh" else "ssh.exe"
RemoteUser = "fake"
RemoteHost = "localhost"
RemotePort = "22"
PrivateKeyPath = null }


/// Performs a command via SSH.
/// ## Parameters
///
/// - `setParams` - Function used to manipulate the default SSHParams value.
/// - `command` - The target path. Can be something like user@host:directory/TargetFile or a local path.
///
/// ## Sample
///
/// SSH (fun p -> { p with ToolPath = "tools/ssh.exe" }) command
let SSH setParams command =
let (p : SSHParams) = setParams SSHDefaults
let target =
if p.RemotePort = "22" then
sprintf "%s@%s" p.RemoteUser p.RemoteHost
else
sprintf "%s@%s:%s" p.RemoteUser p.RemoteHost p.RemotePort

let privateKey = if isNullOrEmpty p.PrivateKeyPath then "" else sprintf "-i \"%s\"" p.PrivateKeyPath
let args = sprintf "%s %s %s" privateKey target (toParam command)

tracefn "%s %s" p.ToolPath args
let result =
ExecProcess (fun info ->
info.FileName <- p.ToolPath
info.Arguments <- args) System.TimeSpan.MaxValue
if result <> 0 then failwithf "Error during SSH. Target: %s Command: %s" target command