-
Notifications
You must be signed in to change notification settings - Fork 91
/
bucket_lifecycle.go
137 lines (121 loc) · 5.92 KB
/
bucket_lifecycle.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
127
128
129
130
131
132
133
134
135
136
137
package cos
import (
"context"
"encoding/xml"
"net/http"
)
type BucketLifecycleAndOperator struct {
Prefix string `xml:"Prefix,omitempty" header:"-"`
Tag []BucketTaggingTag `xml:"Tag,omitempty" header:"-"`
PrefixNotEquals string `xml:"PrefixNotEquals,omitempty" header:"-"`
ObjectSizeGreaterThan int64 `xml:"ObjectSizeGreaterThan,omitempty" header:"-"`
ObjectSizeLessThan int64 `xml:"ObjectSizeLessThan,omitempty" header:"-"`
}
// BucketLifecycleFilter is the param of BucketLifecycleRule
type BucketLifecycleFilter struct {
Prefix string `xml:"Prefix,omitempty" header:"-"`
Tag *BucketTaggingTag `xml:"Tag,omitempty" header:"-"`
And *BucketLifecycleAndOperator `xml:"And,omitempty" header:"-"`
}
// BucketLifecycleExpiration is the param of BucketLifecycleRule
type BucketLifecycleExpiration struct {
Date string `xml:"Date,omitempty" header:"-"`
Days int `xml:"Days,omitempty" header:"-"`
ExpiredObjectDeleteMarker bool `xml:"ExpiredObjectDeleteMarker,omitempty" header:"-"`
}
type BucketAccessFrequency struct {
AccessCountLessThan int `xml:"AccessCountLessThan,omitempty" header:"-"`
RecentDays int `xml:"RecentDays,omitempty" header:"-"`
}
// BucketLifecycleTransition is the param of BucketLifecycleRule
type BucketLifecycleTransition struct {
Date string `xml:"Date,omitempty" header:"-"`
Days int `xml:"Days,omitempty" header:"-"`
StorageClass string `xml:"StorageClass,omitempty" header:"-"`
AccessFrequency *BucketAccessFrequency `xml:"AccessFrequency,omitempty" header:"-"`
}
type BucketLifecycleNoncurrentVersion struct {
NoncurrentDays int `xml:"NoncurrentDays,omitempty" header:"-"`
StorageClass string `xml:"StorageClass,omitempty" header:"-"`
AccessFrequency *BucketAccessFrequency `xml:"AccessFrequency,omitempty" header:"-"`
}
// BucketLifecycleAbortIncompleteMultipartUpload is the param of BucketLifecycleRule
type BucketLifecycleAbortIncompleteMultipartUpload struct {
DaysAfterInitiation int `xml:"DaysAfterInitiation,omitempty" header:"-"`
}
// BucketLifecycleRule is the rule of BucketLifecycle
type BucketLifecycleRule struct {
ID string `xml:"ID,omitempty" header:"-"`
Status string `xml:"Status,omitempty" header:"-"`
Filter *BucketLifecycleFilter `xml:"Filter,omitempty" header:"-"`
Transition []BucketLifecycleTransition `xml:"Transition,omitempty" header:"-"`
Expiration *BucketLifecycleExpiration `xml:"Expiration,omitempty" header:"-"`
AbortIncompleteMultipartUpload *BucketLifecycleAbortIncompleteMultipartUpload `xml:"AbortIncompleteMultipartUpload,omitempty" header:"-"`
NoncurrentVersionTransition []BucketLifecycleNoncurrentVersion `xml:"NoncurrentVersionTransition,omitempty" header:"-"`
NoncurrentVersionExpiration *BucketLifecycleNoncurrentVersion `xml:"NoncurrentVersionExpiration,omitempty" header:"-"`
}
// BucketGetLifecycleResult is the result of BucketGetLifecycle
type BucketGetLifecycleResult struct {
XMLName xml.Name `xml:"LifecycleConfiguration" header:"-"`
Rules []BucketLifecycleRule `xml:"Rule,omitempty" header:"-"`
}
type BucketGetLifecycleOptions struct {
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
}
// GetLifecycle 请求实现读取生命周期管理的配置。当配置不存在时,返回404 Not Found。
// https://www.qcloud.com/document/product/436/8278
func (s *BucketService) GetLifecycle(ctx context.Context, opt ...*BucketGetLifecycleOptions) (*BucketGetLifecycleResult, *Response, error) {
var optHeader *BucketGetLifecycleOptions
if len(opt) > 0 {
optHeader = opt[0]
}
var res BucketGetLifecycleResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?lifecycle",
method: http.MethodGet,
optHeader: optHeader,
result: &res,
}
resp, err := s.client.doRetry(ctx, &sendOpt)
return &res, resp, err
}
// BucketPutLifecycleOptions is the option of PutBucketLifecycle
type BucketPutLifecycleOptions struct {
XMLName xml.Name `xml:"LifecycleConfiguration" header:"-"`
Rules []BucketLifecycleRule `xml:"Rule,omitempty" header:"-"`
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
}
// PutLifecycle 请求实现设置生命周期管理的功能。您可以通过该请求实现数据的生命周期管理配置和定期删除。
// 此请求为覆盖操作,上传新的配置文件将覆盖之前的配置文件。生命周期管理对文件和文件夹同时生效。
// https://www.qcloud.com/document/product/436/8280
func (s *BucketService) PutLifecycle(ctx context.Context, opt *BucketPutLifecycleOptions) (*Response, error) {
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?lifecycle",
method: http.MethodPut,
optHeader: opt,
body: opt,
}
resp, err := s.client.doRetry(ctx, &sendOpt)
return resp, err
}
type BucketDeleteLifecycleOptions struct {
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
}
// DeleteLifecycle 请求实现删除生命周期管理。
// https://www.qcloud.com/document/product/436/8284
func (s *BucketService) DeleteLifecycle(ctx context.Context, opt ...*BucketDeleteLifecycleOptions) (*Response, error) {
var optHeader *BucketDeleteLifecycleOptions
if len(opt) > 0 {
optHeader = opt[0]
}
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?lifecycle",
optHeader: optHeader,
method: http.MethodDelete,
}
resp, err := s.client.doRetry(ctx, &sendOpt)
return resp, err
}