1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
package ssh
import (
"errors"
"io"
"golang.org/x/crypto/ssh"
)
func Create(options *ConnectionCreateOptions, kind EngineMode) error {
if kind == NativeMode {
return nativeConnectionCreate(*options)
}
return golangConnectionCreate(*options)
}
func Dial(options *ConnectionDialOptions, kind EngineMode) (*ssh.Client, error) {
var rep *ConnectionDialReport
var err error
if kind == NativeMode {
return nil, errors.New("ssh dial failed: you cannot create a dial-able client with native ssh")
}
rep, err = golangConnectionDial(*options)
if err != nil {
return nil, err
}
return rep.Client, nil
}
func Exec(options *ConnectionExecOptions, kind EngineMode) (string, error) {
return ExecWithInput(options, kind, nil)
}
func ExecWithInput(options *ConnectionExecOptions, kind EngineMode, input io.Reader) (string, error) {
var rep *ConnectionExecReport
var err error
if kind == NativeMode {
rep, err = nativeConnectionExec(*options, input)
if err != nil {
return "", err
}
} else {
rep, err = golangConnectionExec(*options, input)
if err != nil {
return "", err
}
}
return rep.Response, nil
}
func Scp(options *ConnectionScpOptions, kind EngineMode) (string, error) {
var rep *ConnectionScpReport
var err error
if kind == NativeMode {
if rep, err = nativeConnectionScp(*options); err != nil {
return "", err
}
return rep.Response, nil
}
if rep, err = golangConnectionScp(*options); err != nil {
return "", err
}
return rep.Response, nil
}
|