-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.go
47 lines (40 loc) · 982 Bytes
/
store.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
package awsutils
import (
"errors"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/aws/aws-sdk-go/service/ssm/ssmiface"
)
type Store struct {
ssmClient ssmiface.SSMAPI
}
func NewStore(client ssmiface.SSMAPI) Store {
return Store{ssmClient: client}
}
func (s *Store) GetParameter(keyname string) (*string, error) {
if s.ssmClient == nil {
return nil, errors.New(messageClientNotDefined)
}
withDecryption := true
input := &ssm.GetParameterInput{
Name: &keyname,
WithDecryption: &withDecryption,
}
param, err := s.ssmClient.GetParameter(input)
if err != nil {
return nil, err
}
return param.Parameter.Value, nil
}
func (s *Store) PutParameter(keyname, value string) error {
if s == nil {
return nil
}
input := &ssm.PutParameterInput{
Name: aws.String(keyname),
Value: aws.String(value),
Type: aws.String(ssm.ParameterTypeSecureString),
}
_, err := s.ssmClient.PutParameter(input)
return err
}