diff --git a/api/handler/put.go b/api/handler/put.go index a70566dd8..cd98a4164 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 4a25c1e9d..b8ac9cf34 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 0be06785c..11a4b5567 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 }