forked from 99designs/aws-vault
/
keyring.go
51 lines (40 loc) · 1.02 KB
/
keyring.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
package keyring
import "errors"
const (
SecretServiceBackend string = "secret-service"
KeychainBackend string = "keychain"
KWalletBackend string = "kwallet"
FileBackend string = "file"
)
var DefaultBackend = FileBackend
var supportedBackends = map[string]opener{}
func SupportedBackends() []string {
b := []string{}
for k := range supportedBackends {
b = append(b, k)
}
return b
}
type opener func(name string) (Keyring, error)
func Open(name string, backend string) (Keyring, error) {
op, ok := supportedBackends[backend]
if !ok {
return nil, ErrNoAvailImpl
}
return op(name)
}
type Item struct {
Key string
Data []byte
Label string
Description string
TrustSelf bool
}
type Keyring interface {
Get(key string) (Item, error)
Set(item Item) error
Remove(key string) error
Keys() ([]string, error)
}
var ErrNoAvailImpl = errors.New("Specified keyring backend not available")
var ErrKeyNotFound = errors.New("The specified item could not be found in the keyring.")