From 2cecd9f8b997cf66cac3f88d7c4dd077f1b89fa0 Mon Sep 17 00:00:00 2001 From: mashiike Date: Mon, 7 Feb 2022 18:09:52 +0900 Subject: [PATCH 1/4] fix envrions --- flexentry.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/flexentry.go b/flexentry.go index 6345110..1aa9b1e 100644 --- a/flexentry.go +++ b/flexentry.go @@ -54,14 +54,28 @@ func (e *Entrypoint) Execute(ctx context.Context, opt *ExecuteOption, commands . func (e *Entrypoint) getHandler(args ...string) func(ctx context.Context, event Event) (interface{}, error) { return func(ctx context.Context, event Event) (interface{}, error) { + log.Println("[debug] event:", event) commands, err := e.DetectCommand(ctx, event) if err != nil { log.Println("[error] ", err) return nil, err } + environ, err := e.DetectEnviron(ctx, event) + if err != nil { + log.Println("[error] ", err) + return nil, err + } + if len(environ) > 0 { + for _, e := range environ { + log.Println("[debug] ", e) + } + } else { + environ = []string{} + } opt := &ExecuteOption{ - Stderr: os.Stderr, - Stdout: os.Stdout, + Stderr: os.Stderr, + Stdout: os.Stdout, + Environ: environ, } var bufInput, bufOutput bytes.Buffer if err := json.NewEncoder(&bufInput).Encode(event); err != nil { From 4e818039572a2a34da5a4d5635baa94a87212701 Mon Sep 17 00:00:00 2001 From: mashiike Date: Mon, 7 Feb 2022 18:12:36 +0900 Subject: [PATCH 2/4] shell and shellArgs switch --- executer.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/executer.go b/executer.go index 51e2576..565e963 100644 --- a/executer.go +++ b/executer.go @@ -30,9 +30,17 @@ type ShellExecuter struct { } func NewShellExecuter() *ShellExecuter { + shell := "sh" + if s := os.Getenv("FLEXENTRY_SHELL"); s != "" { + shell = s + } + shellArgs := []string{"-c"} + if sArgs := os.Getenv("FLEXENTRY_SHELL_ARGS"); sArgs != "" { + shellArgs = strings.Split(sArgs, " ") + } return &ShellExecuter{ - shell: "sh", - shellArgs: []string{"-c"}, + shell: shell, + shellArgs: shellArgs, } } From 6d643c52d5d75af0392d8af117abb5647e49d884 Mon Sep 17 00:00:00 2001 From: mashiike Date: Mon, 7 Feb 2022 18:16:01 +0900 Subject: [PATCH 3/4] QUOTE ENV --- executer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/executer.go b/executer.go index 565e963..2a7aca2 100644 --- a/executer.go +++ b/executer.go @@ -47,7 +47,11 @@ func NewShellExecuter() *ShellExecuter { func (e *ShellExecuter) Execute(ctx context.Context, opt *ExecuteOption, commands ...string) error { args := make([]string, 0, len(e.shellArgs)+len(commands)) args = append(args, e.shellArgs...) - args = append(args, strings.Join(commands, " ")) + if os.Getenv("FLEXENTRY_QUATRE_COMMAND") != "" { + args = append(args, `"`+strings.Join(commands, " ")+`"`) + } else { + args = append(args, strings.Join(commands, " ")) + } log.Printf("[debug] $%s %s", e.shell, strings.Join(args, " ")) cmd := exec.CommandContext(ctx, e.shell, args...) From 834e0a0079c6bf2b12a6f3e0749782860dff98ec Mon Sep 17 00:00:00 2001 From: mashiike Date: Mon, 7 Feb 2022 18:16:20 +0900 Subject: [PATCH 4/4] fix typo --- executer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executer.go b/executer.go index 2a7aca2..607f401 100644 --- a/executer.go +++ b/executer.go @@ -47,7 +47,7 @@ func NewShellExecuter() *ShellExecuter { func (e *ShellExecuter) Execute(ctx context.Context, opt *ExecuteOption, commands ...string) error { args := make([]string, 0, len(e.shellArgs)+len(commands)) args = append(args, e.shellArgs...) - if os.Getenv("FLEXENTRY_QUATRE_COMMAND") != "" { + if os.Getenv("FLEXENTRY_QUOTE_COMMAND") != "" { args = append(args, `"`+strings.Join(commands, " ")+`"`) } else { args = append(args, strings.Join(commands, " "))