From f596c8be06b1575ffe94187528d3dcc4efbd9089 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 22 Jun 2022 16:22:28 +0300 Subject: [PATCH] [#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 --- api/handler/delete.go | 13 ++++++++++++- api/layer/container.go | 8 +------- api/layer/layer.go | 5 +++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/api/handler/delete.go b/api/handler/delete.go index 582a907cc..88e968167 100644 --- a/api/handler/delete.go +++ b/api/handler/delete.go @@ -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) diff --git a/api/layer/container.go b/api/layer/container.go index bf6231dcd..eb288ee15 100644 --- a/api/layer/container.go +++ b/api/layer/container.go @@ -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) } diff --git a/api/layer/layer.go b/api/layer/layer.go index 901e0c4b9..e855b9b16 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -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) }