From 0206a7d026aa91ee7743ef633384e516e265b20d Mon Sep 17 00:00:00 2001 From: jojoliang Date: Thu, 17 Sep 2020 17:42:54 +0800 Subject: [PATCH 1/5] =?UTF-8?q?ACL=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bucket_acl.go | 5 ++++- cos.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++- object_acl.go | 5 ++++- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/bucket_acl.go b/bucket_acl.go index 285b906..ecf2d2c 100644 --- a/bucket_acl.go +++ b/bucket_acl.go @@ -6,7 +6,7 @@ import ( ) // BucketGetACLResult is same to the ACLXml -type BucketGetACLResult ACLXml +type BucketGetACLResult = ACLXml // GetACL 使用API读取Bucket的ACL表,只有所有者有权操作。 // @@ -20,6 +20,9 @@ func (s *BucketService) GetACL(ctx context.Context) (*BucketGetACLResult, *Respo result: &res, } resp, err := s.client.send(ctx, &sendOpt) + if err == nil { + decodeACL(resp, &res) + } return &res, resp, err } diff --git a/cos.go b/cos.go index bdca0c9..665084f 100644 --- a/cos.go +++ b/cos.go @@ -11,6 +11,7 @@ import ( "net/http" "net/url" "reflect" + "strings" "text/template" "strconv" @@ -21,7 +22,7 @@ import ( const ( // Version current go sdk version - Version = "0.7.8" + Version = "0.7.10" userAgent = "cos-go-sdk-v5/" + Version contentTypeXML = "application/xml" defaultServiceBaseURL = "http://service.cos.myqcloud.com" @@ -355,3 +356,53 @@ type ACLXml struct { Owner *Owner AccessControlList []ACLGrant `xml:"AccessControlList>Grant,omitempty"` } + +func decodeACL(resp *Response, res *ACLXml) { + ItemMap := map[string]string{ + "ACL": "x-cos-acl", + "READ": "x-cos-grant-read", + "WRITE": "x-cos-grant-write", + "READ_ACP": "x-cos-grant-read-acp", + "WRITE_ACP": "x-cos-grant-write-acp", + "FULL_CONTROL": "x-cos-grant-full-control", + } + publicACL := make(map[string]int) + resACL := make(map[string][]string) + for _, item := range res.AccessControlList { + if item.Grantee == nil { + continue + } + if item.Grantee.ID == "qcs::cam::anyone:anyone" || item.Grantee.URI == "http://cam.qcloud.com/groups/global/AllUsers" { + publicACL[item.Permission] = 1 + } else if item.Grantee.ID != res.Owner.ID { + resACL[item.Permission] = append(resACL[item.Permission], "id=\""+item.Grantee.ID+"\"") + } + } + if publicACL["FULL_CONTROL"] == 1 || (publicACL["READ"] == 1 && publicACL["WRITE"] == 1) { + resACL["ACL"] = []string{"public-read-write"} + } else if publicACL["READ"] == 1 { + resACL["ACL"] = []string{"public-read"} + } else { + resACL["ACL"] = []string{"private"} + } + + for item, header := range ItemMap { + if len(resp.Header.Get(header)) > 0 || len(resACL[item]) == 0 { + continue + } + resp.Header.Set(header, uniqueGrantID(resACL[item])) + } +} + +func uniqueGrantID(grantIDs []string) string { + res := []string{} + filter := make(map[string]int) + for _, id := range grantIDs { + if filter[id] != 0 { + continue + } + filter[id] = 1 + res = append(res, id) + } + return strings.Join(res, ",") +} diff --git a/object_acl.go b/object_acl.go index 2dc5935..addabe1 100644 --- a/object_acl.go +++ b/object_acl.go @@ -6,7 +6,7 @@ import ( ) // ObjectGetACLResult is the result of GetObjectACL -type ObjectGetACLResult ACLXml +type ObjectGetACLResult = ACLXml // GetACL Get Object ACL接口实现使用API读取Object的ACL表,只有所有者有权操作。 // @@ -20,6 +20,9 @@ func (s *ObjectService) GetACL(ctx context.Context, name string) (*ObjectGetACLR result: &res, } resp, err := s.client.send(ctx, &sendOpt) + if err == nil { + decodeACL(resp, &res) + } return &res, resp, err } From 0e9536d989b8e47b71fa02d12cb75d8ffda8b5fc Mon Sep 17 00:00:00 2001 From: jojoliang Date: Sun, 27 Sep 2020 20:33:52 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=A4=9A=E7=89=88=E6=9C=AC=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bucket_encryption_test.go | 4 ++-- cos.go | 2 +- object.go | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bucket_encryption_test.go b/bucket_encryption_test.go index 64be1e1..f1dd306 100644 --- a/bucket_encryption_test.go +++ b/bucket_encryption_test.go @@ -21,9 +21,9 @@ func TestBucketService_GetEncryption(t *testing.T) { testFormValues(t, r, vs) fmt.Fprint(w, ` - + AES256 - + `) diff --git a/cos.go b/cos.go index 665084f..42ca376 100644 --- a/cos.go +++ b/cos.go @@ -22,7 +22,7 @@ import ( const ( // Version current go sdk version - Version = "0.7.10" + Version = "0.7.11" userAgent = "cos-go-sdk-v5/" + Version contentTypeXML = "application/xml" defaultServiceBaseURL = "http://service.cos.myqcloud.com" diff --git a/object.go b/object.go index 60864df..f7e5fbb 100644 --- a/object.go +++ b/object.go @@ -284,6 +284,7 @@ type ObjectDeleteOptions struct { XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"` //兼容其他自定义头部 XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"` + VersionId string `header:"-" url:"VersionId,omitempty" xml:"-"` } // Delete Object请求可以将一个文件(Object)删除。 @@ -304,6 +305,7 @@ func (s *ObjectService) Delete(ctx context.Context, name string, opt ...*ObjectD uri: "/" + encodeURIComponent(name), method: http.MethodDelete, optHeader: optHeader, + optQuery: optHeader, } resp, err := s.client.send(ctx, &sendOpt) return resp, err @@ -440,9 +442,10 @@ type ObjectDeleteMultiResult struct { XMLName xml.Name `xml:"DeleteResult"` DeletedObjects []Object `xml:"Deleted,omitempty"` Errors []struct { - Key string - Code string - Message string + Key string `xml:",omitempty"` + Code string `xml:",omitempty"` + Message string `xml:",omitempty"` + VersionId string `xml:",omitempty"` } `xml:"Error,omitempty"` } @@ -472,6 +475,7 @@ type Object struct { LastModified string `xml:",omitempty"` StorageClass string `xml:",omitempty"` Owner *Owner `xml:",omitempty"` + VersionId string `xml:",omitempty"` } // MultiUploadOptions is the option of the multiupload, From cb662cdad5225cf92be335911d1805a29e445d14 Mon Sep 17 00:00:00 2001 From: jojoliang Date: Mon, 28 Sep 2020 12:05:56 +0800 Subject: [PATCH 3/5] fix MultiUpload when filesize=0 --- object.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/object.go b/object.go index f7e5fbb..d44e351 100644 --- a/object.go +++ b/object.go @@ -620,6 +620,24 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string if err != nil { return nil, nil, err } + if partNum == 0 { + var opt0 *ObjectPutOptions + if opt.OptIni != nil { + opt0 = &ObjectPutOptions{ + opt.OptIni.ACLHeaderOptions, + opt.OptIni.ObjectPutHeaderOptions, + } + } + rsp, err := s.PutFromFile(ctx, name, filepath, opt0) + if err != nil { + return nil, rsp, err + } + result := &CompleteMultipartUploadResult{ + Key: name, + ETag: rsp.Header.Get("ETag"), + } + return result, rsp, nil + } // 2.Init optini := opt.OptIni From 5804e86747f587402b962dcb680ebc0d7c04035d Mon Sep 17 00:00:00 2001 From: jojoliang Date: Mon, 28 Sep 2020 16:14:06 +0800 Subject: [PATCH 4/5] update version --- cos.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cos.go b/cos.go index 42ca376..665084f 100644 --- a/cos.go +++ b/cos.go @@ -22,7 +22,7 @@ import ( const ( // Version current go sdk version - Version = "0.7.11" + Version = "0.7.10" userAgent = "cos-go-sdk-v5/" + Version contentTypeXML = "application/xml" defaultServiceBaseURL = "http://service.cos.myqcloud.com" From b0a399e92dd143fb55b1ed173497644e51450835 Mon Sep 17 00:00:00 2001 From: jojoliang Date: Tue, 29 Sep 2020 20:12:39 +0800 Subject: [PATCH 5/5] update travis.yml --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index e940c8c..6d3e284 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,5 @@ language: go go: -- '1.7' -- '1.8' -- '1.9' -- 1.10.x -- 1.11.x -- 1.12.x - master sudo: false before_install: