From 9e4edd555e84cd2ba513fe4ca1bef6593711a54c Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Thu, 6 May 2021 10:41:26 +0200 Subject: [PATCH] Use proper types for corredor exec automation fn Arguments&results are no longer Any but Vars --- automation/automation/corredor_handler.gen.go | 12 ++++++------ automation/automation/corredor_handler.go | 16 +++++++++------- automation/automation/corredor_handler.yaml | 5 +++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/automation/automation/corredor_handler.gen.go b/automation/automation/corredor_handler.gen.go index efafbf983..c2f85b328 100644 --- a/automation/automation/corredor_handler.gen.go +++ b/automation/automation/corredor_handler.gen.go @@ -36,11 +36,11 @@ type ( Script string hasArgs bool - Args interface{} + Args *expr.Vars } corredorExecResults struct { - Results interface{} + Results *expr.Vars } ) @@ -67,7 +67,7 @@ func (h corredorHandler) Exec() *atypes.Function { }, { Name: "args", - Types: []string{"Any"}, + Types: []string{"Vars"}, }, }, @@ -75,7 +75,7 @@ func (h corredorHandler) Exec() *atypes.Function { { Name: "results", - Types: []string{"Any"}, + Types: []string{"Vars"}, }, }, @@ -99,12 +99,12 @@ func (h corredorHandler) Exec() *atypes.Function { out = &expr.Vars{} { - // converting results.Results (interface{}) to Any + // converting results.Results (*expr.Vars) to Vars var ( tval expr.TypedValue ) - if tval, err = h.reg.Type("Any").Cast(results.Results); err != nil { + if tval, err = h.reg.Type("Vars").Cast(results.Results); err != nil { return } else if err = expr.Assign(out, "results", tval); err != nil { return diff --git a/automation/automation/corredor_handler.go b/automation/automation/corredor_handler.go index c395a76e8..79432a89f 100644 --- a/automation/automation/corredor_handler.go +++ b/automation/automation/corredor_handler.go @@ -5,8 +5,8 @@ import ( "encoding/json" "github.com/cortezaproject/corteza-server/pkg/corredor" "github.com/cortezaproject/corteza-server/pkg/eventbus" + "github.com/cortezaproject/corteza-server/pkg/expr" "github.com/cortezaproject/corteza-server/system/service/event" - "github.com/spf13/cast" ) type ( @@ -41,18 +41,20 @@ func (h corredorHandler) exec(ctx context.Context, args *corredorExecArgs) (r *c return } - return &corredorExecResults{Results: sArgs.payload}, nil + r = &corredorExecResults{} + if r.Results, err = expr.NewVars(sArgs.payload); err != nil { + return nil, err + } + + return } -func makeScriptArgs(in interface{}) *scriptArgs { - return &scriptArgs{ - payload: cast.ToStringMap(in), - } +func makeScriptArgs(in *expr.Vars) *scriptArgs { + return &scriptArgs{payload: in.Dict()} } // mimic onManual event on system: - func (scriptArgs) ResourceType() string { return event.SystemOnManual().ResourceType() } func (scriptArgs) EventType() string { return event.SystemOnManual().EventType() } func (scriptArgs) Match(eventbus.ConstraintMatcher) bool { return false } diff --git a/automation/automation/corredor_handler.yaml b/automation/automation/corredor_handler.yaml index 6b4c870a9..96eda2404 100644 --- a/automation/automation/corredor_handler.yaml +++ b/automation/automation/corredor_handler.yaml @@ -8,7 +8,8 @@ functions: description: Executes script in Corredor Automation server params: script: { types: [ { wf: String } ], required: true } - args: { types: [ { wf: Any } ] } + args: { types: [ { wf: Vars, go: '*expr.Vars' } ] } results: results: - wf: Any + wf: Vars + go: '*expr.Vars'