From 8185b714628554320cb15e2145bd8609d94cf42d Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 11 Jun 2021 14:52:03 +0300 Subject: [PATCH] [#65] Allow no sign requests Signed-off-by: Denis Kirillov --- api/auth/center.go | 2 +- api/layer/layer.go | 12 +++--------- api/user-auth.go | 11 +++++++++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/api/auth/center.go b/api/auth/center.go index 565f11f3d..aa3a501bb 100644 --- a/api/auth/center.go +++ b/api/auth/center.go @@ -70,7 +70,7 @@ func (c *center) Authenticate(r *http.Request) (*token.BearerToken, error) { authHeaderField := r.Header["Authorization"] if len(authHeaderField) != 1 { - return nil, errors.New("unsupported request: wrong length of Authorization header field") + return nil, nil } sms1 := c.reg.getSubmatches(authHeaderField[0]) diff --git a/api/layer/layer.go b/api/layer/layer.go index e238b426a..db1126495 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -130,18 +130,12 @@ func (n *layer) GetBucketInfo(ctx context.Context, name string) (*BucketInfo, er return nil, err } - list, err := n.containerList(ctx) - if err != nil { + containerID := new(cid.ID) + if err := containerID.Parse(name); err != nil { return nil, err } - for _, bkt := range list { - if bkt.Name == name { - return bkt, nil - } - } - - return nil, status.Error(codes.NotFound, "bucket not found") + return n.containerInfo(ctx, containerID) } // ListBuckets returns all user containers. Name of the bucket is a container diff --git a/api/user-auth.go b/api/user-auth.go index cb530e7a8..0d8f5a06d 100644 --- a/api/user-auth.go +++ b/api/user-auth.go @@ -26,8 +26,15 @@ func AttachUserAuth(router *mux.Router, center auth.Center, log *zap.Logger) { return } - h.ServeHTTP(w, r.WithContext( - context.WithValue(r.Context(), BearerTokenKey, token))) + var ctx context.Context + if token == nil { + log.Info("couldn't receive bearer token, switch to use neofs-key") + ctx = r.Context() + } else { + ctx = context.WithValue(r.Context(), BearerTokenKey, token) + } + + h.ServeHTTP(w, r.WithContext(ctx)) }) }) }