From 1aa22329fa24deb95c3fa54ad3d81f3246a055fb Mon Sep 17 00:00:00 2001 From: Pavel Korotkov Date: Wed, 22 Jul 2020 17:58:35 +0300 Subject: [PATCH] Add setting bearer token in container list method --- cmd/gate/app-new-auth.go | 7 ++----- neofs/layer/neofs-container.go | 4 +++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cmd/gate/app-new-auth.go b/cmd/gate/app-new-auth.go index 012c8a210..9dd6aa937 100644 --- a/cmd/gate/app-new-auth.go +++ b/cmd/gate/app-new-auth.go @@ -6,13 +6,10 @@ import ( "github.com/gorilla/mux" "github.com/minio/minio/auth" + s3http "github.com/minio/minio/http" "go.uber.org/zap" ) -type ContextKey string - -const BearerTokenContextKey ContextKey = "bearer-token" - func attachNewUserAuth(router *mux.Router, center *auth.Center, log *zap.Logger) { uamw := func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -21,7 +18,7 @@ func attachNewUserAuth(router *mux.Router, center *auth.Center, log *zap.Logger) log.Error("failed to pass authentication", zap.Error(err)) // TODO: Handle any auth error by rejecting request. } - h.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), BearerTokenContextKey, bearerToken))) + h.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), s3http.BearerTokenContextKey, bearerToken))) }) } diff --git a/neofs/layer/neofs-container.go b/neofs/layer/neofs-container.go index fb43031f6..2f15e5e13 100644 --- a/neofs/layer/neofs-container.go +++ b/neofs/layer/neofs-container.go @@ -6,6 +6,7 @@ import ( "go.uber.org/zap" + s3http "github.com/minio/minio/http" "github.com/nspcc-dev/neofs-api-go/container" "github.com/nspcc-dev/neofs-api-go/refs" "github.com/nspcc-dev/neofs-api-go/service" @@ -16,7 +17,8 @@ func (n *neofsObject) containerList(ctx context.Context) ([]refs.CID, error) { req.OwnerID = n.owner req.SetTTL(service.SingleForwardingTTL) req.SetVersion(APIVersion) - req.SetBearer(nil) + bearerToken := ctx.Value(s3http.BearerTokenContextKey).(*service.BearerTokenMsg) + req.SetBearer(bearerToken) err := service.SignRequestData(n.key, req) if err != nil {