forked from reddit/baseplate.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
48 lines (40 loc) · 1.16 KB
/
config.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
package secrets
import (
"context"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/reddit/baseplate.go/internal/prometheusbpint"
"github.com/reddit/baseplate.go/log"
)
const (
promNamespace = "secrets"
)
var (
parserFailures = promauto.With(prometheusbpint.GlobalRegistry).NewCounter(prometheus.CounterOpts{
Namespace: promNamespace,
Name: "parser_failure_total",
Help: "Total number of secret parser failures",
})
)
// Config is the confuration struct for the secrets package.
//
// Can be deserialized from YAML.
type Config struct {
// Path is the path to the secrets.json file file to load your service's
// secrets from.
Path string `yaml:"path"`
}
// InitFromConfig returns a new *secrets.Store using the given context and config.
func InitFromConfig(ctx context.Context, cfg Config) (*Store, error) {
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()
store, err := NewStore(ctx, cfg.Path, log.CounterWrapper(
nil, // delegate, let it fallback to DefaultWrapper
parserFailures,
))
if err != nil {
return nil, err
}
return store, nil
}