Skip to content

Commit c807d39

Browse files
authored
Merge pull request #66 from agin719/cos-v3-dev
inventory/logging/replication/versioning/tagging
2 parents 4e467b3 + 44546a4 commit c807d39

10 files changed

+623
-60
lines changed

bucket_inventory.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ type BucketInventoryFilter struct {
2222

2323
// BucketInventoryOptionalFields ...
2424
type BucketInventoryOptionalFields struct {
25-
XMLName xml.Name `xml:"OptionalFields,omitempty"`
2625
BucketInventoryFields []string `xml:"Field,omitempty"`
2726
}
2827

@@ -33,25 +32,18 @@ type BucketInventorySchedule struct {
3332

3433
// BucketInventoryEncryption ...
3534
type BucketInventoryEncryption struct {
36-
XMLName xml.Name `xml:"Encryption"`
37-
SSECOS string `xml:"SSE-COS,omitempty"`
35+
SSECOS string `xml:"SSE-COS"`
3836
}
3937

40-
// BucketInventoryDestinationContent ...
41-
type BucketInventoryDestinationContent struct {
38+
// BucketInventoryDestination ...
39+
type BucketInventoryDestination struct {
4240
Bucket string `xml:"Bucket"`
4341
AccountId string `xml:"AccountId,omitempty"`
4442
Prefix string `xml:"Prefix,omitempty"`
4543
Format string `xml:"Format"`
4644
Encryption *BucketInventoryEncryption `xml:"Encryption,omitempty"`
4745
}
4846

49-
// BucketInventoryDestination ...
50-
type BucketInventoryDestination struct {
51-
XMLName xml.Name `xml:"Destination"`
52-
BucketDestination *BucketInventoryDestinationContent `xml:"COSBucketDestination"`
53-
}
54-
5547
// BucketPutInventoryOptions ...
5648
type BucketPutInventoryOptions struct {
5749
XMLName xml.Name `xml:"InventoryConfiguration"`
@@ -61,7 +53,7 @@ type BucketPutInventoryOptions struct {
6153
Filter *BucketInventoryFilter `xml:"Filter,omitempty"`
6254
OptionalFields *BucketInventoryOptionalFields `xml:"OptionalFields,omitempty"`
6355
Schedule *BucketInventorySchedule `xml:"Schedule"`
64-
Destination *BucketInventoryDestination `xml:"Destination"`
56+
Destination *BucketInventoryDestination `xml:"Destination>COSBucketDestination"`
6557
}
6658

6759
// ListBucketInventoryConfigResult result of ListBucketInventoryConfiguration
@@ -74,7 +66,7 @@ type ListBucketInventoryConfigResult struct {
7466
}
7567

7668
// PutBucketInventory https://cloud.tencent.com/document/product/436/33707
77-
func (s *BucketService) PutBucketInventoryTest(ctx context.Context, id string, opt *BucketPutInventoryOptions) (*Response, error) {
69+
func (s *BucketService) PutInventory(ctx context.Context, id string, opt *BucketPutInventoryOptions) (*Response, error) {
7870
u := fmt.Sprintf("/?inventory&id=%s", id)
7971
sendOpt := sendOptions{
8072
baseURL: s.client.BaseURL.BucketURL,
@@ -88,7 +80,7 @@ func (s *BucketService) PutBucketInventoryTest(ctx context.Context, id string, o
8880
}
8981

9082
// GetBucketInventory https://cloud.tencent.com/document/product/436/33705
91-
func (s *BucketService) GetBucketInventoryTest(ctx context.Context, id string) (*BucketGetInventoryResult, *Response, error) {
83+
func (s *BucketService) GetInventory(ctx context.Context, id string) (*BucketGetInventoryResult, *Response, error) {
9284
u := fmt.Sprintf("/?inventory&id=%s", id)
9385
var res BucketGetInventoryResult
9486
sendOpt := sendOptions{
@@ -102,7 +94,7 @@ func (s *BucketService) GetBucketInventoryTest(ctx context.Context, id string) (
10294
}
10395

10496
// DeleteBucketInventory https://cloud.tencent.com/document/product/436/33704
105-
func (s *BucketService) DeleteBucketInventoryTest(ctx context.Context, id string) (*Response, error) {
97+
func (s *BucketService) DeleteInventory(ctx context.Context, id string) (*Response, error) {
10698
u := fmt.Sprintf("/?inventory&id=%s", id)
10799
sendOpt := sendOptions{
108100
baseURL: s.client.BaseURL.BucketURL,
@@ -114,7 +106,7 @@ func (s *BucketService) DeleteBucketInventoryTest(ctx context.Context, id string
114106
}
115107

116108
// ListBucketInventoryConfigurations https://cloud.tencent.com/document/product/436/33706
117-
func (s *BucketService) ListBucketInventoryConfigurationsTest(ctx context.Context, token string) (*ListBucketInventoryConfigResult, *Response, error) {
109+
func (s *BucketService) ListInventoryConfigurations(ctx context.Context, token string) (*ListBucketInventoryConfigResult, *Response, error) {
118110
var res ListBucketInventoryConfigResult
119111
var u string
120112
if token == "" {

bucket_inventory_test.go

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
package cos
2+
3+
import (
4+
"context"
5+
"encoding/xml"
6+
"fmt"
7+
"net/http"
8+
"reflect"
9+
"testing"
10+
)
11+
12+
func TestBucketService_PutInventory(t *testing.T) {
13+
setup()
14+
defer teardown()
15+
opt := &BucketPutInventoryOptions{
16+
XMLName: xml.Name{Local: "InventoryConfiguration"},
17+
ID: "list1",
18+
IsEnabled: "True",
19+
IncludedObjectVersions: "All",
20+
Filter: &BucketInventoryFilter{"myPrefix"},
21+
Schedule: &BucketInventorySchedule{"Daily"},
22+
Destination: &BucketInventoryDestination{
23+
Bucket: "qcs::cos:ap-guangzhou::examplebucket-1250000000",
24+
AccountId: "100000000001",
25+
Prefix: "list1",
26+
Format: "CSV",
27+
Encryption: &BucketInventoryEncryption{},
28+
},
29+
OptionalFields: &BucketInventoryOptionalFields{
30+
BucketInventoryFields: []string{
31+
"Size",
32+
"LastModifiedDate",
33+
"ETag",
34+
"StorageClass",
35+
"IsMultipartUploaded",
36+
"ReplicationStatus",
37+
},
38+
},
39+
}
40+
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
41+
testMethod(t, r, http.MethodPut)
42+
vs := values{
43+
"inventory": "",
44+
"id": "list1",
45+
}
46+
testFormValues(t, r, vs)
47+
48+
body := &BucketPutInventoryOptions{}
49+
xml.NewDecoder(r.Body).Decode(body)
50+
want := opt
51+
if !reflect.DeepEqual(want, body) {
52+
t.Fatalf("Bucket.PutInventory request\n body: %+v\n, want %+v\n", body, want)
53+
}
54+
})
55+
56+
_, err := client.Bucket.PutInventory(context.Background(), "list1", opt)
57+
if err != nil {
58+
t.Fatalf("Bucket.PutInventory failed, error: %v", err)
59+
}
60+
}
61+
62+
func TestBucketService_GetInventory(t *testing.T) {
63+
setup()
64+
defer teardown()
65+
66+
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
67+
testMethod(t, r, http.MethodGet)
68+
vs := values{
69+
"inventory": "",
70+
"id": "list1",
71+
}
72+
testFormValues(t, r, vs)
73+
74+
fmt.Fprint(w, `<InventoryConfiguration>
75+
<Id>list1</Id>
76+
<IsEnabled>True</IsEnabled>
77+
<Destination>
78+
<COSBucketDestination>
79+
<Format>CSV</Format>
80+
<Bucket>qcs::cos:ap-guangzhou::examplebucket-1250000000</Bucket>
81+
<Prefix>list1</Prefix>
82+
<AccountId>100000000001</AccountId>
83+
</COSBucketDestination>
84+
</Destination>
85+
<Schedule>
86+
<Frequency>Daily</Frequency>
87+
</Schedule>
88+
<Filter>
89+
<Prefix>myPrefix</Prefix>
90+
</Filter>
91+
<IncludedObjectVersions>All</IncludedObjectVersions>
92+
<OptionalFields>
93+
<Field>Size</Field>
94+
<Field>LastModifiedDate</Field>
95+
<Field>ETag</Field>
96+
<Field>StorageClass</Field>
97+
<Field>IsMultipartUploaded</Field>
98+
<Field>ReplicationStatus</Field>
99+
</OptionalFields>
100+
</InventoryConfiguration>`)
101+
})
102+
res, _, err := client.Bucket.GetInventory(context.Background(), "list1")
103+
if err != nil {
104+
t.Fatalf("Bucket.GetInventory failed, error: %v", err)
105+
}
106+
want := &BucketGetInventoryResult{
107+
XMLName: xml.Name{Local: "InventoryConfiguration"},
108+
ID: "list1",
109+
IsEnabled: "True",
110+
IncludedObjectVersions: "All",
111+
Filter: &BucketInventoryFilter{"myPrefix"},
112+
Schedule: &BucketInventorySchedule{"Daily"},
113+
Destination: &BucketInventoryDestination{
114+
Bucket: "qcs::cos:ap-guangzhou::examplebucket-1250000000",
115+
AccountId: "100000000001",
116+
Prefix: "list1",
117+
Format: "CSV",
118+
},
119+
OptionalFields: &BucketInventoryOptionalFields{
120+
BucketInventoryFields: []string{
121+
"Size",
122+
"LastModifiedDate",
123+
"ETag",
124+
"StorageClass",
125+
"IsMultipartUploaded",
126+
"ReplicationStatus",
127+
},
128+
},
129+
}
130+
131+
if !reflect.DeepEqual(res, want) {
132+
t.Errorf("Bucket.GetInventory returned\n%+v, want\n%+v", res, want)
133+
}
134+
}
135+
136+
func TestBucketService_ListInventory(t *testing.T) {
137+
setup()
138+
defer teardown()
139+
140+
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
141+
testMethod(t, r, http.MethodGet)
142+
vs := values{
143+
"inventory": "",
144+
}
145+
testFormValues(t, r, vs)
146+
fmt.Fprint(w, `<ListInventoryConfigurationResult>
147+
<InventoryConfiguration>
148+
<Id>list1</Id>
149+
<IsEnabled>True</IsEnabled>
150+
<Destination>
151+
<COSBucketDestination>
152+
<Format>CSV</Format>
153+
<AccountId>1250000000</AccountId>
154+
<Bucket>qcs::cos:ap-beijing::examplebucket-1250000000</Bucket>
155+
<Prefix>list1</Prefix>
156+
<Encryption>
157+
<SSE-COS/>
158+
</Encryption>
159+
</COSBucketDestination>
160+
</Destination>
161+
<Schedule>
162+
<Frequency>Daily</Frequency>
163+
</Schedule>
164+
<Filter>
165+
<Prefix>myPrefix</Prefix>
166+
</Filter>
167+
<IncludedObjectVersions>All</IncludedObjectVersions>
168+
<OptionalFields>
169+
<Field>Size</Field>
170+
<Field>LastModifiedDate</Field>
171+
<Field>ETag</Field>
172+
<Field>StorageClass</Field>
173+
<Field>IsMultipartUpload</Field>
174+
<Field>ReplicationStatus</Field>
175+
</OptionalFields>
176+
</InventoryConfiguration>
177+
<InventoryConfiguration>
178+
<Id>list2</Id>
179+
<IsEnabled>True</IsEnabled>
180+
<Destination>
181+
<COSBucketDestination>
182+
<Format>CSV</Format>
183+
<AccountId>1250000000</AccountId>
184+
<Bucket>qcs::cos:ap-beijing::examplebucket-1250000000</Bucket>
185+
<Prefix>list2</Prefix>
186+
</COSBucketDestination>
187+
</Destination>
188+
<Schedule>
189+
<Frequency>Weekly</Frequency>
190+
</Schedule>
191+
<Filter>
192+
<Prefix>myPrefix2</Prefix>
193+
</Filter>
194+
<IncludedObjectVersions>All</IncludedObjectVersions>
195+
<OptionalFields>
196+
<Field>Size</Field>
197+
<Field>LastModifiedDate</Field>
198+
<Field>ETag</Field>
199+
<Field>StorageClass</Field>
200+
</OptionalFields>
201+
</InventoryConfiguration>
202+
<IsTruncated>false</IsTruncated>
203+
<ContinuationToken>...</ContinuationToken>
204+
<IsTruncated>true</IsTruncated>
205+
<NextContinuationToken>1ueSDFASDF1Tr/XDAFdadEADadf2J/wm36Hy4vbOwM=</NextContinuationToken>
206+
</ListInventoryConfigurationResult>`)
207+
})
208+
209+
res, _, err := client.Bucket.ListInventoryConfigurations(context.Background(), "")
210+
if err != nil {
211+
t.Fatalf("Bucket.ListInventory failed, error: %v", err)
212+
}
213+
want := &ListBucketInventoryConfigResult{
214+
XMLName: xml.Name{Local: "ListInventoryConfigurationResult"},
215+
IsTruncated: true,
216+
ContinuationToken: "...",
217+
NextContinuationToken: "1ueSDFASDF1Tr/XDAFdadEADadf2J/wm36Hy4vbOwM=",
218+
InventoryConfigurations: []BucketListInventoryConfiguartion{
219+
BucketListInventoryConfiguartion{
220+
XMLName: xml.Name{Local: "InventoryConfiguration"},
221+
ID: "list1",
222+
IsEnabled: "True",
223+
IncludedObjectVersions: "All",
224+
Filter: &BucketInventoryFilter{"myPrefix"},
225+
Schedule: &BucketInventorySchedule{"Daily"},
226+
Destination: &BucketInventoryDestination{
227+
Bucket: "qcs::cos:ap-beijing::examplebucket-1250000000",
228+
AccountId: "1250000000",
229+
Prefix: "list1",
230+
Format: "CSV",
231+
Encryption: &BucketInventoryEncryption{},
232+
},
233+
OptionalFields: &BucketInventoryOptionalFields{
234+
BucketInventoryFields: []string{
235+
"Size",
236+
"LastModifiedDate",
237+
"ETag",
238+
"StorageClass",
239+
"IsMultipartUpload",
240+
"ReplicationStatus",
241+
},
242+
},
243+
},
244+
BucketListInventoryConfiguartion{
245+
XMLName: xml.Name{Local: "InventoryConfiguration"},
246+
ID: "list2",
247+
IsEnabled: "True",
248+
IncludedObjectVersions: "All",
249+
Filter: &BucketInventoryFilter{"myPrefix2"},
250+
Schedule: &BucketInventorySchedule{"Weekly"},
251+
Destination: &BucketInventoryDestination{
252+
Bucket: "qcs::cos:ap-beijing::examplebucket-1250000000",
253+
AccountId: "1250000000",
254+
Prefix: "list2",
255+
Format: "CSV",
256+
},
257+
OptionalFields: &BucketInventoryOptionalFields{
258+
BucketInventoryFields: []string{
259+
"Size",
260+
"LastModifiedDate",
261+
"ETag",
262+
"StorageClass",
263+
},
264+
},
265+
},
266+
},
267+
}
268+
if !reflect.DeepEqual(res, want) {
269+
t.Fatalf("Bucket.ListInventory failed, \nwant: %+v\nres: %+v", want, res)
270+
}
271+
}
272+
273+
func TestBucketService_DeleteInventory(t *testing.T) {
274+
setup()
275+
defer teardown()
276+
277+
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
278+
testMethod(t, r, http.MethodDelete)
279+
vs := values{
280+
"inventory": "",
281+
"id": "list1",
282+
}
283+
testFormValues(t, r, vs)
284+
285+
w.WriteHeader(http.StatusNoContent)
286+
})
287+
288+
_, err := client.Bucket.DeleteInventory(context.Background(), "list1")
289+
if err != nil {
290+
t.Fatalf("Bucket.DeleteInventory returned error: %v", err)
291+
}
292+
}

0 commit comments

Comments
 (0)