1
|
|
|
package s3 |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"time" |
6
|
|
|
|
7
|
|
|
SDK "github.com/aws/aws-sdk-go-v2/service/s3" |
8
|
|
|
|
9
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors" |
10
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers" |
11
|
|
|
) |
12
|
|
|
|
13
|
|
|
// PutObjectRetention executes `PutObjectRetention` operation. |
14
|
|
|
func (svc *S3) PutObjectRetention(ctx context.Context, r PutObjectRetentionRequest) (*PutObjectRetentionResult, error) { |
15
|
|
|
out, err := svc.RawPutObjectRetention(ctx, r.ToInput()) |
16
|
|
|
if err != nil { |
17
|
|
|
err = svc.errWrap(errors.ErrorData{ |
18
|
|
|
Err: err, |
19
|
|
|
AWSOperation: "PutObjectRetention", |
20
|
|
|
}) |
21
|
|
|
svc.Errorf(err.Error()) |
|
|
|
|
22
|
|
|
return nil, err |
23
|
|
|
} |
24
|
|
|
return NewPutObjectRetentionResult(out), nil |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
// PutObjectRetentionRequest has parameters for `PutObjectRetention` operation. |
28
|
|
|
type PutObjectRetentionRequest struct { |
29
|
|
|
Bucket string |
30
|
|
|
Key string |
31
|
|
|
|
32
|
|
|
// optional |
33
|
|
|
BypassGovernanceRetention bool |
34
|
|
|
RequestPayer RequestPayer |
35
|
|
|
VersionID string |
36
|
|
|
|
37
|
|
|
ObjectLockRetentionMode ObjectLockRetentionMode |
38
|
|
|
ObjectLockRetainUntilDate time.Time |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
func (r PutObjectRetentionRequest) ToInput() *SDK.PutObjectRetentionInput { |
|
|
|
|
42
|
|
|
in := &SDK.PutObjectRetentionInput{} |
43
|
|
|
if r.Bucket != "" { |
44
|
|
|
in.Bucket = pointers.String(r.Bucket) |
45
|
|
|
} |
46
|
|
|
if r.Key != "" { |
47
|
|
|
in.Key = pointers.String(r.Key) |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if r.BypassGovernanceRetention { |
51
|
|
|
in.BypassGovernanceRetention = pointers.Bool(r.BypassGovernanceRetention) |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
in.RequestPayer = SDK.RequestPayer(r.RequestPayer) |
55
|
|
|
|
56
|
|
|
if r.VersionID != "" { |
57
|
|
|
in.VersionId = pointers.String(r.VersionID) |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
switch { |
61
|
|
|
case r.ObjectLockRetentionMode != "", |
62
|
|
|
!r.ObjectLockRetainUntilDate.IsZero(): |
63
|
|
|
v := &SDK.ObjectLockRetention{} |
64
|
|
|
if !r.ObjectLockRetainUntilDate.IsZero() { |
65
|
|
|
v.RetainUntilDate = &r.ObjectLockRetainUntilDate |
66
|
|
|
} |
67
|
|
|
v.Mode = SDK.ObjectLockRetentionMode(r.ObjectLockRetentionMode) |
68
|
|
|
in.Retention = v |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return in |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// PutObjectRetentionResult contains results from `PutObjectRetention` operation. |
75
|
|
|
type PutObjectRetentionResult struct { |
76
|
|
|
RequestCharged RequestCharged |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
func NewPutObjectRetentionResult(output *SDK.PutObjectRetentionResponse) *PutObjectRetentionResult { |
|
|
|
|
80
|
|
|
r := &PutObjectRetentionResult{} |
81
|
|
|
if output == nil { |
82
|
|
|
return r |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if output.RequestCharged != "" { |
86
|
|
|
r.RequestCharged = RequestCharged(output.RequestCharged) |
87
|
|
|
} |
88
|
|
|
return r |
89
|
|
|
} |
90
|
|
|
|