/
get.go
46 lines (37 loc) · 1.13 KB
/
get.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 secrets
import (
"context"
"github.com/influxdata/flux"
"github.com/influxdata/flux/codes"
"github.com/influxdata/flux/internal/errors"
"github.com/influxdata/flux/interpreter"
"github.com/influxdata/flux/runtime"
"github.com/influxdata/flux/values"
)
const GetKind = "get"
func init() {
runtime.RegisterPackageValue("influxdata/influxdb/secrets", GetKind, GetFunc)
}
// GetFunc is a function that calls Get.
var GetFunc = makeGetFunc()
func makeGetFunc() values.Function {
sig := runtime.MustLookupBuiltinType("influxdata/influxdb/secrets", "get")
return values.NewFunction("get", sig, Get, false)
}
// Get retrieves the secret key identifier for a given secret.
func Get(ctx context.Context, args values.Object) (values.Value, error) {
fargs := interpreter.NewArguments(args)
key, err := fargs.GetRequiredString("key")
if err != nil {
return nil, err
}
ss, err := flux.GetDependencies(ctx).SecretService()
if err != nil {
return nil, errors.Wrapf(err, codes.Inherit, "cannot retrieve secret %q", key)
}
value, err := ss.LoadSecret(ctx, key)
if err != nil {
return nil, err
}
return values.NewString(value), nil
}