summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2020-05-13 11:01:57 +0100
committerPaul Buetow <pbuetow@mimecast.com>2020-05-13 11:01:57 +0100
commite0b1bbb42f88a165965a340e614db6e86f66b8a6 (patch)
tree7d88c0534c83a368463fbcf4d724012e871d4b00 /internal
parent1c56e05adcdd8846708557d631dfb6f73bc26db0 (diff)
refactor
Diffstat (limited to 'internal')
-rw-r--r--internal/clients/remote/connection.go24
-rw-r--r--internal/ssh/client/authmethods.go9
2 files changed, 17 insertions, 16 deletions
diff --git a/internal/clients/remote/connection.go b/internal/clients/remote/connection.go
index 5941115..2d97d14 100644
--- a/internal/clients/remote/connection.go
+++ b/internal/clients/remote/connection.go
@@ -93,31 +93,31 @@ func (c *Connection) initServerPort(server string) {
// Start the server connection. Build up SSH session and send some DTail commands.
func (c *Connection) Start(ctx context.Context, cancel context.CancelFunc, throttleCh, statsCh chan struct{}) {
// Throttle how many connections can be established concurrently (based on ch length)
- logger.Debug("Throttling connection", len(throttleCh), cap(throttleCh))
+ logger.Debug(c.Server, "Throttling connection", len(throttleCh), cap(throttleCh))
select {
case throttleCh <- struct{}{}:
case <-ctx.Done():
- logger.Debug("Not establishing connection as context is done", len(throttleCh), cap(throttleCh), c.Server)
+ logger.Debug(c.Server, "Not establishing connection as context is done", len(throttleCh), cap(throttleCh))
return
}
- logger.Debug("Throttling says that the connection can be established", len(throttleCh), cap(throttleCh), c.Server)
+ logger.Debug(c.Server, "Throttling says that the connection can be established", len(throttleCh), cap(throttleCh))
go func() {
defer func() {
if !c.throttlingDone {
- logger.Debug("Unthrottling connection (1)", len(throttleCh), cap(throttleCh), c.Server)
+ logger.Debug(c.Server, "Unthrottling connection (1)", len(throttleCh), cap(throttleCh))
c.throttlingDone = true
<-throttleCh
}
cancel()
}()
- if err := c.dial(ctx, cancel, c.Server, c.port, throttleCh, statsCh); err != nil {
+ if err := c.dial(ctx, cancel, throttleCh, statsCh); err != nil {
logger.Warn(c.Server, c.port, err)
if c.hostKeyCallback.Untrusted(fmt.Sprintf("%s:%d", c.Server, c.port)) {
- logger.Debug("Not trusting host", c.Server, c.port)
+ logger.Debug(c.Server, "Not trusting host")
}
}
}()
@@ -126,16 +126,16 @@ func (c *Connection) Start(ctx context.Context, cancel context.CancelFunc, throt
}
// Dail into a new SSH connection. Close connection in case of an error.
-func (c *Connection) dial(ctx context.Context, cancel context.CancelFunc, host string, port int, throttleCh, statsCh chan struct{}) error {
- logger.Debug("Incrementing connection stats", host)
+func (c *Connection) dial(ctx context.Context, cancel context.CancelFunc, throttleCh, statsCh chan struct{}) error {
+ logger.Debug(c.Server, "Incrementing connection stats")
statsCh <- struct{}{}
defer func() {
- logger.Debug("Decrementing connection stats", host)
+ logger.Debug(c.Server, "Decrementing connection stats")
<-statsCh
}()
- logger.Debug("Dialing into the connection", host)
- address := fmt.Sprintf("%s:%d", host, port)
+ logger.Debug(c.Server, "Dialing into the connection")
+ address := fmt.Sprintf("%s:%d", c.Server, c.port)
client, err := ssh.Dial("tcp", address, c.config)
if err != nil {
@@ -201,7 +201,7 @@ func (c *Connection) handle(ctx context.Context, cancel context.CancelFunc, sess
}
if !c.throttlingDone {
- logger.Debug("Unthrottling connection (2)", len(throttleCh), cap(throttleCh), c.Server)
+ logger.Debug(c.Server, "Unthrottling connection (2)", len(throttleCh), cap(throttleCh))
c.throttlingDone = true
<-throttleCh
}
diff --git a/internal/ssh/client/authmethods.go b/internal/ssh/client/authmethods.go
index 44c5601..a310159 100644
--- a/internal/ssh/client/authmethods.go
+++ b/internal/ssh/client/authmethods.go
@@ -27,24 +27,24 @@ func initKnownHostsAuthMethods(trustAllHosts bool, throttleCh chan struct{}) ([]
var sshAuthMethods []gossh.AuthMethod
if config.Common.ExperimentalFeaturesEnable {
sshAuthMethods = append(sshAuthMethods, gossh.Password("experimental feature test"))
- logger.Info("Added experimental method to list of auth methods")
+ logger.Debug("Added experimental method to list of auth methods")
}
keyPath := os.Getenv("HOME") + "/.ssh/id_rsa"
if authMethod, err := ssh.PrivateKey(keyPath); err == nil {
sshAuthMethods = append(sshAuthMethods, authMethod)
- logger.Info("Added path to list of auth methods", keyPath)
+ logger.Debug("Added path to list of auth methods", keyPath)
}
keyPath = os.Getenv("HOME") + "/.ssh/id_dsa"
if authMethod, err := ssh.PrivateKey(keyPath); err == nil {
sshAuthMethods = append(sshAuthMethods, authMethod)
- logger.Info("Added path to list of auth methods", keyPath)
+ logger.Debug("Added path to list of auth methods", keyPath)
}
if authMethod, err := ssh.Agent(); err == nil {
sshAuthMethods = append(sshAuthMethods, authMethod)
- logger.Info("Added SSH Agent to list of auth methods")
+ logger.Debug("Added SSH Agent to list of auth methods")
}
knownHostsPath := os.Getenv("HOME") + "/.ssh/known_hosts"
@@ -52,6 +52,7 @@ func initKnownHostsAuthMethods(trustAllHosts bool, throttleCh chan struct{}) ([]
if err != nil {
logger.FatalExit(knownHostsPath, err)
}
+ logger.Debug("Added known hosts file path", knownHostsPath)
return sshAuthMethods, knownHostsCallback
}