From c24fe5cc2169129ec66cda72ac9f60b31a283b1f Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Wed, 28 Jul 2021 16:27:06 +0300 Subject: [PATCH] [#112] Move getBoxData from handler to layer And made it exported Signed-off-by: Angira Kekteeva --- api/handler/put.go | 18 +----------------- api/layer/util.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/api/handler/put.go b/api/handler/put.go index cd98a416..a0e7ff31 100644 --- a/api/handler/put.go +++ b/api/handler/put.go @@ -1,7 +1,6 @@ package handler import ( - "context" "encoding/xml" "fmt" "net/http" @@ -13,7 +12,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/policy" "github.com/nspcc-dev/neofs-s3-gw/api" "github.com/nspcc-dev/neofs-s3-gw/api/layer" - "github.com/nspcc-dev/neofs-s3-gw/creds/accessbox" "go.uber.org/zap" ) @@ -107,7 +105,7 @@ func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) { return } - p.BoxData, err = getBoxData(r.Context()) + p.BoxData, err = layer.GetBoxData(r.Context()) if err != nil { h.registerAndSendError(w, r, err, "could not get boxData") return @@ -172,17 +170,3 @@ func parseBasicACL(basicACL string) (uint32, error) { return uint32(value), nil } } - -func getBoxData(ctx context.Context) (*accessbox.Box, error) { - var boxData *accessbox.Box - data, ok := ctx.Value(api.BoxData).(*accessbox.Box) - if !ok || data == nil { - return nil, fmt.Errorf("couldn't get box data from context") - } - - boxData = data - if boxData.Gate == nil { - boxData.Gate = &accessbox.GateData{} - } - return boxData, nil -} diff --git a/api/layer/util.go b/api/layer/util.go index 9f4247f1..5bcee8b3 100644 --- a/api/layer/util.go +++ b/api/layer/util.go @@ -1,6 +1,8 @@ package layer import ( + "context" + "fmt" "os" "strconv" "strings" @@ -8,6 +10,8 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" + "github.com/nspcc-dev/neofs-s3-gw/api" + "github.com/nspcc-dev/neofs-s3-gw/creds/accessbox" ) type ( @@ -172,3 +176,18 @@ func (o *ObjectInfo) ID() *object.ID { return o.id } // IsDir allows to check if object is a directory. func (o *ObjectInfo) IsDir() bool { return o.isDir } + +// GetBoxData extracts accessbox.Box from context. +func GetBoxData(ctx context.Context) (*accessbox.Box, error) { + var boxData *accessbox.Box + data, ok := ctx.Value(api.BoxData).(*accessbox.Box) + if !ok || data == nil { + return nil, fmt.Errorf("couldn't get box data from context") + } + + boxData = data + if boxData.Gate == nil { + boxData.Gate = &accessbox.GateData{} + } + return boxData, nil +}