[#31] Add force bucket delete flag
Some checks failed
/ DCO (pull_request) Successful in 2m2s
/ Vulncheck (pull_request) Successful in 2m19s
/ Builds (1.21) (pull_request) Successful in 2m32s
/ Builds (1.22) (pull_request) Successful in 2m27s
/ Lint (pull_request) Failing after 2m17s
/ Tests (1.21) (pull_request) Failing after 2m13s
/ Tests (1.22) (pull_request) Failing after 2m46s

Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
This commit is contained in:
Pavel Pogodaev 2024-07-19 22:20:40 +03:00
parent a031777a1b
commit 93f871cd1f
4 changed files with 22 additions and 3 deletions

View file

@ -277,6 +277,7 @@ const (
ErrEvaluatorBindingDoesNotExist
ErrMissingHeaders
ErrInvalidColumnIndex
ErrMissingForceBucketDeleteHeader
ErrPostPolicyConditionInvalidFormat
@ -1709,6 +1710,12 @@ var errorCodes = errorCodeMap{
Description: "Some headers in the query are missing from the file. Check the file and try again.",
HTTPStatusCode: http.StatusBadRequest,
},
ErrMissingForceBucketDeleteHeader: {
ErrCode: ErrMissingForceBucketDeleteHeader,
Code: "ErrMissingForceBucketDeleteHeader",
Description: "Missing X-Amz-Force-Bucket-Delete header.",
HTTPStatusCode: http.StatusBadRequest,
},
ErrInvalidColumnIndex: {
ErrCode: ErrInvalidColumnIndex,
Code: "InvalidColumnIndex",

View file

@ -237,10 +237,21 @@ func (h *handler) DeleteBucketHandler(w http.ResponseWriter, r *http.Request) {
sessionToken = boxData.Gate.SessionTokenForDelete()
}
skipObjCheck := false
if value, ok := r.Header[api.AmzForceBucketDelete]; !ok {
h.logAndSendError(w, "missing X-Amz-Force-Delete-Bucket", reqInfo, errors.GetAPIError(errors.ErrMissingForceBucketDeleteHeader))
return
} else {
s := value[0]
if s == "true" {
skipObjCheck = true
}
}
if err = h.obj.DeleteBucket(r.Context(), &layer.DeleteBucketParams{
BktInfo: bktInfo,
SessionToken: sessionToken,
}); err != nil {
}, skipObjCheck); err != nil {
h.logAndSendError(w, "couldn't delete bucket", reqInfo, err)
return
}

View file

@ -62,6 +62,7 @@ const (
AmzMaxParts = "X-Amz-Max-Parts"
AmzPartNumberMarker = "X-Amz-Part-Number-Marker"
AmzStorageClass = "X-Amz-Storage-Class"
AmzForceBucketDelete = "X-Amz-Force-Delete-Bucket"
AmzServerSideEncryptionCustomerAlgorithm = "x-amz-server-side-encryption-customer-algorithm"
AmzServerSideEncryptionCustomerKey = "x-amz-server-side-encryption-customer-key"

View file

@ -793,7 +793,7 @@ func (n *Layer) ResolveBucket(ctx context.Context, name string) (cid.ID, error)
return cnrID, nil
}
func (n *Layer) DeleteBucket(ctx context.Context, p *DeleteBucketParams) error {
func (n *Layer) DeleteBucket(ctx context.Context, p *DeleteBucketParams, skipCheck bool) error {
res, _, err := n.getAllObjectsVersions(ctx, commonVersionsListingParams{
BktInfo: p.BktInfo,
MaxKeys: 1,
@ -802,7 +802,7 @@ func (n *Layer) DeleteBucket(ctx context.Context, p *DeleteBucketParams) error {
if err != nil {
return err
}
if len(res) != 0 {
if len(res) != 0 && !skipCheck {
return errors.GetAPIError(errors.ErrBucketNotEmpty)
}