-
Notifications
You must be signed in to change notification settings - Fork 634
/
akstore.go
58 lines (51 loc) · 1.16 KB
/
akstore.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
package keystore
import (
"encoding/json"
"fmt"
"regexp"
"github.com/chubaofs/chubaofs/util/caps"
)
type AccessKeyInfo struct {
AccessKey string `json:"access_key"`
ID string `json:"id"`
}
type AccessKeyCaps struct {
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`
Caps []byte `json:"caps"`
ID string `json:"user_id"`
}
func (u *AccessKeyCaps) IsValidCaps() (err error) {
cap := new(caps.Caps)
if err = cap.Init(u.Caps); err != nil {
err = fmt.Errorf("Invalid caps [%s] %s", u.Caps, err.Error())
}
return
}
func (u *AccessKeyCaps) IsValidAK() (err error) {
re := regexp.MustCompile("^[A-Za-z0-9]{16}$")
if !re.MatchString(u.AccessKey) {
err = fmt.Errorf("invalid AccessKey [%s]", u.AccessKey)
return
}
return
}
func (u *AccessKeyCaps) DumpJSONStr() (r string, err error) {
dumpInfo := struct {
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`
Caps string `json:"caps"`
ID string `json:"id"`
}{
u.AccessKey,
u.SecretKey,
string(u.Caps),
u.ID,
}
data, err := json.MarshalIndent(dumpInfo, "", " ")
if err != nil {
return
}
r = string(data)
return
}