[#544] layer: Add session token parameter to DeleteBucketParams

Add `DeleteBucketParams.SessionToken` field in order to unify the
parameters with `CreateBucketParams` and `PutBucketACLParams`.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-06-22 16:22:28 +03:00 committed by Alex Vanin
parent 4fe833164e
commit f596c8be06
3 changed files with 16 additions and 10 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/nspcc-dev/neofs-s3-gw/api/layer"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/session"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
@ -271,7 +272,17 @@ func (h *handler) DeleteBucketHandler(w http.ResponseWriter, r *http.Request) {
return
}
if err = h.obj.DeleteBucket(r.Context(), &layer.DeleteBucketParams{BktInfo: bktInfo}); err != nil {
var sessionToken *session.Container
boxData, err := layer.GetBoxData(r.Context())
if err == nil {
sessionToken = boxData.Gate.SessionTokenForDelete()
}
if err = h.obj.DeleteBucket(r.Context(), &layer.DeleteBucketParams{
BktInfo: bktInfo,
SessionToken: sessionToken,
}); err != nil {
h.logAndSendError(w, "couldn't delete bucket", reqInfo, err)
}
w.WriteHeader(http.StatusNoContent)

View file

@ -180,12 +180,6 @@ func (n *layer) GetContainerEACL(ctx context.Context, idCnr cid.ID) (*eacl.Table
return n.neoFS.ContainerEACL(ctx, idCnr)
}
func (n *layer) deleteContainer(ctx context.Context, idCnr cid.ID) error {
var sessionToken *session.Container
boxData, err := GetBoxData(ctx)
if err == nil {
sessionToken = boxData.Gate.SessionTokenForDelete()
}
func (n *layer) deleteContainer(ctx context.Context, idCnr cid.ID, sessionToken *session.Container) error {
return n.neoFS.DeleteContainer(ctx, idCnr, sessionToken)
}

View file

@ -151,7 +151,8 @@ type (
}
// DeleteBucketParams stores delete bucket request parameters.
DeleteBucketParams struct {
BktInfo *data.BucketInfo
BktInfo *data.BucketInfo
SessionToken *session.Container
}
// PutSystemObjectParams stores putSystemObject parameters.
@ -658,5 +659,5 @@ func (n *layer) DeleteBucket(ctx context.Context, p *DeleteBucketParams) error {
}
n.bucketCache.Delete(p.BktInfo.Name)
return n.deleteContainer(ctx, p.BktInfo.CID)
return n.deleteContainer(ctx, p.BktInfo.CID, p.SessionToken)
}