|
1
|
|
|
package ssm |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"context" |
|
5
|
|
|
"strings" |
|
6
|
|
|
) |
|
7
|
|
|
|
|
8
|
|
|
// XGetParameterValue fetches a parameter value from SSM. |
|
9
|
|
|
func (svc *SSM) XGetParameterValue(ctx context.Context, name string) (value string, notFound bool, err error) { |
|
10
|
|
|
return svc.xGetParameterValue(ctx, name, false) |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
// XGetParameterValueWithDecryption fetches a decrypted value. |
|
14
|
|
|
func (svc *SSM) XGetParameterValueWithDecryption(ctx context.Context, name string) (value string, notFound bool, err error) { |
|
15
|
|
|
return svc.xGetParameterValue(ctx, name, true) |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
func (svc *SSM) xGetParameterValue(ctx context.Context, name string, decryption bool) (value string, notFound bool, err error) { |
|
19
|
|
|
result, err := svc.GetParameter(ctx, GetParameterRequest{ |
|
20
|
|
|
Name: name, |
|
21
|
|
|
WithDecryption: decryption, |
|
22
|
|
|
}) |
|
23
|
|
|
if err != nil { |
|
24
|
|
|
return "", false, err |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
return result.Value, result.NotFound, nil |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
// XGetParameterValueList fetches parameter value list from SSM. |
|
31
|
|
|
func (svc *SSM) XGetParameterValueList(ctx context.Context, list []string) (values map[string]string, err error) { |
|
32
|
|
|
return svc.xGetParameterValueList(ctx, list, false) |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// XGetParameterValueListWithDecryption fetches decrypted value list. |
|
36
|
|
|
func (svc *SSM) XGetParameterValueListWithDecryption(ctx context.Context, list []string) (values map[string]string, err error) { |
|
37
|
|
|
return svc.xGetParameterValueList(ctx, list, true) |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
func (svc *SSM) xGetParameterValueList(ctx context.Context, list []string, decryption bool) (values map[string]string, err error) { |
|
41
|
|
|
result, err := svc.GetParameters(ctx, GetParametersRequest{ |
|
42
|
|
|
Names: list, |
|
43
|
|
|
WithDecryption: decryption, |
|
44
|
|
|
}) |
|
45
|
|
|
m := make(map[string]string) |
|
46
|
|
|
if err != nil { |
|
47
|
|
|
return m, err |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
for _, v := range result.Parameters { |
|
51
|
|
|
m[v.Name] = v.Value |
|
52
|
|
|
} |
|
53
|
|
|
return m, nil |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
// XPutParameter puts the value to SSM parameter store. |
|
57
|
|
|
func (svc *SSM) XPutParameter(ctx context.Context, name, value string) (alreadyExists bool, err error) { |
|
58
|
|
|
result, err := svc.PutParameter(ctx, PutParameterRequest{ |
|
59
|
|
|
Name: name, |
|
60
|
|
|
Value: value, |
|
61
|
|
|
Type: ParameterTypeString, |
|
62
|
|
|
}) |
|
63
|
|
|
if err != nil { |
|
64
|
|
|
return false, err |
|
65
|
|
|
} |
|
66
|
|
|
return result.AlreadyExists, nil |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// XPutParameterList puts the value set (StringList type) to SSM parameter store. |
|
70
|
|
|
func (svc *SSM) XPutParameterList(ctx context.Context, name string, values []string) (alreadyExists bool, err error) { |
|
71
|
|
|
result, err := svc.PutParameter(ctx, PutParameterRequest{ |
|
72
|
|
|
Name: name, |
|
73
|
|
|
Value: strings.Join(values, ","), |
|
74
|
|
|
Type: ParameterTypeStringList, |
|
75
|
|
|
}) |
|
76
|
|
|
if err != nil { |
|
77
|
|
|
return false, err |
|
78
|
|
|
} |
|
79
|
|
|
return result.AlreadyExists, nil |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// XPutParameterSecrure puts the value to SSM parameter store with encryption by default AWS KMS key. |
|
83
|
|
|
func (svc *SSM) XPutParameterSecrure(ctx context.Context, name, value string) (alreadyExists bool, err error) { |
|
84
|
|
|
result, err := svc.PutParameter(ctx, PutParameterRequest{ |
|
85
|
|
|
Name: name, |
|
86
|
|
|
Value: value, |
|
87
|
|
|
Type: ParameterTypeSecureString, |
|
88
|
|
|
}) |
|
89
|
|
|
if err != nil { |
|
90
|
|
|
return false, err |
|
91
|
|
|
} |
|
92
|
|
|
return result.AlreadyExists, nil |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
// XPutParameterSecureCMK puts the value to SSM parameter store with encryption by your AWS KMS key. |
|
96
|
|
|
func (svc *SSM) XPutParameterSecureCMK(ctx context.Context, name, value, keyID string) (alreadyExists bool, err error) { |
|
97
|
|
|
result, err := svc.PutParameter(ctx, PutParameterRequest{ |
|
98
|
|
|
Name: name, |
|
99
|
|
|
Value: value, |
|
100
|
|
|
KeyID: keyID, |
|
101
|
|
|
Type: ParameterTypeSecureString, |
|
102
|
|
|
}) |
|
103
|
|
|
if err != nil { |
|
104
|
|
|
return false, err |
|
105
|
|
|
} |
|
106
|
|
|
return result.AlreadyExists, nil |
|
107
|
|
|
} |
|
108
|
|
|
|