summaryrefslogtreecommitdiff
path: root/internal/clients
diff options
context:
space:
mode:
authorPaul Buetow <git@mx.buetow.org>2020-11-16 22:11:44 +0000
committerPaul Buetow <git@mx.buetow.org>2020-11-16 22:11:44 +0000
commit7df612f527bd5dc2e785bf766d7d61124c260b94 (patch)
tree9d1674b4fe3d7e492afeefc839009e5b11d5fe27 /internal/clients
parent3c889d2eed4e12af505ea84d46d8e52d21057a1f (diff)
remove drun command for simplicity. only focus on interactive commands dealing with log streams
Diffstat (limited to 'internal/clients')
-rw-r--r--internal/clients/runclient.go87
1 files changed, 0 insertions, 87 deletions
diff --git a/internal/clients/runclient.go b/internal/clients/runclient.go
deleted file mode 100644
index 5464d54..0000000
--- a/internal/clients/runclient.go
+++ /dev/null
@@ -1,87 +0,0 @@
-package clients
-
-import (
- "crypto/sha256"
- "encoding/base64"
- "encoding/hex"
- "fmt"
- "runtime"
- "strings"
-
- "github.com/mimecast/dtail/internal/clients/handlers"
- "github.com/mimecast/dtail/internal/io/logger"
- "github.com/mimecast/dtail/internal/omode"
-)
-
-// RunClient is a client to run various commands on the server.
-type RunClient struct {
- baseClient
- jobName string
- background string
-}
-
-// NewRunClient returns a new run client to execute commands on the remote server.
-func NewRunClient(args Args, background, jobName string) (*RunClient, error) {
- args.Mode = omode.RunClient
-
- if jobName == "" {
- jobName = hash(strings.Join(args.Arguments, " "))
- }
-
- c := RunClient{
- baseClient: baseClient{
- Args: args,
- throttleCh: make(chan struct{}, args.ConnectionsPerCPU*runtime.NumCPU()),
- retry: false,
- },
- jobName: jobName,
- background: background,
- }
-
- c.init()
- c.makeConnections(c)
-
- return &c, nil
-}
-
-func (c RunClient) makeHandler(server string) handlers.Handler {
- return handlers.NewClientHandler(server)
-}
-
-func (c RunClient) makeCommands() (commands []string) {
- if c.Timeout > 0 {
- commands = append(commands, fmt.Sprintf("timeout %d run%s %s", c.Timeout, c.options(), c.What))
- return
- }
-
- commands = append(commands, fmt.Sprintf("run%s %s", c.options(), c.What))
- return
-}
-
-func (c RunClient) options() string {
- var sb strings.Builder
-
- logger.Debug("options", fmt.Sprintf(":background=%s", c.background))
- sb.WriteString(fmt.Sprintf(":background=%s", c.background))
-
- logger.Debug("options", fmt.Sprintf(":jobName=%s", c.jobName))
- sb.WriteString(fmt.Sprintf(":jobName=%s", c.jobName))
-
- if len(c.Arguments) > 0 {
- logger.Debug("options", fmt.Sprintf(":outerArgs=base64%%%s", strings.Join(c.Arguments, " ")))
- sb.WriteString(fmt.Sprintf(":outerArgs=base64%%%s", encode64(strings.Join(c.Arguments, " "))))
- }
-
- return sb.String()
-}
-
-func encode64(str string) string {
- return base64.StdEncoding.EncodeToString([]byte(str))
-}
-
-func hash(str string) string {
- h := sha256.New()
- h.Write([]byte(str))
-
- return hex.EncodeToString(h.Sum(nil))
-}