From b72a957341d016e713868c5e59d264ed37bab7a3 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 19 Oct 2020 04:05:08 +0300 Subject: [PATCH] [#25] Migrate handler to NeoFS API v2 Naive migration, without any tries to start application closes #25 Signed-off-by: Evgeniy Kulikov --- api/handler/list.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/api/handler/list.go b/api/handler/list.go index 10c983f5c..2649c974e 100644 --- a/api/handler/list.go +++ b/api/handler/list.go @@ -5,6 +5,8 @@ import ( "strconv" "time" + "github.com/nspcc-dev/neofs-api-go/pkg/owner" + "github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-s3-gate/api" "github.com/nspcc-dev/neofs-s3-gate/api/layer" "github.com/nspcc-dev/neofs-s3-gate/auth" @@ -25,12 +27,14 @@ var maxObjectList = 10000 // Limit number of objects in a listObjectsResponse/li func (h *handler) ListBucketsHandler(w http.ResponseWriter, r *http.Request) { var ( + err error + own = owner.NewID() + tkn *token.BearerToken res *ListBucketsResponse rid = api.GetRequestID(r.Context()) ) - tkn, err := auth.GetBearerToken(r.Context()) - if err != nil { + if tkn, err = auth.GetBearerToken(r.Context()); err != nil { h.log.Error("something went wrong", zap.String("request_id", rid), zap.Error(err)) @@ -41,6 +45,18 @@ func (h *handler) ListBucketsHandler(w http.ResponseWriter, r *http.Request) { HTTPStatusCode: http.StatusInternalServerError, }, r.URL) + return + } else if own, err = layer.GetOwnerID(tkn); err != nil { + h.log.Error("something went wrong", + zap.String("request_id", rid), + zap.Error(err)) + + api.WriteErrorResponse(r.Context(), w, api.Error{ + Code: api.GetAPIError(api.ErrBadRequest).Code, + Description: err.Error(), + HTTPStatusCode: http.StatusBadRequest, + }, r.URL) + return } @@ -61,8 +77,8 @@ func (h *handler) ListBucketsHandler(w http.ResponseWriter, r *http.Request) { res = &ListBucketsResponse{ Owner: Owner{ - ID: tkn.OwnerID.String(), - DisplayName: tkn.OwnerID.String(), + ID: own.String(), + DisplayName: own.String(), }, }