Skip to content

Commit

Permalink
Add: object storage interface for bucket tagging removal
Browse files Browse the repository at this point in the history
Signed-off-by: Mofei Zhang <[email protected]>
  • Loading branch information
mervinkid committed Feb 5, 2020
1 parent 2d27cea commit a4cef6c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
40 changes: 37 additions & 3 deletions objectnode/api_handler_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (o *ObjectNode) deleteBucketHandler(w http.ResponseWriter, r *http.Request)
return
}
// delete volume from master
if authKey, err = calculateMD5(akCaps.ID); err != nil {
if authKey, err = calculateAuthKey(akCaps.ID); err != nil {
_ = InternalError.ServeResponse(w, r)
return
}
Expand All @@ -146,6 +146,9 @@ func (o *ObjectNode) deleteBucketHandler(w http.ResponseWriter, r *http.Request)
_ = InternalError.ServeResponse(w, r)
return
}

// release volume from volume manager
o.vm.Release(bucket)
return
}

Expand Down Expand Up @@ -216,11 +219,42 @@ func (o *ObjectNode) getBucketLocation(w http.ResponseWriter, r *http.Request) {
return
}

func calculateMD5(key string) (authKey string, err error) {
// Delete bucket tagging
// API reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketTagging.html
func (o *ObjectNode) deleteBucketTaggingHandler(w http.ResponseWriter, r *http.Request) {
var (
param *RequestParam
err error
)
if param, err = o.parseRequestParam(r); err != nil {
log.LogErrorf("deleteBucketTaggingHandler: parse request param fail: requestID(%v) err(%v)", RequestIDFromRequest(r), err)
_ = InvalidArgument.ServeResponse(w, r)
return
}

var volume Volume
if len(param.bucket) == 0 {
_ = NoSuchBucket.ServeResponse(w, r)
return
}
if volume, err = o.vm.Volume(param.bucket); err != nil {
log.LogErrorf("deleteBucketTaggingHandler: load volume fail: requestID(%v) volume(%v) err(%v)", RequestIDFromRequest(r), param.bucket, err)
_ = NoSuchBucket.ServeResponse(w, r)
return
}
if err = volume.DeleteXAttr("/", XAttrKeyOSSTagging); err != nil {
log.LogErrorf("deleteBucketTaggingHandler: volume delete tagging xattr fail: requestID(%v) err(%v)", RequestIDFromRequest(r), err)
_ = InternalError.ServeResponse(w, r)
return
}
return
}

func calculateAuthKey(key string) (authKey string, err error) {
h := md5.New()
_, err = h.Write([]byte(key))
if err != nil {
log.LogErrorf("action[calculateAuthKey] calculate auth key[%v] failed,err[%v]", key, err)
log.LogErrorf("calculateAuthKey: calculate auth key fail: key[%v] err[%v]", key, err)
return
}
cipherStr := h.Sum(nil)
Expand Down
23 changes: 12 additions & 11 deletions objectnode/policy_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ const (
GetObjectAclAction = "s3:GetObjectAcl"
GetObjectVersionAction = "s3:GetObjectVersion"
PutObjectVersionAction = "s3:PutObjectVersion"
GetObjectTorrentAction = "s3:GetObjectTorrent"
PutObjectTorrentAction = "s3:PutObjectTorrent"
PutObjectAclAction = "s3:PutObjectAcl"
GetObjectVersionAclAction = "s3:GetObjectVersionAcl"
PutObjectVersionAclAction = "s3:PutObjectVersionAcl"
DeleteBucketPolicyAction = "s3:DeleteBucketPolicy"
ListMultipartUploadPartsAction = "s3:ListMultipartUploadParts"
AbortMultipartUploadAction = "s3:AbortMultipartUpload"
GetBucketLocationAction = "s3:GetBucketLocation"
PutObjectAttrAction = "s3:PutObjectAttr"
PutObjectTaggingAction = "s3:PutObjectTagging"
GetObjectTorrentAction = "s3:GetObjectTorrent"
PutObjectTorrentAction = "s3:PutObjectTorrent"
PutObjectAclAction = "s3:PutObjectAcl"
GetObjectVersionAclAction = "s3:GetObjectVersionAcl"
PutObjectVersionAclAction = "s3:PutObjectVersionAcl"
DeleteBucketPolicyAction = "s3:DeleteBucketPolicy"
ListMultipartUploadPartsAction = "s3:ListMultipartUploadParts"
AbortMultipartUploadAction = "s3:AbortMultipartUpload"
GetBucketLocationAction = "s3:GetBucketLocation"
PutObjectAttrAction = "s3:PutObjectAttr"
PutObjectTaggingAction = "s3:PutObjectTagging"
DeleteBucketTaggingAction = "oss:action:DeleteBucketTagging"
)

func (s Statement) checkActions(p *RequestParam) bool {
Expand Down
6 changes: 6 additions & 0 deletions objectnode/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ func (o *ObjectNode) registerApiRouters(router *mux.Router) {
HandlerFunc(o.policyCheck(o.deleteBucketPolicyHandler, []Action{DeleteBucketPolicyAction}, Write)).
Queries("policy", "")

// Delete bucket tagging
// API reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketTagging.html
r.Methods(http.MethodDelete).
Handler(o.policyCheck(o.deleteBucketTaggingHandler, []Action{DeleteBucketTaggingAction}, Write)).
Queries("tagging", "")

// Delete bucket
// API reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucket.html
r.Methods(http.MethodDelete).HandlerFunc(o.policyCheck(o.deleteBucketHandler, []Action{DeleteBucketAction}, Write))
Expand Down

0 comments on commit a4cef6c

Please sign in to comment.