-
Notifications
You must be signed in to change notification settings - Fork 0
/
parameters.go
105 lines (83 loc) · 2.19 KB
/
parameters.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
97
98
99
100
101
102
103
104
105
package secretlamb
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"github.com/hashicorp/go-retryablehttp"
)
type Parameters struct {
*client
}
type ParameterOutputParameter struct {
Name string `json:"Name"`
Type string `json:"Type"`
Value string `json:"Value"`
Version int64 `json:"Version"`
LastModifiedDate string `json:"LastModifiedDate"`
Arn string `json:"ARN"`
DataType string `json:"DataType"`
}
type ParameterOutput struct {
Parameter ParameterOutputParameter `json:"Parameter"`
}
type ParameterOption struct {
Key string
Value string
}
func ParameterVersion(version int) *ParameterOption {
return &ParameterOption{
Key: "version",
Value: strconv.Itoa(version),
}
}
func ParameterLabel(label string) *ParameterOption {
return &ParameterOption{
Key: "label",
Value: label,
}
}
func ParameterWithDecryption() *ParameterOption {
return &ParameterOption{
Key: "withDecryption",
Value: "true",
}
}
func NewParameters() (*Parameters, error) {
client, err := newClient("/systemsmanager/parameters/get/")
return &Parameters{client: client}, err
}
func MustNewParameters() *Parameters {
client, err := NewParameters()
if err != nil {
panic("MustNewParameters(): " + err.Error())
}
return client
}
func (p *Parameters) WithRetry(retryMax int) *Parameters {
retryClient := retryablehttp.NewClient()
retryClient.RetryMax = retryMax
retryClient.CheckRetry = retryPolicy
p.client.HTTPClient = retryClient.StandardClient()
return p
}
func (p *Parameters) Get(name string, options ...*ParameterOption) (*ParameterOutput, error) {
query := &url.Values{}
query.Add("name", name)
for _, opt := range options {
query.Add(opt.Key, opt.Value)
}
body, err := p.client.get(query)
if err != nil {
return nil, fmt.Errorf("failed to get parameter - http request error: %w", err)
}
output := &ParameterOutput{}
err = json.Unmarshal(body, output)
if err != nil {
return nil, fmt.Errorf("failed to get parameter - json unmarshal error: %w", err)
}
return output, nil
}
func (p *Parameters) GetWithDecryption(name string) (*ParameterOutput, error) {
return p.Get(name, ParameterWithDecryption())
}