Browse Source
Merge pull request #30 from toranger/master
Merge pull request #30 from toranger/master
Support Versioning, Replication, Inventory and Logging APItags/v0.7.8
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 609 additions and 1 deletions
-
134bucket_inventory.go
-
53bucket_logging.go
-
73bucket_replication.go
-
45bucket_version.go
-
96costesting/ci_test.go
-
36example/bucket/deleteReplication.go
-
41example/bucket/getReplication.go
-
39example/bucket/getVersioning.go
-
51example/bucket/putReplication.go
-
41example/bucket/putVersioning.go
-
1object.go
@ -0,0 +1,134 @@ |
|||||
|
package cos |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"encoding/xml" |
||||
|
"fmt" |
||||
|
"net/http" |
||||
|
) |
||||
|
|
||||
|
// Notice bucket_inventory only for test. can not use
|
||||
|
|
||||
|
// BucketGetInventoryResult same struct to options
|
||||
|
type BucketGetInventoryResult BucketPutInventoryOptions |
||||
|
|
||||
|
// BucketListInventoryConfiguartion same struct to options
|
||||
|
type BucketListInventoryConfiguartion BucketPutInventoryOptions |
||||
|
|
||||
|
// BucketInventoryFilter ...
|
||||
|
type BucketInventoryFilter struct { |
||||
|
Prefix string `xml:"Prefix,omitempty"` |
||||
|
} |
||||
|
|
||||
|
// BucketInventoryOptionalFields ...
|
||||
|
type BucketInventoryOptionalFields struct { |
||||
|
XMLName xml.Name `xml:"OptionalFields,omitempty"` |
||||
|
BucketInventoryFields []string `xml:"Field,omitempty"` |
||||
|
} |
||||
|
|
||||
|
// BucketInventorySchedule ...
|
||||
|
type BucketInventorySchedule struct { |
||||
|
Frequency string `xml:"Frequency"` |
||||
|
} |
||||
|
|
||||
|
// BucketInventoryEncryption ...
|
||||
|
type BucketInventoryEncryption struct { |
||||
|
XMLName xml.Name `xml:"Encryption"` |
||||
|
SSECOS string `xml:"SSE-COS,omitempty"` |
||||
|
} |
||||
|
|
||||
|
// BucketInventoryDestinationContent ...
|
||||
|
type BucketInventoryDestinationContent struct { |
||||
|
Bucket string `xml:"Bucket"` |
||||
|
AccountId string `xml:"AccountId,omitempty"` |
||||
|
Prefix string `xml:"Prefix,omitempty"` |
||||
|
Format string `xml:"Format"` |
||||
|
Encryption *BucketInventoryEncryption `xml:"Encryption,omitempty"` |
||||
|
} |
||||
|
|
||||
|
// BucketInventoryDestination ...
|
||||
|
type BucketInventoryDestination struct { |
||||
|
XMLName xml.Name `xml:"Destination"` |
||||
|
BucketDestination *BucketInventoryDestinationContent `xml:"COSBucketDestination"` |
||||
|
} |
||||
|
|
||||
|
// BucketPutInventoryOptions ...
|
||||
|
type BucketPutInventoryOptions struct { |
||||
|
XMLName xml.Name `xml:"InventoryConfiguration"` |
||||
|
ID string `xml:"Id"` |
||||
|
IsEnabled string `xml:"IsEnabled"` |
||||
|
IncludedObjectVersions string `xml:"IncludedObjectVersions"` |
||||
|
Filter *BucketInventoryFilter `xml:"Filter,omitempty"` |
||||
|
OptionalFields *BucketInventoryOptionalFields `xml:"OptionalFields,omitempty"` |
||||
|
Schedule *BucketInventorySchedule `xml:"Schedule"` |
||||
|
Destination *BucketInventoryDestination `xml:"Destination"` |
||||
|
} |
||||
|
|
||||
|
// ListBucketInventoryConfigResult result of ListBucketInventoryConfiguration
|
||||
|
type ListBucketInventoryConfigResult struct { |
||||
|
XMLName xml.Name `xml:"ListInventoryConfigurationResult"` |
||||
|
InventoryConfigurations []BucketListInventoryConfiguartion `xml:"InventoryConfiguration,omitempty"` |
||||
|
IsTruncated bool `xml:"IsTruncated,omitempty"` |
||||
|
ContinuationToken string `xml:"ContinuationToken,omitempty"` |
||||
|
NextContinuationToken string `xml:"NextContinuationToken,omitempty"` |
||||
|
} |
||||
|
|
||||
|
// PutBucketInventory https://cloud.tencent.com/document/product/436/33707
|
||||
|
func (s *BucketService) PutBucketInventoryTest(ctx context.Context, id string, opt *BucketPutInventoryOptions) (*Response, error) { |
||||
|
u := fmt.Sprintf("/?inventory&id=%s", id) |
||||
|
sendOpt := sendOptions{ |
||||
|
baseURL: s.client.BaseURL.BucketURL, |
||||
|
uri: u, |
||||
|
method: http.MethodPut, |
||||
|
body: opt, |
||||
|
} |
||||
|
resp, err := s.client.send(ctx, &sendOpt) |
||||
|
return resp, err |
||||
|
|
||||
|
} |
||||
|
|
||||
|
// GetBucketInventory https://cloud.tencent.com/document/product/436/33705
|
||||
|
func (s *BucketService) GetBucketInventoryTest(ctx context.Context, id string) (*BucketGetInventoryResult, *Response, error) { |
||||
|
u := fmt.Sprintf("/?inventory&id=%s", id) |
||||
|
var res BucketGetInventoryResult |
||||
|
sendOpt := sendOptions{ |
||||
|
baseURL: s.client.BaseURL.BucketURL, |
||||
|
uri: u, |
||||
|
method: http.MethodGet, |
||||
|
result: &res, |
||||
|
} |
||||
|
resp, err := s.client.send(ctx, &sendOpt) |
||||
|
return &res, resp, err |
||||
|
} |
||||
|
|
||||
|
// DeleteBucketInventory https://cloud.tencent.com/document/product/436/33704
|
||||
|
func (s *BucketService) DeleteBucketInventoryTest(ctx context.Context, id string) (*Response, error) { |
||||
|
u := fmt.Sprintf("/?inventory&id=%s", id) |
||||
|
sendOpt := sendOptions{ |
||||
|
baseURL: s.client.BaseURL.BucketURL, |
||||
|
uri: u, |
||||
|
method: http.MethodDelete, |
||||
|
} |
||||
|
resp, err := s.client.send(ctx, &sendOpt) |
||||
|
return resp, err |
||||
|
} |
||||
|
|
||||
|
// ListBucketInventoryConfigurations https://cloud.tencent.com/document/product/436/33706
|
||||
|
func (s *BucketService) ListBucketInventoryConfigurationsTest(ctx context.Context, token string) (*ListBucketInventoryConfigResult, *Response, error) { |
||||
|
var res ListBucketInventoryConfigResult |
||||
|
var u string |
||||
|
if token == "" { |
||||
|
u = "/?inventory" |
||||
|
} else { |
||||
|
u = fmt.Sprintf("/?inventory&continuation-token=%s", encodeURIComponent(token)) |
||||
|
} |
||||
|
sendOpt := sendOptions{ |
||||
|
baseURL: s.client.BaseURL.BucketURL, |
||||
|
uri: u, |
||||
|
method: http.MethodGet, |
||||
|
result: &res, |
||||
|
} |
||||
|
resp, err := s.client.send(ctx, &sendOpt) |
||||
|
return &res, resp, err |
||||
|
|
||||
|
} |
@ -0,0 +1,53 @@ |
|||||
|
package cos |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"encoding/xml" |
||||
|
"net/http" |
||||
|
) |
||||
|
|
||||
|
// Notice bucket logging function is testing, can not use.
|
||||
|
|
||||
|
// BucketLoggingEnabled main struct of logging
|
||||
|
type BucketLoggingEnabled struct { |
||||
|
TargetBucket string `xml:"TargetBucket"` |
||||
|
TargetPrefix string `xml:"TargetPrefix"` |
||||
|
} |
||||
|
|
||||
|
// BucketPutLoggingOptions is the options of PutBucketLogging
|
||||
|
type BucketPutLoggingOptions struct { |
||||
|
XMLName xml.Name `xml:"BucketLoggingStatus"` |
||||
|
LoggingEnabled *BucketLoggingEnabled `xml:"LoggingEnabled"` |
||||
|
} |
||||
|
|
||||
|
// BucketGetLoggingResult is the result of GetBucketLogging
|
||||
|
type BucketGetLoggingResult struct { |
||||
|
XMLName xml.Name `xml:"BucketLoggingStatus"` |
||||
|
LoggingEnabled *BucketLoggingEnabled `xml:"LoggingEnabled"` |
||||
|
} |
||||
|
|
||||
|
// PutBucketLogging https://cloud.tencent.com/document/product/436/17054
|
||||
|
func (s *BucketService) PutBucketLoggingTest(ctx context.Context, opt *BucketPutLoggingOptions) (*Response, error) { |
||||
|
sendOpt := sendOptions{ |
||||
|
baseURL: s.client.BaseURL.BucketURL, |
||||
|
uri: "/?logging", |
||||
|
method: http.MethodPut, |
||||
|
body: opt, |
||||
|
} |
||||
|
resp, err := s.client.send(ctx, &sendOpt) |
||||
|
return resp, err |
||||
|
} |
||||
|
|
||||
|
// GetBucketLogging https://cloud.tencent.com/document/product/436/17053
|
||||
|
func (s *BucketService) GetBucketLoggingTest(ctx context.Context) (*BucketGetLoggingResult, *Response, error) { |
||||
|
var res BucketGetLoggingResult |
||||
|
sendOpt := sendOptions{ |
||||
|
baseURL: s.client.BaseURL.BucketURL, |
||||
|
uri: "/?logging", |
||||
|
method: http.MethodGet, |
||||
|
result: &res, |
||||
|
} |
||||
|
resp, err := s.client.send(ctx, &sendOpt) |
||||
|
return &res, resp, err |
||||
|
|
||||
|
} |
@ -0,0 +1,73 @@ |
|||||
|
package cos |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"encoding/xml" |
||||
|
"net/http" |
||||
|
) |
||||
|
|
||||
|
// ReplicationDestination is the sub struct of BucketReplicationRule
|
||||
|
type ReplicationDestination struct { |
||||
|
Bucket string `xml:"Bucket"` |
||||
|
StorageClass string `xml:"StorageClass,omitempty"` |
||||
|
} |
||||
|
|
||||
|
// BucketReplicationRule is the main param of replication
|
||||
|
type BucketReplicationRule struct { |
||||
|
ID string `xml:"ID,omitempty"` |
||||
|
Status string `xml:"Status"` |
||||
|
Prefix string `xml:"Prefix"` |
||||
|
Destination *ReplicationDestination `xml:"Destination"` |
||||
|
} |
||||
|
|
||||
|
// PutBucketReplicationOptions is the options of PutBucketReplication
|
||||
|
type PutBucketReplicationOptions struct { |
||||
|
XMLName xml.Name `xml:"ReplicationConfiguration"` |
||||
|
Role string `xml:"Role"` |
||||
|
Rule []BucketReplicationRule `xml:"Rule"` |
||||
|
} |
||||
|
|
||||
|
// GetBucketReplicationResult is the result of GetBucketReplication
|
||||
|
type GetBucketReplicationResult struct { |
||||
|
XMLName xml.Name `xml:"ReplicationConfiguration"` |
||||
|
Role string `xml:"Role"` |
||||
|
Rule []BucketReplicationRule `xml:"Rule"` |
||||
|
} |
||||
|
|
||||
|
// PutBucketReplication https://cloud.tencent.com/document/product/436/19223
|
||||
|
func (s *BucketService) PutBucketReplication(ctx context.Context, opt *PutBucketReplicationOptions) (*Response, error) { |
||||
|
sendOpt := sendOptions{ |
||||
|
baseURL: s.client.BaseURL.BucketURL, |
||||
|
uri: "/?replication", |
||||
|
method: http.MethodPut, |
||||
|
body: opt, |
||||
|
} |
||||
|
resp, err := s.client.send(ctx, &sendOpt) |
||||
|
return resp, err |
||||
|
|
||||
|
} |
||||
|
|
||||
|
// GetBucketReplication https://cloud.tencent.com/document/product/436/19222
|
||||
|
func (s *BucketService) GetBucketReplication(ctx context.Context) (*GetBucketReplicationResult, *Response, error) { |
||||
|
var res GetBucketReplicationResult |
||||
|
sendOpt := sendOptions{ |
||||
|
baseURL: s.client.BaseURL.BucketURL, |
||||
|
uri: "/?replication", |
||||
|
method: http.MethodGet, |
||||
|
result: &res, |
||||
|
} |
||||
|
resp, err := s.client.send(ctx, &sendOpt) |
||||
|
return &res, resp, err |
||||
|
|
||||
|
} |
||||
|
|
||||
|
// DeleteBucketReplication https://cloud.tencent.com/document/product/436/19221
|
||||
|
func (s *BucketService) DeleteBucketReplication(ctx context.Context) (*Response, error) { |
||||
|
sendOpt := sendOptions{ |
||||
|
baseURL: s.client.BaseURL.BucketURL, |
||||
|
uri: "/?replication", |
||||
|
method: http.MethodDelete, |
||||
|
} |
||||
|
resp, err := s.client.send(ctx, &sendOpt) |
||||
|
return resp, err |
||||
|
} |
@ -0,0 +1,45 @@ |
|||||
|
package cos |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"encoding/xml" |
||||
|
"net/http" |
||||
|
) |
||||
|
|
||||
|
// BucketPutVersionOptions is the options of PutBucketVersioning
|
||||
|
type BucketPutVersionOptions struct { |
||||
|
XMLName xml.Name `xml:"VersioningConfiguration"` |
||||
|
Status string `xml:"Status"` |
||||
|
} |
||||
|
|
||||
|
// BucketGetVersionResult is the result of GetBucketVersioning
|
||||
|
type BucketGetVersionResult struct { |
||||
|
XMLName xml.Name `xml:"VersioningConfiguration"` |
||||
|
Status string `xml:"Status"` |
||||
|
} |
||||
|
|
||||
|
// PutVersion https://cloud.tencent.com/document/product/436/19889
|
||||
|
// Status has Suspended\Enabled
|
||||
|
func (s *BucketService) PutVersioning(ctx context.Context, opt *BucketPutVersionOptions) (*Response, error) { |
||||
|
sendOpt := sendOptions{ |
||||
|
baseURL: s.client.BaseURL.BucketURL, |
||||
|
uri: "/?versioning", |
||||
|
method: http.MethodPut, |
||||
|
body: opt, |
||||
|
} |
||||
|
resp, err := s.client.send(ctx, &sendOpt) |
||||
|
return resp, err |
||||
|
} |
||||
|
|
||||
|
// GetVersion https://cloud.tencent.com/document/product/436/19888
|
||||
|
func (s *BucketService) GetVersioning(ctx context.Context) (*BucketGetVersionResult, *Response, error) { |
||||
|
var res BucketGetVersionResult |
||||
|
sendOpt := sendOptions{ |
||||
|
baseURL: s.client.BaseURL.BucketURL, |
||||
|
uri: "/?versioning", |
||||
|
method: http.MethodGet, |
||||
|
result: &res, |
||||
|
} |
||||
|
resp, err := s.client.send(ctx, &sendOpt) |
||||
|
return &res, resp, err |
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"net/url" |
||||
|
"os" |
||||
|
|
||||
|
"net/http" |
||||
|
|
||||
|
"github.com/tencentyun/cos-go-sdk-v5" |
||||
|
"github.com/tencentyun/cos-go-sdk-v5/debug" |
||||
|
) |
||||
|
|
||||
|
func main() { |
||||
|
u, _ := url.Parse("https://alanbj-1251668577.cos.ap-beijing.myqcloud.com") |
||||
|
b := &cos.BaseURL{ |
||||
|
BucketURL: u, |
||||
|
} |
||||
|
c := cos.NewClient(b, &http.Client{ |
||||
|
Transport: &cos.AuthorizationTransport{ |
||||
|
SecretID: os.Getenv("COS_SECRETID"), |
||||
|
SecretKey: os.Getenv("COS_SECRETKEY"), |
||||
|
Transport: &debug.DebugRequestTransport{ |
||||
|
RequestHeader: true, |
||||
|
RequestBody: true, |
||||
|
ResponseHeader: true, |
||||
|
ResponseBody: true, |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
|
||||
|
_, err := c.Bucket.DeleteBucketReplication(context.Background()) |
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"net/url" |
||||
|
"os" |
||||
|
|
||||
|
"net/http" |
||||
|
|
||||
|
"github.com/tencentyun/cos-go-sdk-v5" |
||||
|
"github.com/tencentyun/cos-go-sdk-v5/debug" |
||||
|
) |
||||
|
|
||||
|
func main() { |
||||
|
u, _ := url.Parse("https://alanbj-1251668577.cos.ap-beijing.myqcloud.com") |
||||
|
b := &cos.BaseURL{ |
||||
|
BucketURL: u, |
||||
|
} |
||||
|
c := cos.NewClient(b, &http.Client{ |
||||
|
Transport: &cos.AuthorizationTransport{ |
||||
|
SecretID: os.Getenv("COS_SECRETID"), |
||||
|
SecretKey: os.Getenv("COS_SECRETKEY"), |
||||
|
Transport: &debug.DebugRequestTransport{ |
||||
|
RequestHeader: true, |
||||
|
RequestBody: true, |
||||
|
ResponseHeader: true, |
||||
|
ResponseBody: true, |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
|
||||
|
v, _, err := c.Bucket.GetBucketReplication(context.Background()) |
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
for _, r := range v.Rule { |
||||
|
|
||||
|
fmt.Printf("%s, %s\n", r.Status, r.ID) |
||||
|
} |
||||
|
} |
@ -0,0 +1,39 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"net/url" |
||||
|
"os" |
||||
|
|
||||
|
"net/http" |
||||
|
|
||||
|
"github.com/tencentyun/cos-go-sdk-v5" |
||||
|
"github.com/tencentyun/cos-go-sdk-v5/debug" |
||||
|
) |
||||
|
|
||||
|
func main() { |
||||
|
u, _ := url.Parse("https://alanbj-1251668577.cos.ap-beijing.myqcloud.com") |
||||
|
b := &cos.BaseURL{ |
||||
|
BucketURL: u, |
||||
|
} |
||||
|
c := cos.NewClient(b, &http.Client{ |
||||
|
Transport: &cos.AuthorizationTransport{ |
||||
|
SecretID: os.Getenv("COS_SECRETID"), |
||||
|
SecretKey: os.Getenv("COS_SECRETKEY"), |
||||
|
Transport: &debug.DebugRequestTransport{ |
||||
|
RequestHeader: true, |
||||
|
RequestBody: true, |
||||
|
ResponseHeader: true, |
||||
|
ResponseBody: true, |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
|
||||
|
v, _, err := c.Bucket.GetVersioning(context.Background()) |
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
|
||||
|
fmt.Printf("status is %s \n", v.Status) |
||||
|
} |
@ -0,0 +1,51 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"net/url" |
||||
|
"os" |
||||
|
|
||||
|
"net/http" |
||||
|
|
||||
|
"github.com/tencentyun/cos-go-sdk-v5" |
||||
|
"github.com/tencentyun/cos-go-sdk-v5/debug" |
||||
|
) |
||||
|
|
||||
|
func main() { |
||||
|
u, _ := url.Parse("https://alanbj-1251668577.cos.ap-beijing.myqcloud.com") |
||||
|
b := &cos.BaseURL{ |
||||
|
BucketURL: u, |
||||
|
} |
||||
|
c := cos.NewClient(b, &http.Client{ |
||||
|
Transport: &cos.AuthorizationTransport{ |
||||
|
SecretID: os.Getenv("COS_SECRETID"), |
||||
|
SecretKey: os.Getenv("COS_SECRETKEY"), |
||||
|
Transport: &debug.DebugRequestTransport{ |
||||
|
RequestHeader: true, |
||||
|
RequestBody: true, |
||||
|
ResponseHeader: true, |
||||
|
ResponseBody: true, |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
|
||||
|
opt := &cos.PutBucketReplicationOptions{ |
||||
|
// qcs::cam::uin/[UIN]:uin/[Subaccount]
|
||||
|
Role: "qcs::cam::uin/2779643970:uin/2779643970", |
||||
|
Rule: []cos.BucketReplicationRule{ |
||||
|
{ |
||||
|
ID: "1", |
||||
|
// Enabled or Disabled
|
||||
|
Status: "Enabled", |
||||
|
Destination: &cos.ReplicationDestination{ |
||||
|
// qcs::cos:[Region]::[Bucketname-Appid]
|
||||
|
Bucket: "qcs::cos:ap-guangzhou::alangz-1251668577", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
} |
||||
|
_, err := c.Bucket.PutBucketReplication(context.Background(), opt) |
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"net/url" |
||||
|
"os" |
||||
|
|
||||
|
"net/http" |
||||
|
|
||||
|
"github.com/tencentyun/cos-go-sdk-v5" |
||||
|
"github.com/tencentyun/cos-go-sdk-v5/debug" |
||||
|
) |
||||
|
|
||||
|
func main() { |
||||
|
u, _ := url.Parse("https://alanbj-1251668577.cos.ap-beijing.myqcloud.com") |
||||
|
b := &cos.BaseURL{ |
||||
|
BucketURL: u, |
||||
|
} |
||||
|
c := cos.NewClient(b, &http.Client{ |
||||
|
Transport: &cos.AuthorizationTransport{ |
||||
|
SecretID: os.Getenv("COS_SECRETID"), |
||||
|
SecretKey: os.Getenv("COS_SECRETKEY"), |
||||
|
Transport: &debug.DebugRequestTransport{ |
||||
|
RequestHeader: true, |
||||
|
RequestBody: true, |
||||
|
ResponseHeader: true, |
||||
|
ResponseBody: true, |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
|
||||
|
opt := &cos.BucketPutVersionOptions{ |
||||
|
// Enabled or Suspended, the versioning once opened can not close.
|
||||
|
Status: "Enabled", |
||||
|
} |
||||
|
|
||||
|
_, err := c.Bucket.PutVersioning(context.Background(), opt) |
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue