From 92e0b057fd667e4c754342052beb9d803c9ca98c Mon Sep 17 00:00:00 2001 From: "Luis Gustavo S. Barreto" Date: Wed, 2 May 2018 14:53:18 -0300 Subject: [PATCH] Add support for passing payload to command STDIN --- builtin/bins/dkron-executor-shell/shell.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/builtin/bins/dkron-executor-shell/shell.go b/builtin/bins/dkron-executor-shell/shell.go index 6a6772f1a..b632917f9 100644 --- a/builtin/bins/dkron-executor-shell/shell.go +++ b/builtin/bins/dkron-executor-shell/shell.go @@ -1,6 +1,7 @@ package main import ( + "encoding/base64" "log" "os" "os/exec" @@ -54,6 +55,21 @@ func (s *Shell) Execute(args *dkron.ExecuteRequest) ([]byte, error) { }) defer slowTimer.Stop() + stdin, err := cmd.StdinPipe() + if err != nil { + return nil, err + } + + defer stdin.Close() + + payload, err := base64.StdEncoding.DecodeString(args.Config["payload"]) + if err != nil { + return nil, err + } + + stdin.Write(payload) + stdin.Close() + log.Printf("shell: going to run %s", command) err = cmd.Start() if err != nil {