forked from cubefs/cubefs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeystore_cache_op.go
59 lines (52 loc) · 1.35 KB
/
keystore_cache_op.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
53
54
55
56
57
58
59
package authnode
import (
"github.com/chubaofs/chubaofs/proto"
"github.com/chubaofs/chubaofs/util/keystore"
)
// PutKey change keyInfo in keystore cache
func (mf *KeystoreFsm) PutKey(k *keystore.KeyInfo) {
mf.ksMutex.Lock()
defer mf.ksMutex.Unlock()
if _, ok := (mf.keystore)[k.ID]; !ok {
(mf.keystore)[k.ID] = k
}
}
// GetKey Get keyInfo from keystore cache
func (mf *KeystoreFsm) GetKey(id string) (u *keystore.KeyInfo, err error) {
mf.ksMutex.RLock()
defer mf.ksMutex.RUnlock()
u, ok := (mf.keystore)[id]
if !ok {
err = proto.ErrKeyNotExists
}
return
}
// DeleteKey Delete keyInfo in keystore cache
func (mf *KeystoreFsm) DeleteKey(id string) {
mf.ksMutex.Lock()
defer mf.ksMutex.Unlock()
delete(mf.keystore, id)
return
}
func (mf *KeystoreFsm) PutAKInfo(akInfo *keystore.AccessKeyInfo) {
mf.aksMutex.Lock()
defer mf.aksMutex.Unlock()
if _, ok := (mf.accessKeystore)[akInfo.AccessKey]; !ok {
(mf.accessKeystore)[akInfo.AccessKey] = akInfo
}
}
func (mf *KeystoreFsm) GetAKInfo(accessKey string) (akInfo *keystore.AccessKeyInfo, err error) {
mf.aksMutex.RLock()
defer mf.aksMutex.RUnlock()
akInfo, ok := (mf.accessKeystore)[accessKey]
if !ok {
err = proto.ErrAccessKeyNotExists
}
return
}
func (mf *KeystoreFsm) DeleteAKInfo(accessKey string) {
mf.aksMutex.Lock()
defer mf.aksMutex.Unlock()
delete(mf.accessKeystore, accessKey)
return
}