Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c88b73871d | ||
|
|
b0a399e92d | ||
|
|
5804e86747 | ||
|
|
cb662cdad5 | ||
|
|
0e9536d989 | ||
|
|
0206a7d026 | ||
|
|
d5130075f0 | ||
|
|
eb4e1ac4c9 |
@@ -1,11 +1,5 @@
|
|||||||
language: go
|
language: go
|
||||||
go:
|
go:
|
||||||
- '1.7'
|
|
||||||
- '1.8'
|
|
||||||
- '1.9'
|
|
||||||
- 1.10.x
|
|
||||||
- 1.11.x
|
|
||||||
- 1.12.x
|
|
||||||
- master
|
- master
|
||||||
sudo: false
|
sudo: false
|
||||||
before_install:
|
before_install:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// BucketGetACLResult is same to the ACLXml
|
// BucketGetACLResult is same to the ACLXml
|
||||||
type BucketGetACLResult ACLXml
|
type BucketGetACLResult = ACLXml
|
||||||
|
|
||||||
// GetACL 使用API读取Bucket的ACL表,只有所有者有权操作。
|
// GetACL 使用API读取Bucket的ACL表,只有所有者有权操作。
|
||||||
//
|
//
|
||||||
@@ -20,6 +20,9 @@ func (s *BucketService) GetACL(ctx context.Context) (*BucketGetACLResult, *Respo
|
|||||||
result: &res,
|
result: &res,
|
||||||
}
|
}
|
||||||
resp, err := s.client.send(ctx, &sendOpt)
|
resp, err := s.client.send(ctx, &sendOpt)
|
||||||
|
if err == nil {
|
||||||
|
decodeACL(resp, &res)
|
||||||
|
}
|
||||||
return &res, resp, err
|
return &res, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ type BucketEncryptionConfiguration struct {
|
|||||||
|
|
||||||
type BucketPutEncryptionOptions struct {
|
type BucketPutEncryptionOptions struct {
|
||||||
XMLName xml.Name `xml:"ServerSideEncryptionConfiguration"`
|
XMLName xml.Name `xml:"ServerSideEncryptionConfiguration"`
|
||||||
Rule *BucketEncryptionConfiguration `xml:"Rule>ApplySideEncryptionConfiguration"`
|
Rule *BucketEncryptionConfiguration `xml:"Rule>ApplyServerSideEncryptionByDefault"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BucketGetEncryptionResult BucketPutEncryptionOptions
|
type BucketGetEncryptionResult BucketPutEncryptionOptions
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ func TestBucketService_GetEncryption(t *testing.T) {
|
|||||||
testFormValues(t, r, vs)
|
testFormValues(t, r, vs)
|
||||||
fmt.Fprint(w, `<ServerSideEncryptionConfiguration>
|
fmt.Fprint(w, `<ServerSideEncryptionConfiguration>
|
||||||
<Rule>
|
<Rule>
|
||||||
<ApplySideEncryptionConfiguration>
|
<ApplyServerSideEncryptionByDefault>
|
||||||
<SSEAlgorithm>AES256</SSEAlgorithm>
|
<SSEAlgorithm>AES256</SSEAlgorithm>
|
||||||
</ApplySideEncryptionConfiguration>
|
</ApplyServerSideEncryptionByDefault>
|
||||||
</Rule>
|
</Rule>
|
||||||
</ServerSideEncryptionConfiguration>`)
|
</ServerSideEncryptionConfiguration>`)
|
||||||
|
|
||||||
|
|||||||
53
cos.go
53
cos.go
@@ -11,6 +11,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -21,7 +22,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Version current go sdk version
|
// Version current go sdk version
|
||||||
Version = "0.7.8"
|
Version = "0.7.10"
|
||||||
userAgent = "cos-go-sdk-v5/" + Version
|
userAgent = "cos-go-sdk-v5/" + Version
|
||||||
contentTypeXML = "application/xml"
|
contentTypeXML = "application/xml"
|
||||||
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
|
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
|
||||||
@@ -355,3 +356,53 @@ type ACLXml struct {
|
|||||||
Owner *Owner
|
Owner *Owner
|
||||||
AccessControlList []ACLGrant `xml:"AccessControlList>Grant,omitempty"`
|
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, ",")
|
||||||
|
}
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ const (
|
|||||||
kRepRegion = "ap-chengdu"
|
kRepRegion = "ap-chengdu"
|
||||||
|
|
||||||
// Batch测试需要的源存储桶和目标存储桶,目前只在成都、重庆地域公测
|
// Batch测试需要的源存储桶和目标存储桶,目前只在成都、重庆地域公测
|
||||||
kBatchBucket = "testcd-1259654469"
|
kBatchBucket = "cosgosdktest-1259654469"
|
||||||
kTargetBatchBucket = "cosgosdkreptest-1259654469" //复用了存储桶
|
kTargetBatchBucket = "cosgosdktest-1259654469" //复用了存储桶
|
||||||
kBatchRegion = "ap-chengdu"
|
kBatchRegion = "ap-guangzhou"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *CosTestSuite) SetupSuite() {
|
func (s *CosTestSuite) SetupSuite() {
|
||||||
@@ -812,7 +812,7 @@ func (s *CosTestSuite) TestBatch() {
|
|||||||
assert.Equal(s.T(), res3.Priority, 3, "priority not right")
|
assert.Equal(s.T(), res3.Priority, 3, "priority not right")
|
||||||
|
|
||||||
// 等待状态变成Suspended
|
// 等待状态变成Suspended
|
||||||
for i := 0; i < 10; i = i + 1 {
|
for i := 0; i < 50; i = i + 1 {
|
||||||
res, _, err := client.Batch.DescribeJob(context.Background(), jobid, headers)
|
res, _, err := client.Batch.DescribeJob(context.Background(), jobid, headers)
|
||||||
assert.Nil(s.T(), err, "describe job Failed")
|
assert.Nil(s.T(), err, "describe job Failed")
|
||||||
assert.Equal(s.T(), res2.Job.ConfirmationRequired, "true", "ConfirmationRequired not right")
|
assert.Equal(s.T(), res2.Job.ConfirmationRequired, "true", "ConfirmationRequired not right")
|
||||||
|
|||||||
28
object.go
28
object.go
@@ -284,6 +284,7 @@ type ObjectDeleteOptions struct {
|
|||||||
XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"`
|
XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"`
|
||||||
//兼容其他自定义头部
|
//兼容其他自定义头部
|
||||||
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
|
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
|
||||||
|
VersionId string `header:"-" url:"VersionId,omitempty" xml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete Object请求可以将一个文件(Object)删除。
|
// Delete Object请求可以将一个文件(Object)删除。
|
||||||
@@ -304,6 +305,7 @@ func (s *ObjectService) Delete(ctx context.Context, name string, opt ...*ObjectD
|
|||||||
uri: "/" + encodeURIComponent(name),
|
uri: "/" + encodeURIComponent(name),
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
optHeader: optHeader,
|
optHeader: optHeader,
|
||||||
|
optQuery: optHeader,
|
||||||
}
|
}
|
||||||
resp, err := s.client.send(ctx, &sendOpt)
|
resp, err := s.client.send(ctx, &sendOpt)
|
||||||
return resp, err
|
return resp, err
|
||||||
@@ -440,9 +442,10 @@ type ObjectDeleteMultiResult struct {
|
|||||||
XMLName xml.Name `xml:"DeleteResult"`
|
XMLName xml.Name `xml:"DeleteResult"`
|
||||||
DeletedObjects []Object `xml:"Deleted,omitempty"`
|
DeletedObjects []Object `xml:"Deleted,omitempty"`
|
||||||
Errors []struct {
|
Errors []struct {
|
||||||
Key string
|
Key string `xml:",omitempty"`
|
||||||
Code string
|
Code string `xml:",omitempty"`
|
||||||
Message string
|
Message string `xml:",omitempty"`
|
||||||
|
VersionId string `xml:",omitempty"`
|
||||||
} `xml:"Error,omitempty"`
|
} `xml:"Error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,6 +475,7 @@ type Object struct {
|
|||||||
LastModified string `xml:",omitempty"`
|
LastModified string `xml:",omitempty"`
|
||||||
StorageClass string `xml:",omitempty"`
|
StorageClass string `xml:",omitempty"`
|
||||||
Owner *Owner `xml:",omitempty"`
|
Owner *Owner `xml:",omitempty"`
|
||||||
|
VersionId string `xml:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MultiUploadOptions is the option of the multiupload,
|
// MultiUploadOptions is the option of the multiupload,
|
||||||
@@ -616,6 +620,24 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
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
|
// 2.Init
|
||||||
optini := opt.OptIni
|
optini := opt.OptIni
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ObjectGetACLResult is the result of GetObjectACL
|
// ObjectGetACLResult is the result of GetObjectACL
|
||||||
type ObjectGetACLResult ACLXml
|
type ObjectGetACLResult = ACLXml
|
||||||
|
|
||||||
// GetACL Get Object ACL接口实现使用API读取Object的ACL表,只有所有者有权操作。
|
// GetACL Get Object ACL接口实现使用API读取Object的ACL表,只有所有者有权操作。
|
||||||
//
|
//
|
||||||
@@ -20,6 +20,9 @@ func (s *ObjectService) GetACL(ctx context.Context, name string) (*ObjectGetACLR
|
|||||||
result: &res,
|
result: &res,
|
||||||
}
|
}
|
||||||
resp, err := s.client.send(ctx, &sendOpt)
|
resp, err := s.client.send(ctx, &sendOpt)
|
||||||
|
if err == nil {
|
||||||
|
decodeACL(resp, &res)
|
||||||
|
}
|
||||||
return &res, resp, err
|
return &res, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user