diff --git a/automation/automation/http_request_handler.go b/automation/automation/http_request_handler.go index 8bcf84681..6f39f638d 100644 --- a/automation/automation/http_request_handler.go +++ b/automation/automation/http_request_handler.go @@ -89,10 +89,6 @@ func (h httpRequestHandler) makeRequest(ctx context.Context, args *httpRequestSe return nil } - if args.Body != nil { - return nil - } - if args.hasBody && args.bodyStream == nil { if args.bodyString != "" { args.bodyStream = strings.NewReader(args.bodyString) diff --git a/automation/automation/jsenv_handler.go b/automation/automation/jsenv_handler.go index 0e1feb8a2..29b018f49 100644 --- a/automation/automation/jsenv_handler.go +++ b/automation/automation/jsenv_handler.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/cortezaproject/corteza-server/pkg/expr" "github.com/cortezaproject/corteza-server/pkg/jsenv" ) @@ -35,6 +36,17 @@ func (h jsenvHandler) execute(ctx context.Context, args *jsenvExecuteArgs) (res return } + var vv interface{} + + switch a := args.Scope.(type) { + case *expr.KVV: + vv = a.Get() + case *expr.String: + vv = a.Get() + default: + vv = a + } + // call jsenv, feed it function and expect a result tr := jsenv.NewTransformer(jsenv.LoaderJS, jsenv.TargetNoop) vm := jsenv.New(tr) @@ -46,7 +58,7 @@ func (h jsenvHandler) execute(ctx context.Context, args *jsenvExecuteArgs) (res return } - out, err := fn.Exec(vm.New(args.scopeString)) + out, err := fn.Exec(vm.New(vv)) if err != nil { err = fmt.Errorf("could not exec jsenv function: %s", err) diff --git a/pkg/apigw/route.go b/pkg/apigw/route.go index 1ea36a086..7f3c7de05 100644 --- a/pkg/apigw/route.go +++ b/pkg/apigw/route.go @@ -10,6 +10,7 @@ import ( "github.com/cortezaproject/corteza-server/pkg/apigw/pipeline" "github.com/cortezaproject/corteza-server/pkg/apigw/types" + "github.com/cortezaproject/corteza-server/pkg/auth" "github.com/cortezaproject/corteza-server/pkg/options" "go.uber.org/zap" ) @@ -34,7 +35,7 @@ type ( func (r route) ServeHTTP(w http.ResponseWriter, req *http.Request) { var ( - ctx = req.Context() + ctx = auth.SetIdentityToContext(req.Context(), auth.ServiceUser()) scope = types.Scp{} ) diff --git a/system/service/apigw_filter.go b/system/service/apigw_filter.go index e10b23cb5..e5b2ce6db 100644 --- a/system/service/apigw_filter.go +++ b/system/service/apigw_filter.go @@ -66,6 +66,7 @@ func (svc *apigwFilter) FindByID(ctx context.Context, ID uint64) (q *types.Apigw func (svc *apigwFilter) Create(ctx context.Context, new *types.ApigwFilter) (q *types.ApigwFilter, err error) { var ( qProps = &apigwFilterActionProps{filter: new} + r *types.ApigwRoute ) err = func() (err error) { @@ -78,7 +79,7 @@ func (svc *apigwFilter) Create(ctx context.Context, new *types.ApigwFilter) (q * new.CreatedAt = *now() new.CreatedBy = a.GetIdentityFromContext(ctx).Identity() - if _, err = svc.route.FindByID(ctx, new.Route); err != nil { + if r, err = svc.route.FindByID(ctx, new.Route); err != nil { return ApigwFilterErrNotFound(qProps) } @@ -87,8 +88,11 @@ func (svc *apigwFilter) Create(ctx context.Context, new *types.ApigwFilter) (q * } q = new - // send the signal to reload all functions - apigw.Service().Reload(ctx) + + // send the signal to reload all routes + if r.Enabled { + apigw.Service().Reload(ctx) + } return nil }() @@ -100,6 +104,7 @@ func (svc *apigwFilter) Update(ctx context.Context, upd *types.ApigwFilter) (q * var ( qProps = &apigwFilterActionProps{filter: upd} qq *types.ApigwFilter + r *types.ApigwRoute e error ) @@ -112,7 +117,7 @@ func (svc *apigwFilter) Update(ctx context.Context, upd *types.ApigwFilter) (q * return ApigwFilterErrNotAllowedToUpdate(qProps) } - if _, err = svc.route.FindByID(ctx, upd.Route); err != nil { + if r, err = svc.route.FindByID(ctx, upd.Route); err != nil { return err } @@ -130,8 +135,10 @@ func (svc *apigwFilter) Update(ctx context.Context, upd *types.ApigwFilter) (q * q = upd - // send the signal to reload all function - apigw.Service().Reload(ctx) + // send the signal to reload all routes + if r.Enabled { + apigw.Service().Reload(ctx) + } return nil }() @@ -143,6 +150,7 @@ func (svc *apigwFilter) DeleteByID(ctx context.Context, ID uint64) (err error) { var ( qProps = &apigwFilterActionProps{} q *types.ApigwFilter + r *types.ApigwRoute ) err = func() (err error) { @@ -154,6 +162,10 @@ func (svc *apigwFilter) DeleteByID(ctx context.Context, ID uint64) (err error) { return ApigwFilterErrNotAllowedToDelete(qProps) } + if r, err = svc.route.FindByID(ctx, q.Route); err != nil { + return err + } + qProps.setFilter(q) q.DeletedAt = now() @@ -163,8 +175,10 @@ func (svc *apigwFilter) DeleteByID(ctx context.Context, ID uint64) (err error) { return } - // send the signal to reload all queues - apigw.Service().Reload(ctx) + // send the signal to reload all routes + if r.Enabled { + apigw.Service().Reload(ctx) + } return nil }() @@ -176,6 +190,7 @@ func (svc *apigwFilter) UndeleteByID(ctx context.Context, ID uint64) (err error) var ( qProps = &apigwFilterActionProps{} q *types.ApigwFilter + r *types.ApigwRoute ) err = func() (err error) { @@ -187,6 +202,10 @@ func (svc *apigwFilter) UndeleteByID(ctx context.Context, ID uint64) (err error) return ApigwFilterErrNotAllowedToDelete(qProps) } + if r, err = svc.route.FindByID(ctx, q.Route); err != nil { + return err + } + qProps.setFilter(q) q.DeletedAt = nil @@ -196,8 +215,10 @@ func (svc *apigwFilter) UndeleteByID(ctx context.Context, ID uint64) (err error) return } - // send the signal to reload all queues - apigw.Service().Reload(ctx) + // send the signal to reload all routes + if r.Enabled { + apigw.Service().Reload(ctx) + } return nil }()