-
Notifications
You must be signed in to change notification settings - Fork 1
/
provider.go
55 lines (44 loc) · 1.02 KB
/
provider.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 provider
import (
"context"
"strings"
"github.com/alexfalkowski/konfig/provider/env"
"github.com/alexfalkowski/konfig/provider/ssm"
"github.com/alexfalkowski/konfig/provider/vault"
)
type transformer interface {
Transform(ctx context.Context, value string) (any, error)
IsMissing(err error) bool
}
type transformers map[string]transformer
// Transformer for provider.
type Transformer struct {
ts transformers
}
// NewTransformer for provider.
func NewTransformer(et *env.Transformer, vt *vault.Transformer, st *ssm.Transformer) *Transformer {
ts := transformers{
"env": et,
"vault": vt,
"ssm": st,
}
return &Transformer{ts: ts}
}
// Transform for provider.
func (t *Transformer) Transform(ctx context.Context, value string) (any, error) {
args := strings.Split(value, ":")
if len(args) != 2 {
return value, nil
}
tr, ok := t.ts[args[0]]
if !ok {
return value, nil
}
a, err := tr.Transform(ctx, args[1])
if err != nil {
if tr.IsMissing(err) {
return value, nil
}
}
return a, err
}