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()) |
|
|
|
|
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 { |
|
|
|
|
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 { |
|
|
|
|
71
|
|
|
KeyMetadata KeyMetadata |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
func NewCreateKeyResult(output *SDK.CreateKeyResponse) *CreateKeyResult { |
|
|
|
|
75
|
|
|
r := &CreateKeyResult{} |
76
|
|
|
if output == nil { |
77
|
|
|
return r |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
r.KeyMetadata = newKeyMetadata(output.KeyMetadata) |
81
|
|
|
return r |
82
|
|
|
} |
83
|
|
|
|