-
Notifications
You must be signed in to change notification settings - Fork 351
/
secrettest.go
52 lines (41 loc) · 981 Bytes
/
secrettest.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
package secrettest
import (
"time"
"github.com/zalando/skipper/secrets"
)
type TestRegistry struct {
encrypterMap map[string]secrets.Encryption
}
var tr *TestRegistry
// NewTestRegistry returns a singleton TestRegistry
func NewTestRegistry() *TestRegistry {
if tr != nil {
return tr
}
e := make(map[string]secrets.Encryption)
return &TestRegistry{
encrypterMap: e,
}
}
func (tr *TestRegistry) GetEncrypter(refreshInterval time.Duration, s string) (secrets.Encryption, error) {
if e, ok := tr.encrypterMap[s]; ok {
return e, nil
}
testEnc, err := secrets.WithSource(&TestingSecretSource{secretKey: s})
if err != nil {
return nil, err
}
if err := testEnc.RefreshCiphers(); err != nil {
return nil, err
}
tr.encrypterMap[s] = testEnc
return testEnc, nil
}
type TestingSecretSource struct {
getCount int
secretKey string
}
func (s *TestingSecretSource) GetSecret() ([][]byte, error) {
s.getCount++
return [][]byte{[]byte(s.secretKey)}, nil
}