in pkg/client/ssh/ssh.go [33:57]
func (client *SSHClient) RunCommand(cmd *SSHCommand) (out []byte, err error) {
session, connection, err := client.NewSession()
if err != nil {
return nil, err
}
defer func() {
closeErr := session.Close()
if closeErr != nil && !errors.Is(closeErr, io.EOF) {
client.log.Error(closeErr, "failed to close SSH session")
}
closeErr = connection.Close()
if closeErr != nil && !errors.Is(closeErr, io.EOF) {
client.log.Error(closeErr, "failed to close SSH connection")
}
}()
out, err = session.Output(cmd.Path)
if err != nil {
return nil, fmt.Errorf("failed to exec cmd %q on the remote host, %w", cmd.Path, err)
}
return
}