-
Notifications
You must be signed in to change notification settings - Fork 91
/
bucket_object_lock.go
82 lines (71 loc) · 2.39 KB
/
bucket_object_lock.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
package cos
import (
"context"
"encoding/xml"
"net/http"
)
type ObjectLockRule struct {
Days int `xml:"DefaultRetention>Days,omitempty"`
}
type BucketPutObjectLockOptions struct {
XMLName xml.Name `xml:"ObjectLockConfiguration"`
ObjectLockEnabled string `xml:"ObjectLockEnabled,omitempty"`
Rule *ObjectLockRule `xml:"Rule,omitempty"`
}
type BucketGetObjectLockResult BucketPutObjectLockOptions
func (s *BucketService) PutObjectLockConfiguration(ctx context.Context, opt *BucketPutObjectLockOptions) (*Response, error) {
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?object-lock",
method: http.MethodPut,
body: opt,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return resp, err
}
func (s *BucketService) GetObjectLockConfiguration(ctx context.Context) (*BucketGetObjectLockResult, *Response, error) {
var res BucketGetObjectLockResult
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?object-lock",
method: http.MethodGet,
result: &res,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return &res, resp, err
}
type ObjectGetRetentionOptions struct {
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
}
type ObjectGetRetentionResult struct {
XMLName xml.Name `xml:"Retention"`
RetainUntilDate string `xml:"RetainUntilDate,omitempty"`
Mode string `xml:"Mode,omitempty"`
}
func (s *ObjectService) GetRetention(ctx context.Context, key string, opt *ObjectGetRetentionOptions) (*ObjectGetRetentionResult, *Response, error) {
var res ObjectGetRetentionResult
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/" + encodeURIComponent(key) + "?retention",
method: http.MethodGet,
optHeader: opt,
result: &res,
}
resp, err := s.client.doRetry(ctx, &sendOpt)
return &res, resp, err
}
type ObjectPutRetentionOptions struct {
XMLName xml.Name `xml:"Retention"`
RetainUntilDate string `xml:"RetainUntilDate,omitempty"`
Mode string `xml:"Mode,omitempty"`
}
func (s *ObjectService) PutRetention(ctx context.Context, key string, opt *ObjectPutRetentionOptions) (*Response, error) {
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/" + encodeURIComponent(key) + "?retention",
method: http.MethodPut,
body: opt,
}
resp, err := s.client.doRetry(ctx, &sendOpt)
return resp, err
}