-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathparameters.go
More file actions
57 lines (47 loc) · 1.61 KB
/
parameters.go
File metadata and controls
57 lines (47 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package bcdaaws
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/ssm"
)
// Returns the value of a single parameter from the SSM Parameter Store
func GetParameter(ctx context.Context, client *ssm.Client, keyname string) (string, error) {
withDecryption := true
result, err := client.GetParameter(ctx, &ssm.GetParameterInput{
Name: &keyname,
WithDecryption: &withDecryption,
})
if err != nil {
return "", fmt.Errorf("error retrieving parameter %s from parameter store: %w", keyname, err)
}
val := *result.Parameter.Value
if val == "" {
return "", fmt.Errorf("no parameter store value found for %s", keyname)
}
return val, nil
}
// Returns a list of parameters from the SSM Parameter Store
func GetParameters(ctx context.Context, client *ssm.Client, keynames []string) (map[string]string, error) {
withDecryption := true
output, err := client.GetParameters(ctx, &ssm.GetParametersInput{
Names: keynames,
WithDecryption: &withDecryption,
})
if err != nil {
return nil, fmt.Errorf("error connecting to parameter store: %s", err)
}
// Unknown keys will come back as invalid, make sure we error on them
if len(output.InvalidParameters) > 0 {
invalidParamsStr := ""
for i := 0; i < len(output.InvalidParameters); i++ {
invalidParamsStr += fmt.Sprintf("%s,\n", output.InvalidParameters[i])
}
return nil, fmt.Errorf("invalid parameters error: %s", invalidParamsStr)
}
// Build the parameter map that we're going to return
paramMap := make(map[string]string)
for _, item := range output.Parameters {
paramMap[*item.Name] = *item.Value
}
return paramMap, nil
}