forked from tencentyun/cos-go-sdk-v5
/
bucket_inventory.go
126 lines (109 loc) · 4.34 KB
/
bucket_inventory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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 {
BucketInventoryFields []string `xml:"Field,omitempty"`
}
// BucketInventorySchedule ...
type BucketInventorySchedule struct {
Frequency string `xml:"Frequency"`
}
// BucketInventoryEncryption ...
type BucketInventoryEncryption struct {
SSECOS string `xml:"SSE-COS"`
}
// BucketInventoryDestination ...
type BucketInventoryDestination struct {
Bucket string `xml:"Bucket"`
AccountId string `xml:"AccountId,omitempty"`
Prefix string `xml:"Prefix,omitempty"`
Format string `xml:"Format"`
Encryption *BucketInventoryEncryption `xml:"Encryption,omitempty"`
}
// 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>COSBucketDestination"`
}
// 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) PutInventory(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) GetInventory(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) DeleteInventory(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) ListInventoryConfigurations(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
}