Support Versioning, Replication, Inventory and Logging api
This commit is contained in:
132
bucket_inventory.go
Normal file
132
bucket_inventory.go
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
package cos
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/xml"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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) PutBucketInventory(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) GetBucketInventory(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) DeleteBucketInventory(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) ListBucketInventoryConfigurations(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
|
||||||
|
|
||||||
|
}
|
||||||
51
bucket_logging.go
Normal file
51
bucket_logging.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package cos
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/xml"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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) PutBucketLogging(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) GetBucketLogging(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
|
||||||
|
|
||||||
|
}
|
||||||
73
bucket_replication.go
Normal file
73
bucket_replication.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
45
bucket_version.go
Normal file
45
bucket_version.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -185,6 +185,100 @@ func (s *CosTestSuite) TestPutGetDeleteCORS() {
|
|||||||
assert.Equal(s.T(), 1, len(v.Rules), "GetBucketCORS wrong number rules")
|
assert.Equal(s.T(), 1, len(v.Rules), "GetBucketCORS wrong number rules")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *CosTestSuite) TestVersionAndReplication() {
|
||||||
|
opt := &cos.BucketPutVersionOptions{
|
||||||
|
// Enabled or Suspended, the versioning once opened can not close.
|
||||||
|
Status: "Enabled",
|
||||||
|
}
|
||||||
|
_, err := s.Client.Bucket.PutVersioning(context.Background(), opt)
|
||||||
|
assert.Nil(s.T(), err, "PutVersioning Failed")
|
||||||
|
v, _, err := s.Client.Bucket.GetVersioning(context.Background())
|
||||||
|
assert.Nil(s.T(), err, "GetVersioning Failed")
|
||||||
|
assert.Equal(s.T(), "Enabled", v.Status, "Get Wrong Version status")
|
||||||
|
|
||||||
|
repOpt := &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-beijing::alanbj-1251668577",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = s.Client.Bucket.PutBucketReplication(context.Background(), repOpt)
|
||||||
|
assert.Nil(s.T(), err, "PutBucketReplication Failed")
|
||||||
|
vr, _, err := s.Client.Bucket.GetBucketReplication(context.Background())
|
||||||
|
assert.Nil(s.T(), err, "GetBucketReplication Failed")
|
||||||
|
for _, r := range vr.Rule {
|
||||||
|
assert.Equal(s.T(), "Enabled", r.Status, "Get Wrong Version status")
|
||||||
|
assert.Equal(s.T(), "qcs::cos:ap-beijing::alanbj-1251668577", r.Destination.Bucket, "Get Wrong Version status")
|
||||||
|
|
||||||
|
}
|
||||||
|
_, err = s.Client.Bucket.DeleteBucketReplication(context.Background())
|
||||||
|
assert.Nil(s.T(), err, "DeleteBucketReplication Failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CosTestSuite) TestBucketInventory() {
|
||||||
|
id := "test1"
|
||||||
|
opt := &cos.BucketPutInventoryOptions{
|
||||||
|
ID: id,
|
||||||
|
// True or False
|
||||||
|
IsEnabled: "True",
|
||||||
|
IncludedObjectVersions: "All",
|
||||||
|
Filter: &cos.BucketInventoryFilter{
|
||||||
|
Prefix: "test",
|
||||||
|
},
|
||||||
|
OptionalFields: &cos.BucketInventoryOptionalFields{
|
||||||
|
BucketInventoryFields: []string{
|
||||||
|
"Size", "LastModifiedDate",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Schedule: &cos.BucketInventorySchedule{
|
||||||
|
// Weekly or Daily
|
||||||
|
Frequency: "Daily",
|
||||||
|
},
|
||||||
|
Destination: &cos.BucketInventoryDestination{
|
||||||
|
BucketDestination: &cos.BucketInventoryDestinationContent{
|
||||||
|
Bucket: "qcs::cos:ap-guangzhou::alangz-1251668577",
|
||||||
|
Format: "CSV",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, err := s.Client.Bucket.PutBucketInventory(context.Background(), id, opt)
|
||||||
|
assert.Nil(s.T(), err, "PutBucketInventory Failed")
|
||||||
|
v, _, err := s.Client.Bucket.GetBucketInventory(context.Background(), id)
|
||||||
|
assert.Nil(s.T(), err, "GetBucketInventory Failed")
|
||||||
|
assert.Equal(s.T(), "test1", v.ID, "Get Wrong inventory id")
|
||||||
|
assert.Equal(s.T(), "True", v.IsEnabled, "Get Wrong inventory isenabled")
|
||||||
|
assert.Equal(s.T(), "qcs::cos:ap-guangzhou::alangz-1251668577", v.Destination.BucketDestination.Bucket, "Get Wrong inventory isenabled")
|
||||||
|
|
||||||
|
_, err = s.Client.Bucket.DeleteBucketInventory(context.Background(), id)
|
||||||
|
assert.Nil(s.T(), err, "DeleteBucketInventory Failed")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CosTestSuite) TestBucketLogging() {
|
||||||
|
opt := &cos.BucketPutLoggingOptions{
|
||||||
|
LoggingEnabled: &cos.BucketLoggingEnabled{
|
||||||
|
// The bucket must same region.
|
||||||
|
TargetBucket: "alangz-1251668577",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, err := s.Client.Bucket.PutBucketLogging(context.Background(), opt)
|
||||||
|
assert.Nil(s.T(), err, "PutBucketLogging Failed")
|
||||||
|
v, _, err := s.Client.Bucket.GetBucketLogging(context.Background())
|
||||||
|
assert.Nil(s.T(), err, "GetBucketLogging Failed")
|
||||||
|
assert.Equal(s.T(), "alangz-1251668577", v.LoggingEnabled.TargetBucket, "Get Wrong Version status")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (s *CosTestSuite) TestPutGetDeleteLifeCycle() {
|
func (s *CosTestSuite) TestPutGetDeleteLifeCycle() {
|
||||||
lc := &cos.BucketPutLifecycleOptions{
|
lc := &cos.BucketPutLifecycleOptions{
|
||||||
Rules: []cos.BucketLifecycleRule{
|
Rules: []cos.BucketLifecycleRule{
|
||||||
@@ -351,7 +445,7 @@ func (s *CosTestSuite) TestPutObjectRestore() {
|
|||||||
Tier: "Expedited",
|
Tier: "Expedited",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
resp, _ := s.Client.Object.PutRestore(context.Background(), name, opt)
|
resp, _ := s.Client.Object.PostRestore(context.Background(), name, opt)
|
||||||
retCode := resp.StatusCode
|
retCode := resp.StatusCode
|
||||||
if retCode != 200 && retCode != 202 && retCode != 409 {
|
if retCode != 200 && retCode != 202 && retCode != 409 {
|
||||||
right := false
|
right := false
|
||||||
|
|||||||
37
example/bucket/deleteInventory.go
Normal file
37
example/bucket/deleteInventory.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
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://alangz-1251668577.cos.ap-guangzhou.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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
id := "test1"
|
||||||
|
_, err := c.Bucket.DeleteBucketInventory(context.Background(), id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
example/bucket/deleteReplication.go
Normal file
36
example/bucket/deleteReplication.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
38
example/bucket/getInventory.go
Normal file
38
example/bucket/getInventory.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
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://alangz-1251668577.cos.ap-guangzhou.myqcloud.com")
|
||||||
|
// u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
id := "test1"
|
||||||
|
_, _, err := c.Bucket.GetBucketInventory(context.Background(), id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
41
example/bucket/getLogging.go
Normal file
41
example/bucket/getLogging.go
Normal file
@@ -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://alangz-1251668577.cos.ap-guangzhou.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.GetBucketLogging(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.LoggingEnabled != nil {
|
||||||
|
fmt.Printf("target bucket is %s \n", v.LoggingEnabled.TargetBucket)
|
||||||
|
}
|
||||||
|
}
|
||||||
41
example/bucket/getReplication.go
Normal file
41
example/bucket/getReplication.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
39
example/bucket/getVersioning.go
Normal file
39
example/bucket/getVersioning.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
40
example/bucket/listInventoryConfig.go
Normal file
40
example/bucket/listInventoryConfig.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
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://alangz-1251668577.cos.ap-guangzhou.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.ListBucketInventoryConfigurations(context.Background(), "")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
for _, p := range v.InventoryConfigurations {
|
||||||
|
fmt.Printf("%s\n", p.Destination.BucketDestination.Bucket)
|
||||||
|
}
|
||||||
|
}
|
||||||
61
example/bucket/putInventory.go
Normal file
61
example/bucket/putInventory.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
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://alangz-1251668577.cos.ap-guangzhou.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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
id := "test1"
|
||||||
|
opt := &cos.BucketPutInventoryOptions{
|
||||||
|
ID: id,
|
||||||
|
// True or False
|
||||||
|
IsEnabled: "True",
|
||||||
|
IncludedObjectVersions: "All",
|
||||||
|
Filter: &cos.BucketInventoryFilter{
|
||||||
|
Prefix: "test",
|
||||||
|
},
|
||||||
|
OptionalFields: &cos.BucketInventoryOptionalFields{
|
||||||
|
BucketInventoryFields: []string{
|
||||||
|
"Size", "LastModifiedDate",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Schedule: &cos.BucketInventorySchedule{
|
||||||
|
// Weekly or Daily
|
||||||
|
Frequency: "Daily",
|
||||||
|
},
|
||||||
|
Destination: &cos.BucketInventoryDestination{
|
||||||
|
BucketDestination: &cos.BucketInventoryDestinationContent{
|
||||||
|
Bucket: "qcs::cos:ap-guangzhou::alangz-1251668577",
|
||||||
|
Format: "CSV",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_, err := c.Bucket.PutBucketInventory(context.Background(), id, opt)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
43
example/bucket/putLogging.go
Normal file
43
example/bucket/putLogging.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
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://alangz-1251668577.cos.ap-guangzhou.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.BucketPutLoggingOptions{
|
||||||
|
LoggingEnabled: &cos.BucketLoggingEnabled{
|
||||||
|
// The bucket must same region.
|
||||||
|
TargetBucket: "alangzz-1251668577",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := c.Bucket.PutBucketLogging(context.Background(), opt)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
51
example/bucket/putReplication.go
Normal file
51
example/bucket/putReplication.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
41
example/bucket/putVersioning.go
Normal file
41
example/bucket/putVersioning.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user