This commit is contained in:
aozhiwei 2024-08-04 09:41:23 +08:00
parent 69123c0dfb
commit 5373eb80a7
3 changed files with 83 additions and 46 deletions

View File

@ -1,43 +1,48 @@
{
"roles": {
"admin": {
"api": [
"*"
],
"ui": [
"*"
]
},
"operator": {
"api": [
"*"
],
"ui": [
"*"
]
},
"service": {
"api": [
"*"
],
"ui": [
"*"
]
},
"guest": {
"api": [],
"ui": []
}
"api": [
],
"ui": [
],
"roles": {
"admin": {
"api": [
"*"
],
"ui": [
"*"
]
},
"accounts": {
"0x903c617e66902aa1b916DF79c7F1730fba40c2cA": {
"roles": [
"service"
],
"special": {
"api": [],
"ui": ["addannouncement", "editannouncement", "addaudit", "editaudit"]
}
}
"operator": {
"api": [
"*"
],
"ui": [
"*"
]
},
"service": {
"api": [
"*"
],
"ui": [
"*"
]
},
"guest": {
"api": [],
"ui": []
}
}
},
"accounts": {
"0x903c617e66902aa1b916DF79c7F1730fba40c2cA": {
"roles": [
"service"
],
"special": {
"api": [],
"ui": ["addannouncement", "editannouncement", "addaudit", "editaudit"]
}
}
}
}

View File

@ -6,7 +6,7 @@
"service"
],
"special": {
"api": [],
"api": ["xxx", "-xxx"],
"ui": ["addannouncement", "editannouncement", "addaudit", "editaudit"]
}
}

View File

@ -14,13 +14,36 @@ type Permission struct {
ui *q5.ConcurrentMap[string, bool]
}
type role struct {
api *q5.ConcurrentMap[string, bool]
ui *q5.ConcurrentMap[string, bool]
}
type user struct {
accountAddress string
roleHash *q5.ConcurrentMap[string, *role]
api *q5.ConcurrentMap[string, bool]
ui *q5.ConcurrentMap[string, bool]
specApi []string
specUi []string
}
type PermissionTable struct {
f5.CustomMetaTable
accountPermission *q5.ConcurrentMap[string, *Permission]
apiHash *q5.ConcurrentMap[string, bool]
uiHash *q5.ConcurrentMap[string, bool]
roleHash *q5.ConcurrentMap[string, *role]
userHash *q5.ConcurrentMap[string, *Permission]
}
func (this *PermissionTable) Load() {
this.accountPermission = new(q5.ConcurrentMap[string, *Permission])
this.apiHash = new(q5.ConcurrentMap[string, bool])
this.uiHash = new(q5.ConcurrentMap[string, bool])
this.roleHash = new(q5.ConcurrentMap[string, *role])
this.userHash = new(q5.ConcurrentMap[string, *Permission])
this.loadPermission()
this.loadRole()
this.loadUser()
{
if jsonStr, err := f5.ReadJsonFile("../config/permission.json"); err == nil {
type cfgPermission struct {
@ -77,7 +100,7 @@ func (this *PermissionTable) Load() {
accpermission.ui.Store(v, !ret)
}
this.accountPermission.Store(strings.ToLower(account), accpermission)
this.userHash.Store(strings.ToLower(account), accpermission)
}
} else {
panic(fmt.Sprintf("load metafile error %s %s", "permission.json", err))
@ -90,7 +113,7 @@ func (this *PermissionTable) CheckAPIPermission(account string, cmd string) bool
return false
}
accper, exist := this.accountPermission.Load(account)
accper, exist := this.userHash.Load(account)
if !exist {
return false
}
@ -109,7 +132,7 @@ func (this *PermissionTable) CheckAPIPermission(account string, cmd string) bool
}
func (this *PermissionTable) GetUIPermission(account string) string {
per, exist := this.accountPermission.Load(account)
per, exist := this.userHash.Load(account)
if !exist {
return "{}"
}
@ -123,3 +146,12 @@ func (this *PermissionTable) GetUIPermission(account string) string {
v, _ := json.Marshal(kvlist)
return string(v)
}
func (this *PermissionTable) loadPermission() {
}
func (this *PermissionTable) loadRole() {
}
func (this *PermissionTable) loadUser() {
}