@@ -58,7 +58,7 @@ func execute(command cacao.Command,
5858 if err != nil {
5959 return cacao .NewVariables (), err
6060 }
61- defer client . Close ( )
61+ defer close ( client )
6262
6363 return executeCommand (session , command )
6464}
@@ -72,11 +72,15 @@ func executeCommand(session *ssh.Session,
7272 log .Error (err )
7373 return cacao .NewVariables (), err
7474 }
75- defer session .Close ()
7675 results := cacao .NewVariables (cacao.Variable {Type : cacao .VariableTypeString ,
7776 Name : sshResultVariableName ,
7877 Value : string (response )})
7978 log .Trace ("Finished ssh execution will return the variables: " , results )
79+ sessionErr := session .Close ()
80+ if sessionErr != nil {
81+ log .Error (sessionErr )
82+ }
83+
8084 return results , err
8185}
8286
@@ -118,7 +122,7 @@ func getSession(config ssh.ClientConfig, target cacao.AgentTarget) (*ssh.Session
118122 session , err := client .NewSession ()
119123 if err != nil {
120124 log .Error (err )
121- client . Close ( )
125+ close ( client )
122126 return nil , nil , err
123127 }
124128 return session , client , err
@@ -149,16 +153,27 @@ func CheckSshAuthenticationInfo(authentication cacao.AuthenticationInformation)
149153 if strings .TrimSpace (authentication .Username ) == "" {
150154 return errors .New ("username is empty" )
151155 }
152- if authentication .Type == "user-auth" {
156+
157+ switch authentication .Type {
158+ case "user-auth" :
153159 if strings .TrimSpace (authentication .Password ) == "" {
154160 return errors .New ("password is empty" )
155161 }
156- } else if authentication . Type == "private-key" {
162+ case "private-key" :
157163 if strings .TrimSpace (authentication .PrivateKey ) == "" {
158164 return errors .New ("private key is not set" )
159165 }
160- } else {
166+ default :
161167 return errors .New ("non supported authentication type" )
162168 }
163169 return nil
164170}
171+
172+ func close (client * ssh.Client ) {
173+ if client != nil {
174+ err := client .Close ()
175+ if err != nil {
176+ log .Error (err )
177+ }
178+ }
179+ }
0 commit comments