3
0

Reload routes on filter update, jsenv update, http handler body fix

This commit is contained in:
Peter Grlica
2021-08-18 14:09:48 +02:00
parent b718bd83ac
commit 6645ac0c66
4 changed files with 46 additions and 16 deletions
@@ -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)
+13 -1
View File
@@ -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)
+2 -1
View File
@@ -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{}
)
+31 -10
View File
@@ -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
}()