/
opts.go
63 lines (48 loc) · 1.49 KB
/
opts.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
56
57
58
59
60
61
62
63
// SPDX-License-Identifier: Apache-2.0
package secret
import (
"context"
"github.com/sirupsen/logrus"
"gorm.io/gorm"
)
// EngineOpt represents a configuration option to initialize the database engine for Secrets.
type EngineOpt func(*engine) error
// WithClient sets the gorm.io/gorm client in the database engine for Secrets.
func WithClient(client *gorm.DB) EngineOpt {
return func(e *engine) error {
// set the gorm.io/gorm client in the secret engine
e.client = client
return nil
}
}
// WithEncryptionKey sets the encryption key in the database engine for Secrets.
func WithEncryptionKey(key string) EngineOpt {
return func(e *engine) error {
// set the encryption key in the secret engine
e.config.EncryptionKey = key
return nil
}
}
// WithLogger sets the github.com/sirupsen/logrus logger in the database engine for Secrets.
func WithLogger(logger *logrus.Entry) EngineOpt {
return func(e *engine) error {
// set the github.com/sirupsen/logrus logger in the secret engine
e.logger = logger
return nil
}
}
// WithSkipCreation sets the skip creation logic in the database engine for Secrets.
func WithSkipCreation(skipCreation bool) EngineOpt {
return func(e *engine) error {
// set to skip creating tables and indexes in the secret engine
e.config.SkipCreation = skipCreation
return nil
}
}
// WithContext sets the context in the database engine for Secrets.
func WithContext(ctx context.Context) EngineOpt {
return func(e *engine) error {
e.ctx = ctx
return nil
}
}