forked from lukasjarosch/skipper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
48 lines (38 loc) · 1.04 KB
/
driver.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 skipper
import (
"fmt"
"strings"
driver "github.com/lukasjarosch/skipper/internal/secret"
)
type SecretDriver interface {
Type() string
Encrypt(data string) (string, error)
Decrypt(encrypted string) (string, error)
}
type ConfigurableSecretDriver interface {
SecretDriver
Configure(config map[string]interface{}) error
}
var driverCache = map[string]SecretDriver{}
func SecretDriverFactory(name string) (secretDriver SecretDriver, err error) {
name = strings.ToLower(name)
// return a cached version of the driver if there is one
if secretDriver, cached := driverCache[name]; cached {
return secretDriver, nil
}
// create new driver and cache it
switch name {
case "plain":
secretDriver, err = driver.NewPlain()
case "base64":
secretDriver, err = driver.NewBase64()
case "aes":
secretDriver, err = driver.NewAes()
case "azurekv":
secretDriver, err = driver.NewAzure()
default:
return nil, fmt.Errorf("driver '%s' cannot be loaded: not implemented", name)
}
driverCache[name] = secretDriver
return secretDriver, nil
}