From 8aac61652f61b085b39bd3bcdea9b26634a96bb9 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Mon, 26 Jul 2021 13:30:51 +0300 Subject: [PATCH] [#89] Move BoxData to CreateBucketParams Signed-off-by: Denis Kirillov --- api/handler/put.go | 6 +++--- api/layer/container.go | 7 +++---- api/layer/layer.go | 13 +++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/api/handler/put.go b/api/handler/put.go index a70566dd..cd98a416 100644 --- a/api/handler/put.go +++ b/api/handler/put.go @@ -107,14 +107,14 @@ func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) { return } - boxData, err := getBoxData(r.Context()) + p.BoxData, err = getBoxData(r.Context()) if err != nil { h.registerAndSendError(w, r, err, "could not get boxData") return } if createParams.LocationConstraint != "" { - for _, placementPolicy := range boxData.Policies { + for _, placementPolicy := range p.BoxData.Policies { if placementPolicy.LocationConstraint == createParams.LocationConstraint { p.Policy = placementPolicy.Policy break @@ -129,7 +129,7 @@ func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) { } } - cid, err := h.obj.CreateBucket(r.Context(), &p, boxData) + cid, err := h.obj.CreateBucket(r.Context(), &p) if err != nil { h.registerAndSendError(w, r, err, "could not create bucket") return diff --git a/api/layer/container.go b/api/layer/container.go index 4a25c1e9..b8ac9cf3 100644 --- a/api/layer/container.go +++ b/api/layer/container.go @@ -15,7 +15,6 @@ import ( cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" "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" "github.com/nspcc-dev/neofs-sdk-go/pkg/pool" "go.uber.org/zap" ) @@ -123,14 +122,14 @@ func (n *layer) containerList(ctx context.Context) ([]*BucketInfo, error) { return list, nil } -func (n *layer) createContainer(ctx context.Context, p *CreateBucketParams, boxData *accessbox.Box) (*cid.ID, error) { +func (n *layer) createContainer(ctx context.Context, p *CreateBucketParams) (*cid.ID, error) { cnr := container.New( container.WithPolicy(p.Policy), container.WithCustomBasicACL(p.ACL), container.WithAttribute(container.AttributeName, p.Name), container.WithAttribute(container.AttributeTimestamp, strconv.FormatInt(time.Now().Unix(), 10))) - cnr.SetSessionToken(boxData.Gate.SessionToken) + cnr.SetSessionToken(p.BoxData.Gate.SessionToken) cnr.SetOwnerID(n.Owner(ctx)) cid, err := n.pool.PutContainer(ctx, cnr) @@ -142,7 +141,7 @@ func (n *layer) createContainer(ctx context.Context, p *CreateBucketParams, boxD return nil, err } - if err := n.setContainerEACL(ctx, cid, boxData.Gate.GateKey); err != nil { + if err := n.setContainerEACL(ctx, cid, p.BoxData.Gate.GateKey); err != nil { return nil, err } diff --git a/api/layer/layer.go b/api/layer/layer.go index 0be06785..11a4b556 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -74,9 +74,10 @@ type ( } // CreateBucketParams stores bucket create request parameters. CreateBucketParams struct { - Name string - ACL uint32 - Policy *netmap.PlacementPolicy + Name string + ACL uint32 + Policy *netmap.PlacementPolicy + BoxData *accessbox.Box } // DeleteBucketParams stores delete bucket request parameters. DeleteBucketParams struct { @@ -104,7 +105,7 @@ type ( ListBuckets(ctx context.Context) ([]*BucketInfo, error) GetBucketInfo(ctx context.Context, name string) (*BucketInfo, error) - CreateBucket(ctx context.Context, p *CreateBucketParams, boxData *accessbox.Box) (*cid.ID, error) + CreateBucket(ctx context.Context, p *CreateBucketParams) (*cid.ID, error) DeleteBucket(ctx context.Context, p *DeleteBucketParams) error GetObject(ctx context.Context, p *GetObjectParams) error @@ -498,11 +499,11 @@ func (n *layer) DeleteObjects(ctx context.Context, bucket string, objects []stri return errs } -func (n *layer) CreateBucket(ctx context.Context, p *CreateBucketParams, boxData *accessbox.Box) (*cid.ID, error) { +func (n *layer) CreateBucket(ctx context.Context, p *CreateBucketParams) (*cid.ID, error) { _, err := n.GetBucketInfo(ctx, p.Name) if err != nil { if errors.Is(err, ErrBucketNotFound) { - return n.createContainer(ctx, p, boxData) + return n.createContainer(ctx, p) } return nil, err }