From 358dc4ea246b88be408423e4bc92c9c740c59fa7 Mon Sep 17 00:00:00 2001 From: Peter Grlica Date: Thu, 2 Sep 2021 10:00:44 +0200 Subject: [PATCH] Added ctx changes to apigw --- pkg/apigw/pipeline/pipeline.go | 15 +++++++++++++++ pkg/apigw/service.go | 11 +++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pkg/apigw/pipeline/pipeline.go b/pkg/apigw/pipeline/pipeline.go index 43bf08e17..a5f87036d 100644 --- a/pkg/apigw/pipeline/pipeline.go +++ b/pkg/apigw/pipeline/pipeline.go @@ -1,11 +1,14 @@ package pipeline import ( + "context" "net/http" "sort" "time" + actx "github.com/cortezaproject/corteza-server/pkg/apigw/ctx" "github.com/cortezaproject/corteza-server/pkg/apigw/types" + "github.com/cortezaproject/corteza-server/pkg/auth" "go.uber.org/zap" ) @@ -100,6 +103,18 @@ func (pp *Pl) makeHandler(hh Worker) func(next http.Handler) http.Handler { if hh.Async { go func() { + var ( + newCtx = context.Background() + + ident = auth.GetIdentityFromContext(r.Context()) + scope = actx.ScopeFromContext(r.Context()) + ) + + newCtx = actx.ScopeToContext(context.Background(), scope) + newCtx = auth.SetIdentityToContext(newCtx, ident) + + r = r.WithContext(newCtx) + // only log error, do not call error handler, // since we do not reply back the response (it was already sent) if err = fn(); err != nil { diff --git a/pkg/apigw/service.go b/pkg/apigw/service.go index cb4b325a1..3b8bde898 100644 --- a/pkg/apigw/service.go +++ b/pkg/apigw/service.go @@ -76,7 +76,10 @@ func (s *apigw) Reload(ctx context.Context) { } func (s *apigw) loadRoutes(ctx context.Context) (rr []*route, err error) { - routes, _, err := s.storer.SearchApigwRoutes(ctx, st.ApigwRouteFilter{Enabled: true, Deleted: f.StateExcluded}) + routes, _, err := s.storer.SearchApigwRoutes(ctx, st.ApigwRouteFilter{ + Enabled: true, + Deleted: f.StateExcluded, + }) if err != nil { return @@ -100,7 +103,11 @@ func (s *apigw) loadRoutes(ctx context.Context) (rr []*route, err error) { } func (s *apigw) loadFilters(ctx context.Context, route uint64) (ff []*st.ApigwFilter, err error) { - ff, _, err = s.storer.SearchApigwFilters(ctx, st.ApigwFilterFilter{RouteID: route}) + ff, _, err = s.storer.SearchApigwFilters(ctx, st.ApigwFilterFilter{ + RouteID: route, + Deleted: f.StateExcluded, + }) + return }