Skip to content

Commit

Permalink
Added ctx changes to apigw
Browse files Browse the repository at this point in the history
  • Loading branch information
petergrlica committed Sep 2, 2021
1 parent b40d93f commit 358dc4e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
15 changes: 15 additions & 0 deletions pkg/apigw/pipeline/pipeline.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions pkg/apigw/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit 358dc4e

Please sign in to comment.