From 03939ec9f9079bfe31806f5e42ac8d7fdd3f7ef9 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Fri, 10 Feb 2023 16:03:48 +1100 Subject: [PATCH] functionbuilder --- build/app/models/post_params_body.go | 3 +++ build/app/restapi/embedded_spec.go | 16 ++++++++++++---- build/app/restapi/operations/direktiv_post.go | 2 +- readme.md | 3 ++- tests/v1.0/tests.yaml | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/build/app/models/post_params_body.go b/build/app/models/post_params_body.go index f6f4678..117d21c 100644 --- a/build/app/models/post_params_body.go +++ b/build/app/models/post_params_body.go @@ -17,6 +17,9 @@ import ( // swagger:model postParamsBody type PostParamsBody struct { + // Name of the json input file to utilise + Infile string `json:"infile,omitempty"` + // the filename of the output spreadsheet OutFilename *string `json:"out-filename,omitempty"` diff --git a/build/app/restapi/embedded_spec.go b/build/app/restapi/embedded_spec.go index c756223..a7f71b0 100644 --- a/build/app/restapi/embedded_spec.go +++ b/build/app/restapi/embedded_spec.go @@ -68,6 +68,10 @@ func init() { "schema": { "type": "object", "properties": { + "infile": { + "description": "Name of the json input file to utilise", + "type": "string" + }, "out-filename": { "description": "the filename of the output spreadsheet", "type": "string", @@ -117,7 +121,7 @@ func init() { "cmds": [ { "action": "exec", - "exec": "/bin/json2excel -inputJson 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 }}'", "print": true, "silent": false }, @@ -135,7 +139,7 @@ func init() { }, "x-direktiv-examples": [ { - "content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.input) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx", + "content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: /tmp/input.json\n data: |\n jq(.input) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx", "title": "Basic" } ], @@ -276,7 +280,7 @@ func init() { "cmds": [ { "action": "exec", - "exec": "/bin/json2excel -inputJson 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 }}'", "print": true, "silent": false }, @@ -294,7 +298,7 @@ func init() { }, "x-direktiv-examples": [ { - "content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.input) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx", + "content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: /tmp/input.json\n data: |\n jq(.input) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx", "title": "Basic" } ], @@ -364,6 +368,10 @@ func init() { "postParamsBody": { "type": "object", "properties": { + "infile": { + "description": "Name of the json input file to utilise", + "type": "string" + }, "out-filename": { "description": "the filename of the output spreadsheet", "type": "string", diff --git a/build/app/restapi/operations/direktiv_post.go b/build/app/restapi/operations/direktiv_post.go index 01ff584..57545f7 100644 --- a/build/app/restapi/operations/direktiv_post.go +++ b/build/app/restapi/operations/direktiv_post.go @@ -176,7 +176,7 @@ func runCommand0(ctx context.Context, params.DirektivDir, } - cmd, err := templateString(`/bin/json2excel -inputJson input.json -worksheetName "{{ .WorksheetName }}" -outputFilename '{{ .OutFilename }}'`, at) + 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() diff --git a/readme.md b/readme.md index 3196097..ce540e4 100644 --- a/readme.md +++ b/readme.md @@ -32,7 +32,7 @@ functions: function: export-xlsx input: files: - - name: input.json + - name: /tmp/input.json data: | jq(.input) worksheet-name: "TestSpreadsheet" @@ -101,6 +101,7 @@ functions: | Name | Type | Go type | Required | Default | Description | Example | |------|------|---------|:--------:| ------- |-------------|---------| +| infile | string| `string` | | | Name of the json input file to utilise | | | out-filename | string| `string` | | `"output.xlsx"`| the filename of the output spreadsheet | | | worksheet-name | string| `string` | | `"Sheet1"`| Label for the worksheet created in the spreadsheet | | diff --git a/tests/v1.0/tests.yaml b/tests/v1.0/tests.yaml index f94e9d8..9afe227 100644 --- a/tests/v1.0/tests.yaml +++ b/tests/v1.0/tests.yaml @@ -11,6 +11,6 @@ states: input: files: - data: "jq(.input) \n" - name: input.json + name: /tmp/input.json out-filename: example.xlsx worksheet-name: TestSpreadsheet