-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathioAwsSSM.go
96 lines (85 loc) · 2.56 KB
/
ioAwsSSM.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package iohandler
import (
"context"
"fmt"
"log"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/aws/aws-sdk-go-v2/service/ssm/types"
)
type IOAwsSSM struct{}
/* ***************************************************************
* Write a parameter into the parameter store.
*************************************************************** */
func (c *IOAwsSSM) Write(path string, object []byte, tags []types.Tag) error {
var ss string = string(object)
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
log.Fatalf("unable to load SDK config, %v", err)
return err
}
client := ssm.NewFromConfig(cfg)
client.PutParameter(context.Background(), &ssm.PutParameterInput{
Name: &path,
Value: &ss,
Tags: tags,
})
return nil
}
/* ***************************************************************
* Read a parameter from the Parameter Store
*************************************************************** */
func (c *IOAwsSSM) Read(path string) ([]byte, error) {
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
log.Fatalf("unable to load SDK config, %v", err)
return nil, err
}
client := ssm.NewFromConfig(cfg)
param, err := client.GetParameter(context.Background(), &ssm.GetParameterInput{
Name: &path,
WithDecryption: true,
})
if err != nil {
fmt.Println(err)
}
return []byte(*param.Parameter.Value), nil
}
/* ***************************************************************
* List all the parameters from the parameter store with the
* past "path"
*************************************************************** */
func (c *IOAwsSSM) List(path string) ([]string, error) {
cfg, err := config.LoadDefaultConfig(context.TODO())
var output []string
if err != nil {
log.Fatalf("unable to load SDK config, %v", err)
return nil, err
}
client := ssm.NewFromConfig(cfg)
params, err := client.DescribeParameters(context.Background(), &ssm.DescribeParametersInput{
ParameterFilters: []types.ParameterStringFilter{
{
Key: aws.String("Path"),
Values: []string{path},
},
},
})
for _, v := range params.Parameters {
output = append(output, *v.Name)
}
return output, err
}
/* ***************************************************************
* Count the parameters in the Parameter Store in
* the path "path"
*************************************************************** */
func (c *IOAwsSSM) Count(path string) (int, error) {
p, err := c.List(path)
if err != nil {
fmt.Println(err)
return 0, err
}
return len(p), err
}