-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
secret_store_mem.go
49 lines (41 loc) · 1.31 KB
/
secret_store_mem.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
package libkb
type SecretStoreMem struct {
secrets map[NormalizedUsername]LKSecFullSecret
}
var _ SecretStoreAll = (*SecretStoreMem)(nil)
func NewSecretStoreMem() *SecretStoreMem {
return &SecretStoreMem{
secrets: make(map[NormalizedUsername]LKSecFullSecret),
}
}
func (s *SecretStoreMem) RetrieveSecret(m MetaContext, username NormalizedUsername) (LKSecFullSecret, error) {
secret, ok := s.secrets[username]
if !ok {
return LKSecFullSecret{}, NewErrSecretForUserNotFound(username)
}
return secret, nil
}
func (s *SecretStoreMem) StoreSecret(m MetaContext, username NormalizedUsername, secret LKSecFullSecret) error {
s.secrets[username] = secret
return nil
}
func (s *SecretStoreMem) ClearSecret(m MetaContext, username NormalizedUsername) error {
if username.IsNil() {
m.Debug("NOOPing SecretStoreMem#ClearSecret for empty username")
return nil
}
delete(s.secrets, username)
return nil
}
func (s *SecretStoreMem) GetUsersWithStoredSecrets(m MetaContext) ([]string, error) {
var usernames []string
for k := range s.secrets {
uname := k.String()
if !isPPSSecretStore(uname) {
usernames = append(usernames, uname)
}
}
return usernames, nil
}
func (s *SecretStoreMem) GetOptions(MetaContext) *SecretStoreOptions { return nil }
func (s *SecretStoreMem) SetOptions(MetaContext, *SecretStoreOptions) {}