forked from TrueCloudLab/frostfs-s3-gw
[#25] Migrate handler to NeoFS API v2
Naive migration, without any tries to start application closes #25 Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
parent
7deeb68d47
commit
b72a957341
1 changed files with 20 additions and 4 deletions
|
@ -5,6 +5,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"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"
|
||||||
"github.com/nspcc-dev/neofs-s3-gate/api/layer"
|
"github.com/nspcc-dev/neofs-s3-gate/api/layer"
|
||||||
"github.com/nspcc-dev/neofs-s3-gate/auth"
|
"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) {
|
func (h *handler) ListBucketsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var (
|
var (
|
||||||
|
err error
|
||||||
|
own = owner.NewID()
|
||||||
|
tkn *token.BearerToken
|
||||||
res *ListBucketsResponse
|
res *ListBucketsResponse
|
||||||
rid = api.GetRequestID(r.Context())
|
rid = api.GetRequestID(r.Context())
|
||||||
)
|
)
|
||||||
|
|
||||||
tkn, err := auth.GetBearerToken(r.Context())
|
if tkn, err = auth.GetBearerToken(r.Context()); err != nil {
|
||||||
if err != nil {
|
|
||||||
h.log.Error("something went wrong",
|
h.log.Error("something went wrong",
|
||||||
zap.String("request_id", rid),
|
zap.String("request_id", rid),
|
||||||
zap.Error(err))
|
zap.Error(err))
|
||||||
|
@ -41,6 +45,18 @@ func (h *handler) ListBucketsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
HTTPStatusCode: http.StatusInternalServerError,
|
HTTPStatusCode: http.StatusInternalServerError,
|
||||||
}, r.URL)
|
}, 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +77,8 @@ func (h *handler) ListBucketsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
res = &ListBucketsResponse{
|
res = &ListBucketsResponse{
|
||||||
Owner: Owner{
|
Owner: Owner{
|
||||||
ID: tkn.OwnerID.String(),
|
ID: own.String(),
|
||||||
DisplayName: tkn.OwnerID.String(),
|
DisplayName: own.String(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue