diff options
author | openshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com> | 2021-08-02 17:15:54 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-02 17:15:54 +0000 |
commit | bdbc21095a377a723df1f5c36fdc70273fe9a471 (patch) | |
tree | 107c854c67dd7baf8bd63b11f5404de8bd642f74 /cmd/podman/system/connection/shared.go | |
parent | 0e2a7be0ec825449a1b95bd5df13e2519c67dcb4 (diff) | |
parent | 1d10ca739f3599b9bd746783ad15c8f51ce9f75c (diff) | |
download | podman-bdbc21095a377a723df1f5c36fdc70273fe9a471.tar.gz podman-bdbc21095a377a723df1f5c36fdc70273fe9a471.tar.bz2 podman-bdbc21095a377a723df1f5c36fdc70273fe9a471.zip |
Merge pull request #10828 from cdoern/scp
Created image scp feature
Diffstat (limited to 'cmd/podman/system/connection/shared.go')
-rw-r--r-- | cmd/podman/system/connection/shared.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cmd/podman/system/connection/shared.go b/cmd/podman/system/connection/shared.go new file mode 100644 index 000000000..3fd7c59fb --- /dev/null +++ b/cmd/podman/system/connection/shared.go @@ -0,0 +1,28 @@ +package connection + +import ( + "bytes" + + "github.com/pkg/errors" + "golang.org/x/crypto/ssh" +) + +// ExecRemoteCommand takes a ssh client connection and a command to run and executes the +// command on the specified client. The function returns the Stdout from the client or the Stderr +func ExecRemoteCommand(dial *ssh.Client, run string) (string, error) { + sess, err := dial.NewSession() // new ssh client session + if err != nil { + return "", err + } + defer sess.Close() + + var buffer bytes.Buffer + var bufferErr bytes.Buffer + sess.Stdout = &buffer // output from client funneled into buffer + sess.Stderr = &bufferErr // err form client funneled into buffer + if err := sess.Run(run); err != nil { // run the command on the ssh client + return "", errors.Wrapf(err, bufferErr.String()) + } + out := buffer.String() // output from command + return out, nil +} |