2024-02-02 23:35:21 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2024-02-05 23:25:55 +00:00
|
|
|
// sshCheckResponse reads the output from the remote and returns an error
|
2024-02-02 23:35:21 +00:00
|
|
|
// if the remote output was not 0
|
2024-02-05 23:25:55 +00:00
|
|
|
func sshCheckResponse(remoteOutPipe io.Reader) error {
|
2024-02-02 23:35:21 +00:00
|
|
|
buffer := make([]uint8, 1)
|
|
|
|
_, err := remoteOutPipe.Read(buffer)
|
|
|
|
if err != nil {
|
2024-02-05 23:25:55 +00:00
|
|
|
return fmt.Errorf("ssh: failed to make read output buffer (%w)", err)
|
2024-02-02 23:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
responseType := buffer[0]
|
|
|
|
message := ""
|
|
|
|
if responseType > 0 {
|
|
|
|
bufferedReader := bufio.NewReader(remoteOutPipe)
|
|
|
|
message, err = bufferedReader.ReadString('\n')
|
|
|
|
if err != nil {
|
2024-02-05 23:25:55 +00:00
|
|
|
return fmt.Errorf("ssh: failed to read output buffer (%w)", err)
|
2024-02-02 23:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if not 0 (aka OK)
|
|
|
|
if responseType != 0 {
|
2024-02-05 23:25:55 +00:00
|
|
|
return fmt.Errorf("ssh: remote returned error (%d: %s)", responseType, message)
|
2024-02-02 23:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|