This commit is contained in:
@@ -141,6 +141,12 @@ func init() {
|
|||||||
"print": true,
|
"print": true,
|
||||||
"silent": false
|
"silent": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"action": "exec",
|
||||||
|
"exec": "find / -name '*.json'",
|
||||||
|
"print": true,
|
||||||
|
"silent": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"action": "exec",
|
"action": "exec",
|
||||||
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Infile) \"\" }} \"/tmp/input.json\" {{- else }} {{ .Infile }} {{- end }} input.json -worksheetName \"{{ .WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Infile) \"\" }} \"/tmp/input.json\" {{- else }} {{ .Infile }} {{- end }} input.json -worksheetName \"{{ .WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
||||||
@@ -152,7 +158,7 @@ func init() {
|
|||||||
"exec": "base64 -w 0 /tmp/{{ .OutFilename }}"
|
"exec": "base64 -w 0 /tmp/{{ .OutFilename }}"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"output": "{\n \"export-excel\": {{ (index . 4).result | toJson }}\n}\n"
|
"output": "{\n \"export-excel\": {{ (index . 5).result | toJson }}\n}\n"
|
||||||
},
|
},
|
||||||
"x-direktiv-errors": {
|
"x-direktiv-errors": {
|
||||||
"io.direktiv.command.error": "Command execution failed",
|
"io.direktiv.command.error": "Command execution failed",
|
||||||
@@ -318,6 +324,12 @@ func init() {
|
|||||||
"print": true,
|
"print": true,
|
||||||
"silent": false
|
"silent": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"action": "exec",
|
||||||
|
"exec": "find / -name '*.json'",
|
||||||
|
"print": true,
|
||||||
|
"silent": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"action": "exec",
|
"action": "exec",
|
||||||
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Infile) \"\" }} \"/tmp/input.json\" {{- else }} {{ .Infile }} {{- end }} input.json -worksheetName \"{{ .WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Infile) \"\" }} \"/tmp/input.json\" {{- else }} {{ .Infile }} {{- end }} input.json -worksheetName \"{{ .WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
||||||
@@ -329,7 +341,7 @@ func init() {
|
|||||||
"exec": "base64 -w 0 /tmp/{{ .OutFilename }}"
|
"exec": "base64 -w 0 /tmp/{{ .OutFilename }}"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"output": "{\n \"export-excel\": {{ (index . 4).result | toJson }}\n}\n"
|
"output": "{\n \"export-excel\": {{ (index . 5).result | toJson }}\n}\n"
|
||||||
},
|
},
|
||||||
"x-direktiv-errors": {
|
"x-direktiv-errors": {
|
||||||
"io.direktiv.command.error": "Command execution failed",
|
"io.direktiv.command.error": "Command execution failed",
|
||||||
|
@@ -235,8 +235,39 @@ func PostDirektivHandle(params PostParams) middleware.Responder {
|
|||||||
paramsCollector = append(paramsCollector, ret)
|
paramsCollector = append(paramsCollector, ret)
|
||||||
accParams.Commands = paramsCollector
|
accParams.Commands = paramsCollector
|
||||||
|
|
||||||
|
ret, err = runCommand5(ctx, accParams, ri)
|
||||||
|
|
||||||
|
responses = append(responses, ret)
|
||||||
|
|
||||||
|
// if foreach returns an error there is no continue
|
||||||
|
//
|
||||||
|
// default we do not continue
|
||||||
|
cont = convertTemplateToBool("<no value>", accParams, false)
|
||||||
|
// cont = convertTemplateToBool("<no value>", accParams, true)
|
||||||
|
//
|
||||||
|
|
||||||
|
if err != nil && !cont {
|
||||||
|
|
||||||
|
errName := cmdErr
|
||||||
|
|
||||||
|
// if the delete function added the cancel tag
|
||||||
|
ci, ok := sm.Load(*params.DirektivActionID)
|
||||||
|
if ok {
|
||||||
|
cinfo, ok := ci.(*ctxInfo)
|
||||||
|
if ok && cinfo.cancelled {
|
||||||
|
errName = "direktiv.actionCancelled"
|
||||||
|
err = fmt.Errorf("action got cancel request")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return generateError(errName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
paramsCollector = append(paramsCollector, ret)
|
||||||
|
accParams.Commands = paramsCollector
|
||||||
|
|
||||||
s, err := templateString(`{
|
s, err := templateString(`{
|
||||||
"export-excel": {{ (index . 4).result | toJson }}
|
"export-excel": {{ (index . 5).result | toJson }}
|
||||||
}
|
}
|
||||||
`, responses)
|
`, responses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -368,7 +399,7 @@ func runCommand3(ctx context.Context,
|
|||||||
params.DirektivDir,
|
params.DirektivDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd, err := templateString(`/bin/json2excel -inputJson {{- if eq (deref .Infile) "" }} "/tmp/input.json" {{- else }} {{ .Infile }} {{- end }} input.json -worksheetName "{{ .WorksheetName }}" -outputFilename '{{ .OutFilename }}'`, at)
|
cmd, err := templateString(`find / -name '*.json'`, at)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ri.Logger().Infof("error executing command: %v", err)
|
ri.Logger().Infof("error executing command: %v", err)
|
||||||
ir[resultKey] = err.Error()
|
ir[resultKey] = err.Error()
|
||||||
@@ -401,6 +432,39 @@ func runCommand4(ctx context.Context,
|
|||||||
params.DirektivDir,
|
params.DirektivDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd, err := templateString(`/bin/json2excel -inputJson {{- if eq (deref .Infile) "" }} "/tmp/input.json" {{- else }} {{ .Infile }} {{- end }} input.json -worksheetName "{{ .WorksheetName }}" -outputFilename '{{ .OutFilename }}'`, at)
|
||||||
|
if err != nil {
|
||||||
|
ri.Logger().Infof("error executing command: %v", err)
|
||||||
|
ir[resultKey] = err.Error()
|
||||||
|
return ir, err
|
||||||
|
}
|
||||||
|
cmd = strings.Replace(cmd, "\n", "", -1)
|
||||||
|
|
||||||
|
silent := convertTemplateToBool("false", at, false)
|
||||||
|
print := convertTemplateToBool("true", at, true)
|
||||||
|
output := ""
|
||||||
|
|
||||||
|
envs := []string{}
|
||||||
|
|
||||||
|
return runCmd(ctx, cmd, envs, output, silent, print, ri)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// end commands
|
||||||
|
|
||||||
|
// exec
|
||||||
|
func runCommand5(ctx context.Context,
|
||||||
|
params accParams, ri *apps.RequestInfo) (map[string]interface{}, error) {
|
||||||
|
|
||||||
|
ir := make(map[string]interface{})
|
||||||
|
ir[successKey] = false
|
||||||
|
|
||||||
|
at := accParamsTemplate{
|
||||||
|
*params.Body,
|
||||||
|
params.Commands,
|
||||||
|
params.DirektivDir,
|
||||||
|
}
|
||||||
|
|
||||||
cmd, err := templateString(`base64 -w 0 /tmp/{{ .OutFilename }}`, at)
|
cmd, err := templateString(`base64 -w 0 /tmp/{{ .OutFilename }}`, at)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ri.Logger().Infof("error executing command: %v", err)
|
ri.Logger().Infof("error executing command: %v", err)
|
||||||
|
Reference in New Issue
Block a user