Passed
Pull Request — master (#11)
by eval
01:29
created

kms/client_op_scheduled_key_deletion.go   A

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 38
dl 0
loc 63
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A kms.NewScheduleKeyDeletionResult 0 13 4
A kms.ScheduleKeyDeletionRequest.ToInput 0 9 3
A kms.*KMS.ScheduleKeyDeletion 0 11 2
1
package kms
2
3
import (
4
	"context"
5
	"time"
6
7
	SDK "github.com/aws/aws-sdk-go-v2/service/kms"
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
// ScheduleKeyDeletion executes `ScheduleKeyDeletion` operation.
14
func (svc *KMS) ScheduleKeyDeletion(ctx context.Context, r ScheduleKeyDeletionRequest) (*ScheduleKeyDeletionResult, error) {
15
	out, err := svc.RawScheduleKeyDeletion(ctx, r.ToInput())
16
	if err != nil {
17
		err = svc.errWrap(errors.ErrorData{
18
			Err:          err,
19
			AWSOperation: "ScheduleKeyDeletion",
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 NewScheduleKeyDeletionResult(out), nil
25
}
26
27
// ScheduleKeyDeletionRequest has parameters for `ScheduleKeyDeletion` operation.
28
type ScheduleKeyDeletionRequest struct {
29
	KeyID string
30
31
	// optional
32
	PendingWindowInDays int64 // must be [7 ~ 30] days
33
}
34
35
func (r ScheduleKeyDeletionRequest) ToInput() *SDK.ScheduleKeyDeletionInput {
0 ignored issues
show
introduced by
exported method ScheduleKeyDeletionRequest.ToInput should have comment or be unexported
Loading history...
36
	in := &SDK.ScheduleKeyDeletionInput{}
37
	if r.KeyID != "" {
38
		in.KeyId = pointers.String(r.KeyID)
39
	}
40
	if r.PendingWindowInDays != 0 {
41
		in.PendingWindowInDays = pointers.Long64(r.PendingWindowInDays)
42
	}
43
	return in
44
}
45
46
type ScheduleKeyDeletionResult struct {
0 ignored issues
show
introduced by
exported type ScheduleKeyDeletionResult should have comment or be unexported
Loading history...
47
	DeletionDate time.Time
48
	KeyID        string
49
}
50
51
func NewScheduleKeyDeletionResult(output *SDK.ScheduleKeyDeletionResponse) *ScheduleKeyDeletionResult {
0 ignored issues
show
introduced by
exported function NewScheduleKeyDeletionResult should have comment or be unexported
Loading history...
52
	r := &ScheduleKeyDeletionResult{}
53
	if output == nil {
54
		return r
55
	}
56
57
	if output.DeletionDate != nil {
58
		r.DeletionDate = *output.DeletionDate
59
	}
60
	if output.KeyId != nil {
61
		r.KeyID = *output.KeyId
62
	}
63
	return r
64
}
65