diff --git a/internal/executor/arguments.go b/internal/executor/arguments.go index 294b5b8..5f4640d 100644 --- a/internal/executor/arguments.go +++ b/internal/executor/arguments.go @@ -23,35 +23,51 @@ var ( } ) +func parseCommandForReplacements(rawShellCommand string, values map[string]string) (string, map[string]string, error) { + r := regexp.MustCompile("{{ *?([a-zA-Z0-9_]+?) *?}}") + foundArgumentNames := r.FindAllStringSubmatch(rawShellCommand, -1) + + usedArguments := make(map[string]string) + + for _, match := range foundArgumentNames { + argName := match[1] + argValue, argProvided := values[argName] + + if !argProvided { + return "", nil, errors.New("Required arg not provided: " + argName) + } + + usedArguments[argName] = argValue + + rawShellCommand = strings.ReplaceAll(rawShellCommand, match[0], argValue) + } + + return rawShellCommand, usedArguments, nil +} + func parseActionArguments(rawShellCommand string, values map[string]string, action *config.Action, actionTitle string, entityPrefix string) (string, error) { log.WithFields(log.Fields{ "actionTitle": actionTitle, "cmd": rawShellCommand, }).Infof("Action parse args - Before") - r := regexp.MustCompile("{{ *?([a-zA-Z0-9_]+?) *?}}") - matches := r.FindAllStringSubmatch(rawShellCommand, -1) + rawShellCommand, usedArgs, err := parseCommandForReplacements(rawShellCommand, values) - for _, match := range matches { - argValue, argProvided := values[match[1]] + if err != nil { + return "", err + } - if !argProvided { - log.Infof("%v", values) - return "", errors.New("Required arg not provided: " + match[1]) - } - - err := typecheckActionArgument(match[1], argValue, action) + for argName, argValue := range usedArgs { + err := typecheckActionArgument(argName, argValue, action) if err != nil { return "", err } log.WithFields(log.Fields{ - "name": match[1], + "name": argName, "value": argValue, }).Debugf("Arg assigned") - - rawShellCommand = strings.ReplaceAll(rawShellCommand, match[0], argValue) } rawShellCommand = sv.ReplaceEntityVars(entityPrefix, rawShellCommand) diff --git a/internal/executor/executor.go b/internal/executor/executor.go index 23b2ae7..12332af 100644 --- a/internal/executor/executor.go +++ b/internal/executor/executor.go @@ -528,7 +528,14 @@ func stepExecAfter(req *ExecutionRequest) bool { "exitCode": fmt.Sprintf("%v", req.logEntry.ExitCode), } - finalParsedCommand, _ := parseActionArguments(req.Action.ShellAfterCompleted, args, req.Action, req.logEntry.ActionTitle, req.EntityPrefix) + finalParsedCommand, _, err := parseCommandForReplacements(req.Action.ShellAfterCompleted, args) + + if err != nil { + msg := "Could not prepare shellAfterCompleted command: " + err.Error() + "\n" + req.logEntry.Output += msg + log.Warnf(msg) + return true + } cmd := wrapCommandInShell(ctx, finalParsedCommand) cmd.Stdout = &stdout @@ -538,14 +545,14 @@ func stepExecAfter(req *ExecutionRequest) bool { waiterr := cmd.Wait() - req.logEntry.Output += "\n" + stdout.String() - req.logEntry.Output += "OliveTin::shellAfterCompleted stdout\n" + stdout.String() + req.logEntry.Output += "\n" + req.logEntry.Output += "OliveTin::shellAfterCompleted stdout\n" req.logEntry.Output += stdout.String() - req.logEntry.Output += "OliveTin::shellAfterCompleted stderr\n" + stdout.String() + req.logEntry.Output += "OliveTin::shellAfterCompleted stderr\n" req.logEntry.Output += stderr.String() - req.logEntry.Output += "OliveTin::shellAfterCompleted errors and summary\n" + stdout.String() + req.logEntry.Output += "OliveTin::shellAfterCompleted errors and summary\n" appendErrorToStderr(runerr, req.logEntry) appendErrorToStderr(waiterr, req.logEntry) @@ -555,7 +562,7 @@ func stepExecAfter(req *ExecutionRequest) bool { req.logEntry.Output += fmt.Sprintf("Your shellAfterCompleted exited with code %v\n", cmd.ProcessState.ExitCode()) - req.logEntry.Output += "OliveTin::shellAfterCompleted output complete\n" + stdout.String() + req.logEntry.Output += "OliveTin::shellAfterCompleted output complete\n" return true } diff --git a/webui.dev/js/marshaller.js b/webui.dev/js/marshaller.js index ceef2c8..02a479a 100644 --- a/webui.dev/js/marshaller.js +++ b/webui.dev/js/marshaller.js @@ -34,12 +34,12 @@ function createAnnotation (key, val) { domAnnotation.appendChild(createElement('span', { innerText: key, - classNames: ['annotationKey'] + classNames: ['annotation-key'] })) domAnnotation.appendChild(createElement('span', { innerText: val, - classNames: ['annotationValue'] + classNames: ['annotation-value'] })) return domAnnotation diff --git a/webui.dev/style.css b/webui.dev/style.css index c02f3cf..9a64ee1 100644 --- a/webui.dev/style.css +++ b/webui.dev/style.css @@ -472,7 +472,7 @@ span.annotation { margin-right: .2em; } -span.annotationKey { +span.annotation-key { padding: 0.4em; border-radius: 0.4em 0 0 .4em; display: inline-block; @@ -480,7 +480,7 @@ span.annotationKey { color: #666; } -span.annotationValue { +span.annotation-value { padding: 0.4em; border-radius: 0 .4em .4em 0; display: inline-block;