Added ctx changes to apigw
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user