Skip to content

Commit

Permalink
make a clone of the host when iterating over gateways
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Feb 3, 2016
1 parent ddb5f02 commit 21cb898
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/commands/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,24 @@ func proxy(host *config.Host, conf *config.Config, dryRun bool) error {
Logger.Errorf("Failed to use 'direct' connection: %v", err)
}
} else {
hostCopy := host.Clone()
gatewayHost := conf.GetGatewaySafe(gateway)

err := prepareHostControlPath(host, gatewayHost)
err := prepareHostControlPath(hostCopy, gatewayHost)
if err != nil {
return err
}

if host.ProxyCommand == "" {
host.ProxyCommand = "nc %h %p"
if hostCopy.ProxyCommand == "" {
hostCopy.ProxyCommand = "nc %h %p"
}
// FIXME: dynamically add "-v" flags

if err = hostPrepare(host); err != nil {
if err = hostPrepare(hostCopy); err != nil {
return err
}

command := "ssh %name -- " + host.ExpandString(host.ProxyCommand)
command := "ssh %name -- " + hostCopy.ExpandString(hostCopy.ProxyCommand)

Logger.Debugf("Using gateway '%s': %s", gateway, command)
err = proxyCommand(gatewayHost, command, dryRun)
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,17 @@ func NewHost(name string) *Host {
}
}

// Name returns the name of a host
func (h *Host) Name() string {
return h.name
}

// Clone returns a copy of an existing Host
func (h *Host) Clone() *Host {
newHost := *h
return &newHost
}

// ApplyDefaults ensures a Host is valid by filling the missing fields with defaults
func (h *Host) ApplyDefaults(defaults *Host) {
// ssh-config fields
Expand Down

0 comments on commit 21cb898

Please sign in to comment.