Skip to content

Commit

Permalink
Enhancement: add routing for unimplemented APIs
Browse files Browse the repository at this point in the history
In view of the particularity of the AWS S3 protocol rules, additional
routes are implemented for unimplemented APIs to prevent users from
incorrectly routing to other APIs when requesting unimplemented APIs.

Signed-off-by: Mofei Zhang <[email protected]>
  • Loading branch information
mervinkid committed Apr 8, 2020
1 parent 8696839 commit 4edef10
Show file tree
Hide file tree
Showing 14 changed files with 480 additions and 126 deletions.
57 changes: 42 additions & 15 deletions objectnode/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,54 @@ const (
FullControlPermission = "FULL_CONTROL"
)

// https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/dev/acl-overview.html
// Mapping of ACL Permissions and Access Policy Permissions
// Reference: https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/dev/acl-overview.html
var (
aclBucketPermissionActions = map[Permission]proto.Actions{
ReadPermission: {proto.OSSListBucketAction, proto.OSSListBucketVersionsAction, proto.OSSListBucketMultipartUploadsAction},
WritePermission: {proto.OSSPutObjectAction, proto.OSSDeleteObjectAction, proto.OSSDeleteBucketAction},
ReadACPPermission: {proto.OSSGetBucketAclAction},
WriteACPPermission: {proto.OSSPutBucketAclAction},
ReadPermission: {
proto.OSSListObjectsAction,
proto.OSSListObjectVersionsAction,
proto.OSSListMultipartUploadsAction,
},
WritePermission: {
proto.OSSPutObjectAction,
proto.OSSDeleteObjectAction,
proto.OSSDeleteObjectsAction,
},
ReadACPPermission: {
proto.OSSGetBucketAclAction,
},
WriteACPPermission: {
proto.OSSPutBucketAclAction,
},
FullControlPermission: {
proto.OSSListBucketAction, proto.OSSListBucketVersionsAction, proto.OSSListBucketMultipartUploadsAction,
proto.OSSPutObjectAction, proto.OSSDeleteObjectAction, proto.OSSDeleteBucketAction,
proto.OSSGetBucketAclAction, proto.OSSPutBucketAclAction},
proto.OSSListObjectsAction,
proto.OSSListObjectVersionsAction,
proto.OSSListMultipartUploadsAction,
proto.OSSPutObjectAction,
proto.OSSDeleteObjectAction,
proto.OSSDeleteObjectsAction,
proto.OSSGetBucketAclAction,
proto.OSSPutBucketAclAction,
},
}
aclObjectPermissionActions = map[Permission]proto.Actions{
ReadPermission: {proto.OSSGetObjectAction, proto.OSSGetObjectVersionAction, proto.OSSGetObjectTorrentAction},
WritePermission: {},
ReadACPPermission: {proto.OSSGetObjectAclAction, proto.OSSGetObjectVersionAclAction},
WriteACPPermission: {proto.OSSPutObjectAclAction, proto.OSSPutObjectVersionAclAction},
ReadPermission: {
proto.OSSGetObjectAction,
proto.OSSGetObjectTorrentAction,
},
WritePermission: {},
ReadACPPermission: {
proto.OSSGetObjectAclAction,
},
WriteACPPermission: {
proto.OSSPutObjectAclAction},
FullControlPermission: {
proto.OSSGetObjectAction, proto.OSSGetObjectVersionAction, proto.OSSGetObjectTorrentAction,
proto.OSSGetObjectAclAction, proto.OSSGetObjectVersionAclAction,
proto.OSSPutObjectAclAction, proto.OSSPutObjectVersionAclAction},
proto.OSSGetObjectAction,
proto.OSSGetObjectTorrentAction,
proto.OSSGetObjectAclAction,
proto.OSSPutObjectAclAction,
},
}
)

Expand Down
1 change: 0 additions & 1 deletion objectnode/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func (o *ObjectNode) unsupportedOperationHandler(w http.ResponseWriter, r *http.
if err = UnsupportedOperation.ServeResponse(w, r); err != nil {
log.LogErrorf("unsupportedOperationHandler: serve response fail: requestID(%v) err(%v)",
GetRequestID(r), err)
ServeInternalStaticErrorResponse(w, r)
}
return
}
5 changes: 0 additions & 5 deletions objectnode/api_handler_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ import (
"github.com/gorilla/mux"
)

type CreateBucketConfiguration struct {
xmlns string `xml:"xmlns"`
locationConstraint string `xml:"locationConstraint"`
}

// Head bucket
// API reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadBucket.html
func (o *ObjectNode) headBucketHandler(w http.ResponseWriter, r *http.Request) {
Expand Down
1 change: 0 additions & 1 deletion objectnode/policy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
)

func (o *ObjectNode) getBucketPolicyHandler(w http.ResponseWriter, r *http.Request) {
log.LogInfof("Get bucket acl")
var (
err error
ec *ErrorCode
Expand Down
6 changes: 3 additions & 3 deletions objectnode/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ type ListBucketResultV2 struct {
}

type Tag struct {
Key string `xml:"Key",json:"k"`
Value string `xml:"Value",json:"v"`
Key string `xml:"Key" json:"k"`
Value string `xml:"Value" json:"v"`
}

type Tagging struct {
XMLName xml.Name `json:"-"`
TagSet []*Tag `xml:"TagSet>Tag",json:"ts"`
TagSet []*Tag `xml:"TagSet>Tag" json:"ts"`
}

func NewTagging() *Tagging {
Expand Down
Loading

0 comments on commit 4edef10

Please sign in to comment.