Passed
Push — master ( 067f16...6918f7 )
by eval
01:50
created

s3.PutObjectRetentionRequest.ToInput   B

Complexity

Conditions 7

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 20
nop 0
dl 0
loc 31
rs 8
c 0
b 0
f 0
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())
0 ignored issues
show
introduced by
can't check non-constant format in call to Errorf
Loading history...
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 {
0 ignored issues
show
introduced by
exported method PutObjectRetentionRequest.ToInput should have comment or be unexported
Loading history...
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 {
0 ignored issues
show
introduced by
exported function NewPutObjectRetentionResult should have comment or be unexported
Loading history...
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