-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssm.go
56 lines (44 loc) · 1.16 KB
/
ssm.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
package ssm
import (
"context"
"encoding/json"
"errors"
"github.com/alexfalkowski/konfig/provider/ssm/trace/opentracing"
"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/aws/aws-sdk-go-v2/service/ssm/types"
)
// Secret from SSM.
type Secret struct {
Data map[string]any `json:"data"`
}
// Transformer for SSM.
type Transformer struct {
client *ssm.Client
tracer opentracing.Tracer
}
// NewTransformer for SSM.
func NewTransformer(client *ssm.Client, tracer opentracing.Tracer) *Transformer {
return &Transformer{client: client, tracer: tracer}
}
// Transform for SSM.
func (t *Transformer) Transform(ctx context.Context, value string) (any, error) {
ctx, span := opentracing.StartSpanFromContext(ctx, t.tracer, "transform", value)
defer span.Finish()
out, err := t.client.GetParameter(ctx, &ssm.GetParameterInput{Name: &value})
if err != nil {
var perr *types.ParameterNotFound
if errors.As(err, &perr) {
return value, nil
}
return value, err
}
var sec Secret
if err := json.Unmarshal([]byte(*out.Parameter.Value), &sec); err != nil {
return value, err
}
v := sec.Data["value"]
if v == nil {
return value, nil
}
return v, nil
}