forked from ehazlett/libsecret
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libsecret.go
42 lines (32 loc) · 1017 Bytes
/
libsecret.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
package libsecret
import (
"fmt"
"sort"
"strings"
"github.com/ehazlett/libsecret/store"
)
// Initialize creates a new Store object, initializing the client
type Initialize func(addr string, options *store.Config) (store.SecretStore, error)
var (
// Backend initializers
initializers = make(map[store.Backend]Initialize)
)
func supportedBackends() string {
keys := make([]string, 0, len(initializers))
for k := range initializers {
keys = append(keys, string(k))
}
sort.Strings(keys)
return strings.Join(keys, ", ")
}
// NewSecretStore creates a an instance of store
func NewSecretStore(backend store.Backend, addr string, options *store.Config) (store.SecretStore, error) {
if init, exists := initializers[backend]; exists {
return init(addr, options)
}
return nil, fmt.Errorf("%s %s", store.ErrBackendNotSupported.Error(), supportedBackends())
}
// AddSecretStore adds a new store backend to libkv
func AddSecretStore(store store.Backend, init Initialize) {
initializers[store] = init
}