summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Bütow <pbuetow@mimecast.com>2020-01-22 13:08:13 +0000
committerPaul Bütow <pbuetow@mimecast.com>2020-01-22 13:08:13 +0000
commitce1663bacc1c83983ba9e4446d07b6d79d004b9c (patch)
tree351dc9d4b2266256f5b38ad284abc59211dddc7e
parentbd683ec4a63b01255274ab6f2463c95a49695e90 (diff)
add execclient
-rw-r--r--internal/clients/execclient.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/internal/clients/execclient.go b/internal/clients/execclient.go
new file mode 100644
index 0000000..10bd081
--- /dev/null
+++ b/internal/clients/execclient.go
@@ -0,0 +1,48 @@
+package clients
+
+import (
+ "fmt"
+ "runtime"
+ "strings"
+
+ "github.com/mimecast/dtail/internal/clients/handlers"
+ "github.com/mimecast/dtail/internal/clients/remote"
+ "github.com/mimecast/dtail/internal/omode"
+ "github.com/mimecast/dtail/internal/ssh/client"
+
+ gossh "golang.org/x/crypto/ssh"
+)
+
+// ExecClient is a client for execute various commands on the server.
+type ExecClient struct {
+ baseClient
+}
+
+// NewExecClient returns a new cat client.
+func NewExecClient(args Args) (*ExecClient, error) {
+ args.Regex = "."
+ args.Mode = omode.ExecClient
+
+ c := ExecClient{
+ baseClient: baseClient{
+ Args: args,
+ stop: make(chan struct{}),
+ stopped: make(chan struct{}),
+ throttleCh: make(chan struct{}, args.ConnectionsPerCPU*runtime.NumCPU()),
+ retry: false,
+ },
+ }
+
+ c.init(c)
+
+ return &c, nil
+}
+
+func (c ExecClient) makeConnection(server string, sshAuthMethods []gossh.AuthMethod, hostKeyCallback *client.HostKeyCallback) *remote.Connection {
+ conn := remote.NewConnection(server, c.UserName, sshAuthMethods, hostKeyCallback)
+ conn.Handler = handlers.NewClientHandler(server, c.PingTimeout)
+ for _, file := range strings.Split(c.Files, ";") {
+ conn.Commands = append(conn.Commands, fmt.Sprintf("%s %s", c.Mode.String(), file))
+ }
+ return conn
+}