-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
78 lines (66 loc) · 1.78 KB
/
options.go
File metadata and controls
78 lines (66 loc) · 1.78 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package vault
import (
"context"
log "github.com/xraph/go-utils/log"
)
// Option configures a Vault instance.
type Option func(*Vault)
// WithAppID sets the application identifier used for scoping.
func WithAppID(appID string) Option {
return func(v *Vault) {
v.config.AppID = appID
}
}
// WithEncryptionKey sets the master encryption key (32 bytes for AES-256-GCM).
func WithEncryptionKey(key []byte) Option {
return func(v *Vault) {
v.config.EncryptionKey = key
}
}
// WithEncryptionKeyEnv sets the environment variable name for the encryption key.
func WithEncryptionKeyEnv(envVar string) Option {
return func(v *Vault) {
v.config.EncryptionKeyEnv = envVar
}
}
// WithLogger sets the structured logger.
func WithLogger(l log.Logger) Option {
return func(v *Vault) {
v.logger = l
}
}
// WithConfig sets the vault configuration directly.
func WithConfig(cfg Config) Option {
return func(v *Vault) {
v.config = cfg
}
}
// Storer is the interface that store backends must implement.
// It is defined here to avoid import cycles — the store package
// composes subsystem store interfaces into a concrete type.
type Storer interface {
Ping(ctx interface{ Deadline() (interface{}, bool) }) error
Close() error
}
// Vault is the central type. It is defined here as a forward declaration
// so that options can reference it. The full implementation is in vault.go
// (created in a later phase).
type Vault struct {
config Config
logger log.Logger
}
// Health checks the health of the Vault.
func (v *Vault) Health(_ context.Context) error {
return nil
}
// NewVault creates a new Vault instance with the given options.
func NewVault(opts ...Option) *Vault {
v := &Vault{
config: DefaultConfig(),
logger: log.NewNoopLogger(),
}
for _, opt := range opts {
opt(v)
}
return v
}