[#89] Move BoxData to CreateBucketParams

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-07-26 13:30:51 +03:00
parent b695e6a3b4
commit 8aac61652f
3 changed files with 13 additions and 13 deletions

View file

@ -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

View file

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

View file

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