Added ctx changes to apigw

This commit is contained in:
Peter Grlica
2021-09-02 10:00:44 +02:00
parent b40d93f7c1
commit 358dc4ea24
2 changed files with 24 additions and 2 deletions
+15
View File
@@ -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 {
+9 -2
View File
@@ -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
}