|
@@ -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) {
|
|
func parseActionArguments(rawShellCommand string, values map[string]string, action *config.Action, actionTitle string, entityPrefix string) (string, error) {
|
|
|
log.WithFields(log.Fields{
|
|
log.WithFields(log.Fields{
|
|
|
"actionTitle": actionTitle,
|
|
"actionTitle": actionTitle,
|
|
|
"cmd": rawShellCommand,
|
|
"cmd": rawShellCommand,
|
|
|
}).Infof("Action parse args - Before")
|
|
}).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 !argProvided {
|
|
|
|
|
- log.Infof("%v", values)
|
|
|
|
|
- return "", errors.New("Required arg not provided: " + match[1])
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return "", err
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- err := typecheckActionArgument(match[1], argValue, action)
|
|
|
|
|
|
|
+ for argName, argValue := range usedArgs {
|
|
|
|
|
+ err := typecheckActionArgument(argName, argValue, action)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return "", err
|
|
return "", err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
log.WithFields(log.Fields{
|
|
log.WithFields(log.Fields{
|
|
|
- "name": match[1],
|
|
|
|
|
|
|
+ "name": argName,
|
|
|
"value": argValue,
|
|
"value": argValue,
|
|
|
}).Debugf("Arg assigned")
|
|
}).Debugf("Arg assigned")
|
|
|
-
|
|
|
|
|
- rawShellCommand = strings.ReplaceAll(rawShellCommand, match[0], argValue)
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
rawShellCommand = sv.ReplaceEntityVars(entityPrefix, rawShellCommand)
|
|
rawShellCommand = sv.ReplaceEntityVars(entityPrefix, rawShellCommand)
|