-
Notifications
You must be signed in to change notification settings - Fork 1
/
vault.go
46 lines (36 loc) · 970 Bytes
/
vault.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
package vault
import (
"context"
"github.com/alexfalkowski/konfig/server/config/provider/vault/trace/opentracing"
"github.com/hashicorp/vault/api"
)
// Transformer for vault.
type Transformer struct {
client *api.Client
tracer opentracing.Tracer
}
// NewTransformer for vault.
func NewTransformer(client *api.Client, tracer opentracing.Tracer) *Transformer {
return &Transformer{client: client, tracer: tracer}
}
// Transform for vault.
func (t *Transformer) Transform(ctx context.Context, value string) (any, error) {
ctx, span := opentracing.StartSpanFromContext(ctx, t.tracer, "transform", value)
defer span.Finish()
sec, err := t.client.Logical().ReadWithContext(ctx, value)
if err != nil {
return value, err
}
if sec == nil || sec.Data == nil {
return value, nil
}
d := sec.Data["data"]
if d == nil {
return value, nil
}
md, ok := d.(map[string]any)
if !ok || md["value"] == nil {
return value, nil
}
return md["value"], nil
}