Skip to content
Draft
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
15 changes: 11 additions & 4 deletions pkg/agent/transport/ssh/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ func init() {
}
}

// sshConfigArguments computes SSH configuration arguments.
func sshConfigArguments() []string {
if configPath := os.Getenv("MUTAGEN_SSH_CONFIG_PATH"); configPath != "" {
// According to `man ssh`, "none" is also a valid value for `-F`.
return []string{"-F", configPath}
}
return nil
}

// sshTransport implements the agent.Transport interface using SSH.
type sshTransport struct {
// user is the SSH user under which agents should be invoked.
Expand Down Expand Up @@ -96,6 +105,7 @@ func (t *sshTransport) Copy(localPath, remoteName string) error {

// Set up arguments.
var scpArguments []string
scpArguments = append(scpArguments, sshConfigArguments()...)
scpArguments = append(scpArguments, ssh.CompressionFlag())
scpArguments = append(scpArguments, ssh.ConnectTimeoutFlag(connectTimeoutSeconds))
scpArguments = append(scpArguments, ssh.ServerAliveFlags(serverAliveIntervalSeconds, serverAliveCountMax)...)
Expand Down Expand Up @@ -156,10 +166,7 @@ func (t *sshTransport) Command(command string) (*exec.Cmd, error) {
// more efficient to compress at that layer, even with the slower Go
// implementation.
var sshArguments []string
if configPath := os.Getenv("MUTAGEN_SSH_CONFIG_PATH"); configPath != "" {
// According to `man ssh`, "none" is also a valid value for `-F`
sshArguments = append(sshArguments, "-F", configPath)
}
sshArguments = append(sshArguments, sshConfigArguments()...)
sshArguments = append(sshArguments, ssh.ConnectTimeoutFlag(connectTimeoutSeconds))
sshArguments = append(sshArguments, ssh.ServerAliveFlags(serverAliveIntervalSeconds, serverAliveCountMax)...)
if t.port != 0 {
Expand Down
13 changes: 13 additions & 0 deletions pkg/agent/transport/ssh/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,16 @@ func TestCommandOutput(t *testing.T) {
t.Error("output not in UTF-8 encoding")
}
}

func TestSSHConfigArguments(t *testing.T) {
t.Setenv("MUTAGEN_SSH_CONFIG_PATH", "")
if arguments := sshConfigArguments(); len(arguments) != 0 {
t.Fatal("unexpected SSH configuration arguments:", arguments)
}

t.Setenv("MUTAGEN_SSH_CONFIG_PATH", "none")
arguments := sshConfigArguments()
if len(arguments) != 2 || arguments[0] != "-F" || arguments[1] != "none" {
t.Fatal("unexpected SSH configuration arguments:", arguments)
}
}
Loading