forked from hairyhenderson/gomplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasource_awssmp.go
55 lines (42 loc) · 1.19 KB
/
datasource_awssmp.go
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
package data
import (
"errors"
"path"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ssm"
gaws "github.com/hairyhenderson/gomplate/aws"
)
func parseAWSSMPArgs(origPath string, args ...string) (paramPath string, err error) {
paramPath = origPath
if len(args) >= 1 {
paramPath = path.Join(paramPath, args[0])
}
if len(args) >= 2 {
err = errors.New("Maximum two arguments to aws+smp datasource: alias, extraPath")
}
return
}
func readAWSSMP(source *Source, args ...string) (output []byte, err error) {
if source.ASMPG == nil {
source.ASMPG = ssm.New(gaws.SDKSession())
}
paramPath, err := parseAWSSMPArgs(source.URL.Path, args...)
source.Type = json_mimetype
output, err = readAWSSMPParam(source, paramPath)
return
}
func readAWSSMPParam(source *Source, paramPath string) ([]byte, error) {
input := &ssm.GetParameterInput{
Name: aws.String(paramPath),
WithDecryption: aws.Bool(true),
}
response, err := source.ASMPG.GetParameter(input)
if err != nil {
logFatalf("Error reading aws+smp from AWS using GetParameter with input %v:\n%v",
input, err)
return nil, err
}
result := *response.Parameter
output := ToJSON(result)
return []byte(output), nil
}