bugfix: Fixed unusual issues that slipped through with shellAfterCompleted (#425)
* bugfix: Fixed unusual issues that slipped through with shellAfterCompleted #419 #420 * cicd: Fix broken style lint
This commit is contained in:
parent
5d82ae7680
commit
6c289506c2
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue