Refactoring api/handler

- don't require token.BearerToken
- don't call `GetObjectInfo`

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-11-27 15:32:52 +03:00
parent 58b877b97c
commit 1868034723
2 changed files with 0 additions and 33 deletions

View file

@ -5,9 +5,7 @@ import (
"strconv"
"time"
sdk "github.com/nspcc-dev/cdn-neofs-sdk"
"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"
"go.uber.org/zap"
@ -29,27 +27,10 @@ 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())
)
if tkn, err = sdk.BearerToken(r.Context()); 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.ErrInternalError).Code,
Description: err.Error(),
HTTPStatusCode: http.StatusInternalServerError,
}, r.URL)
return
}
own = tkn.Issuer()
list, err := h.obj.ListBuckets(r.Context())
if err != nil {
h.log.Error("something went wrong",

View file

@ -30,20 +30,6 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
HTTPStatusCode: http.StatusBadRequest,
}, r.URL)
return
} else if _, err = h.obj.GetObjectInfo(r.Context(), bkt, obj); err == nil {
h.log.Error("object exists",
zap.String("request_id", rid),
zap.String("bucket_name", bkt),
zap.String("object_name", obj),
zap.Error(err))
api.WriteErrorResponse(r.Context(), w, api.Error{
Code: api.GetAPIError(api.ErrMethodNotAllowed).Code,
Description: "Object: " + bkt + "#" + obj + " already exists",
HTTPStatusCode: http.StatusBadRequest,
}, r.URL)
return
}