mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-05-09 18:23:21 +08:00
upgrade easyssh to 1.1.6
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
26b3d47ee2
commit
586606ddec
@ -92,12 +92,12 @@ func (p Plugin) Exec() error {
|
|||||||
errChannel <- err
|
errChannel <- err
|
||||||
} else {
|
} else {
|
||||||
// read from the output channel until the done signal is passed
|
// read from the output channel until the done signal is passed
|
||||||
stillGoing := true
|
|
||||||
isTimeout := true
|
isTimeout := true
|
||||||
for stillGoing {
|
loop:
|
||||||
|
for {
|
||||||
select {
|
select {
|
||||||
case isTimeout = <-doneChan:
|
case isTimeout = <-doneChan:
|
||||||
stillGoing = false
|
break loop
|
||||||
case outline := <-stdoutChan:
|
case outline := <-stdoutChan:
|
||||||
p.log(host, "out:", outline)
|
p.log(host, "out:", outline)
|
||||||
case errline := <-stderrChan:
|
case errline := <-stderrChan:
|
||||||
|
57
vendor/github.com/appleboy/easyssh-proxy/README.md
generated
vendored
57
vendor/github.com/appleboy/easyssh-proxy/README.md
generated
vendored
@ -1,6 +1,11 @@
|
|||||||
# easyssh-proxy
|
# easyssh-proxy
|
||||||
|
|
||||||
[](https://godoc.org/github.com/appleboy/easyssh-proxy) [](http://drone.wu-boy.com/appleboy/easyssh-proxy) [](https://codecov.io/gh/appleboy/easyssh-proxy) [](https://goreportcard.com/report/github.com/appleboy/easyssh-proxy) [](https://sourcegraph.com/github.com/appleboy/easyssh-proxy?badge)
|
[](https://godoc.org/github.com/appleboy/easyssh-proxy)
|
||||||
|
[](http://drone.wu-boy.com/appleboy/easyssh-proxy)
|
||||||
|
[](https://codecov.io/gh/appleboy/easyssh-proxy)
|
||||||
|
[](https://goreportcard.com/report/github.com/appleboy/easyssh-proxy)
|
||||||
|
[](https://sourcegraph.com/github.com/appleboy/easyssh-proxy?badge)
|
||||||
|
[](https://github.com/appleboy/easyssh-proxy/releases/latest)
|
||||||
|
|
||||||
easyssh-proxy provides a simple implementation of some SSH protocol features in Go.
|
easyssh-proxy provides a simple implementation of some SSH protocol features in Go.
|
||||||
|
|
||||||
@ -124,3 +129,53 @@ See [example/proxy/proxy.go](./example/proxy/proxy.go)
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### SSH Stream Log
|
||||||
|
|
||||||
|
See [example/stream/stream.go](./example/stream/stream.go)
|
||||||
|
|
||||||
|
[embedmd]:# (example/stream/stream.go go /func/ /^}$/)
|
||||||
|
```go
|
||||||
|
func main() {
|
||||||
|
// Create MakeConfig instance with remote username, server address and path to private key.
|
||||||
|
ssh := &easyssh.MakeConfig{
|
||||||
|
Server: "localhost",
|
||||||
|
User: "drone-scp",
|
||||||
|
KeyPath: "./tests/.ssh/id_rsa",
|
||||||
|
Port: "22",
|
||||||
|
Timeout: 60 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call Run method with command you want to run on remote server.
|
||||||
|
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream("for i in {1..5}; do echo ${i}; sleep 1; done; exit 2;", 60)
|
||||||
|
// Handle errors
|
||||||
|
if err != nil {
|
||||||
|
panic("Can't run remote command: " + err.Error())
|
||||||
|
} else {
|
||||||
|
// read from the output channel until the done signal is passed
|
||||||
|
isTimeout := true
|
||||||
|
loop:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case isTimeout = <-doneChan:
|
||||||
|
break loop
|
||||||
|
case outline := <-stdoutChan:
|
||||||
|
fmt.Println("out:", outline)
|
||||||
|
case errline := <-stderrChan:
|
||||||
|
fmt.Println("err:", errline)
|
||||||
|
case err = <-errChan:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// get exit code or command error.
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("err: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// command time out
|
||||||
|
if !isTimeout {
|
||||||
|
fmt.Println("Error: command timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
39
vendor/github.com/appleboy/easyssh-proxy/easyssh.go
generated
vendored
39
vendor/github.com/appleboy/easyssh-proxy/easyssh.go
generated
vendored
@ -156,25 +156,31 @@ func (ssh_conf *MakeConfig) connect() (*ssh.Session, error) {
|
|||||||
// Stream returns one channel that combines the stdout and stderr of the command
|
// Stream returns one channel that combines the stdout and stderr of the command
|
||||||
// as it is run on the remote machine, and another that sends true when the
|
// as it is run on the remote machine, and another that sends true when the
|
||||||
// command is done. The sessions and channels will then be closed.
|
// command is done. The sessions and channels will then be closed.
|
||||||
func (ssh_conf *MakeConfig) Stream(command string, timeout int) (stdout chan string, stderr chan string, done chan bool, errChan chan error, err error) {
|
func (ssh_conf *MakeConfig) Stream(command string, timeout int) (<-chan string, <-chan string, <-chan bool, <-chan error, error) {
|
||||||
|
// continuously send the command's output over the channel
|
||||||
|
stdoutChan := make(chan string)
|
||||||
|
stderrChan := make(chan string)
|
||||||
|
doneChan := make(chan bool)
|
||||||
|
errChan := make(chan error)
|
||||||
|
|
||||||
// connect to remote host
|
// connect to remote host
|
||||||
session, err := ssh_conf.connect()
|
session, err := ssh_conf.connect()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stdout, stderr, done, errChan, err
|
return stdoutChan, stderrChan, doneChan, errChan, err
|
||||||
}
|
}
|
||||||
// defer session.Close()
|
// defer session.Close()
|
||||||
// connect to both outputs (they are of type io.Reader)
|
// connect to both outputs (they are of type io.Reader)
|
||||||
outReader, err := session.StdoutPipe()
|
outReader, err := session.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stdout, stderr, done, errChan, err
|
return stdoutChan, stderrChan, doneChan, errChan, err
|
||||||
}
|
}
|
||||||
errReader, err := session.StderrPipe()
|
errReader, err := session.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stdout, stderr, done, errChan, err
|
return stdoutChan, stderrChan, doneChan, errChan, err
|
||||||
}
|
}
|
||||||
err = session.Start(command)
|
err = session.Start(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stdout, stderr, done, errChan, err
|
return stdoutChan, stderrChan, doneChan, errChan, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// combine outputs, create a line-by-line scanner
|
// combine outputs, create a line-by-line scanner
|
||||||
@ -182,16 +188,11 @@ func (ssh_conf *MakeConfig) Stream(command string, timeout int) (stdout chan str
|
|||||||
stderrReader := io.MultiReader(errReader)
|
stderrReader := io.MultiReader(errReader)
|
||||||
stdoutScanner := bufio.NewScanner(stdoutReader)
|
stdoutScanner := bufio.NewScanner(stdoutReader)
|
||||||
stderrScanner := bufio.NewScanner(stderrReader)
|
stderrScanner := bufio.NewScanner(stderrReader)
|
||||||
// continuously send the command's output over the channel
|
|
||||||
stdoutChan := make(chan string)
|
|
||||||
stderrChan := make(chan string)
|
|
||||||
done = make(chan bool)
|
|
||||||
errChan = make(chan error)
|
|
||||||
|
|
||||||
go func(stdoutScanner, stderrScanner *bufio.Scanner, stdoutChan, stderrChan chan string, done chan bool, errChan chan error) {
|
go func(stdoutScanner, stderrScanner *bufio.Scanner, stdoutChan, stderrChan chan string, doneChan chan bool, errChan chan error) {
|
||||||
defer close(stdoutChan)
|
defer close(stdoutChan)
|
||||||
defer close(stderrChan)
|
defer close(stderrChan)
|
||||||
defer close(done)
|
defer close(doneChan)
|
||||||
defer close(errChan)
|
defer close(errChan)
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
|
|
||||||
@ -212,15 +213,15 @@ func (ssh_conf *MakeConfig) Stream(command string, timeout int) (stdout chan str
|
|||||||
select {
|
select {
|
||||||
case <-res:
|
case <-res:
|
||||||
errChan <- session.Wait()
|
errChan <- session.Wait()
|
||||||
done <- true
|
doneChan <- true
|
||||||
case <-timeoutChan:
|
case <-timeoutChan:
|
||||||
stderrChan <- "Run Command Timeout!"
|
stderrChan <- "Run Command Timeout!"
|
||||||
errChan <- nil
|
errChan <- nil
|
||||||
done <- false
|
doneChan <- false
|
||||||
}
|
}
|
||||||
}(stdoutScanner, stderrScanner, stdoutChan, stderrChan, done, errChan)
|
}(stdoutScanner, stderrScanner, stdoutChan, stderrChan, doneChan, errChan)
|
||||||
|
|
||||||
return stdoutChan, stderrChan, done, errChan, err
|
return stdoutChan, stderrChan, doneChan, errChan, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run command on remote machine and returns its stdout as a string
|
// Run command on remote machine and returns its stdout as a string
|
||||||
@ -230,11 +231,11 @@ func (ssh_conf *MakeConfig) Run(command string, timeout int) (outStr string, err
|
|||||||
return outStr, errStr, isTimeout, err
|
return outStr, errStr, isTimeout, err
|
||||||
}
|
}
|
||||||
// read from the output channel until the done signal is passed
|
// read from the output channel until the done signal is passed
|
||||||
stillGoing := true
|
loop:
|
||||||
for stillGoing {
|
for {
|
||||||
select {
|
select {
|
||||||
case isTimeout = <-doneChan:
|
case isTimeout = <-doneChan:
|
||||||
stillGoing = false
|
break loop
|
||||||
case outline := <-stdoutChan:
|
case outline := <-stdoutChan:
|
||||||
if outline != "" {
|
if outline != "" {
|
||||||
outStr += outline + "\n"
|
outStr += outline + "\n"
|
||||||
|
10
vendor/vendor.json
vendored
10
vendor/vendor.json
vendored
@ -3,12 +3,12 @@
|
|||||||
"ignore": "test",
|
"ignore": "test",
|
||||||
"package": [
|
"package": [
|
||||||
{
|
{
|
||||||
"checksumSHA1": "YgrgNVNBf7Ro0f3KuiHewOCHrwo=",
|
"checksumSHA1": "EcF7T9tPEMMJfuRdPBB3NdRUg4c=",
|
||||||
"path": "github.com/appleboy/easyssh-proxy",
|
"path": "github.com/appleboy/easyssh-proxy",
|
||||||
"revision": "14882d1d04ac6a85700586997695fcd936470e86",
|
"revision": "33d87eae3a018c3312e32cc4eb4578d5a563aabd",
|
||||||
"revisionTime": "2017-05-11T07:07:30Z",
|
"revisionTime": "2017-05-16T07:22:25Z",
|
||||||
"version": "1.1.5",
|
"version": "1.1.6",
|
||||||
"versionExact": "1.1.5"
|
"versionExact": "1.1.6"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "dvabztWVQX8f6oMLRyv4dLH+TGY=",
|
"checksumSHA1": "dvabztWVQX8f6oMLRyv4dLH+TGY=",
|
||||||
|
Loading…
Reference in New Issue
Block a user