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 +}