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

kms.NewCreateKeyResult   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
package kms
2
3
import (
4
	"context"
5
6
	SDK "github.com/aws/aws-sdk-go-v2/service/kms"
7
8
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors"
9
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers"
10
)
11
12
// CreateKey executes `CreateKey` operation.
13
func (svc *KMS) CreateKey(ctx context.Context, r CreateKeyRequest) (*CreateKeyResult, error) {
14
	out, err := svc.RawCreateKey(ctx, r.ToInput())
15
	if err != nil {
16
		err = svc.errWrap(errors.ErrorData{
17
			Err:          err,
18
			AWSOperation: "CreateKey",
19
		})
20
		svc.Errorf(err.Error())
0 ignored issues
show
introduced by
can't check non-constant format in call to Errorf
Loading history...
21
		return nil, err
22
	}
23
	return NewCreateKeyResult(out), nil
24
}
25
26
// CreateKeyRequest has parameters for `CreateKey` operation.
27
type CreateKeyRequest struct {
28
	BypassPolicyLockoutSafetyCheck bool
29
	CustomKeyStoreID               string
30
	CustomerMasterKeySpec          CustomerMasterKeySpec
31
	Description                    string
32
	KeyUsage                       KeyUsageType
33
	Origin                         OriginType
34
	Policy                         string
35
	Tags                           []Tag
36
}
37
38
func (r CreateKeyRequest) ToInput() *SDK.CreateKeyInput {
0 ignored issues
show
introduced by
exported method CreateKeyRequest.ToInput should have comment or be unexported
Loading history...
39
	in := &SDK.CreateKeyInput{}
40
	if r.BypassPolicyLockoutSafetyCheck {
41
		in.BypassPolicyLockoutSafetyCheck = pointers.Bool(r.BypassPolicyLockoutSafetyCheck)
42
	}
43
	if r.CustomKeyStoreID != "" {
44
		in.CustomKeyStoreId = pointers.String(r.CustomKeyStoreID)
45
	}
46
47
	in.CustomerMasterKeySpec = SDK.CustomerMasterKeySpec(r.CustomerMasterKeySpec)
48
49
	if r.Description != "" {
50
		in.Description = pointers.String(r.Description)
51
	}
52
53
	in.KeyUsage = SDK.KeyUsageType(r.KeyUsage)
54
	in.Origin = SDK.OriginType(r.Origin)
55
56
	if r.Policy != "" {
57
		in.Policy = pointers.String(r.Policy)
58
	}
59
60
	if len(r.Tags) != 0 {
61
		list := make([]SDK.Tag, len(r.Tags))
62
		for i, v := range r.Tags {
63
			list[i] = v.ToSDK()
64
		}
65
		in.Tags = list
66
	}
67
	return in
68
}
69
70
type CreateKeyResult struct {
0 ignored issues
show
introduced by
exported type CreateKeyResult should have comment or be unexported
Loading history...
71
	KeyMetadata KeyMetadata
72
}
73
74
func NewCreateKeyResult(output *SDK.CreateKeyResponse) *CreateKeyResult {
0 ignored issues
show
introduced by
exported function NewCreateKeyResult should have comment or be unexported
Loading history...
75
	r := &CreateKeyResult{}
76
	if output == nil {
77
		return r
78
	}
79
80
	r.KeyMetadata = newKeyMetadata(output.KeyMetadata)
81
	return r
82
}
83