mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-09 18:00:23 +08:00
Added conditions to normalising user
This commit is contained in:
@@ -190,15 +190,15 @@ func (acl *ACL) SetUser(ctx context.Context, cmd []string) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(str) > 4 && strings.EqualFold(str[0:4], "%RW~") {
|
if len(str) > 4 && strings.EqualFold(str[0:4], "%RW~") {
|
||||||
user.IncludedKeys = append(user.IncludedKeys, str[3:])
|
user.IncludedKeys = append(user.IncludedKeys, str[4:])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(str) > 3 && strings.EqualFold(str[0:4], "%R~") {
|
if len(str) > 3 && strings.EqualFold(str[0:3], "%R~") {
|
||||||
user.IncludedReadKeys = append(user.IncludedReadKeys, str[2:])
|
user.IncludedReadKeys = append(user.IncludedReadKeys, str[3:])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(str) > 3 && strings.EqualFold(str[0:4], "%w~") {
|
if len(str) > 3 && strings.EqualFold(str[0:3], "%W~") {
|
||||||
user.IncludedWriteKeys = append(user.IncludedWriteKeys, str[2:])
|
user.IncludedWriteKeys = append(user.IncludedWriteKeys, str[3:])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Parse channels
|
// Parse channels
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
package acl
|
package acl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kelvinmwinuka/memstore/src/utils"
|
||||||
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Username string `json:"Username" yaml:"Username"`
|
Username string `json:"Username" yaml:"Username"`
|
||||||
Enabled bool `json:"Enabled" yaml:"Enabled"`
|
Enabled bool `json:"Enabled" yaml:"Enabled"`
|
||||||
@@ -24,13 +28,37 @@ type User struct {
|
|||||||
func (user *User) Normalise() {
|
func (user *User) Normalise() {
|
||||||
user.IncludedCategories = RemoveDuplicateEntries(user.IncludedCategories, "allCategories")
|
user.IncludedCategories = RemoveDuplicateEntries(user.IncludedCategories, "allCategories")
|
||||||
user.ExcludedCategories = RemoveDuplicateEntries(user.ExcludedCategories, "allCategories")
|
user.ExcludedCategories = RemoveDuplicateEntries(user.ExcludedCategories, "allCategories")
|
||||||
|
if utils.Contains(user.ExcludedCategories, "*") {
|
||||||
|
user.IncludedCategories = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
user.IncludedCommands = RemoveDuplicateEntries(user.IncludedCommands, "allCommands")
|
user.IncludedCommands = RemoveDuplicateEntries(user.IncludedCommands, "allCommands")
|
||||||
user.ExcludedCommands = RemoveDuplicateEntries(user.ExcludedCommands, "allCommands")
|
user.ExcludedCommands = RemoveDuplicateEntries(user.ExcludedCommands, "allCommands")
|
||||||
|
if utils.Contains(user.ExcludedCommands, "*") {
|
||||||
|
user.IncludedCommands = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
user.IncludedKeys = RemoveDuplicateEntries(user.IncludedKeys, "allKeys")
|
user.IncludedKeys = RemoveDuplicateEntries(user.IncludedKeys, "allKeys")
|
||||||
|
if len(user.IncludedKeys) == 0 {
|
||||||
|
user.IncludedKeys = []string{"*"}
|
||||||
|
}
|
||||||
user.IncludedReadKeys = RemoveDuplicateEntries(user.IncludedReadKeys, "allKeys")
|
user.IncludedReadKeys = RemoveDuplicateEntries(user.IncludedReadKeys, "allKeys")
|
||||||
|
if len(user.IncludedReadKeys) == 0 {
|
||||||
|
user.IncludedReadKeys = []string{"*"}
|
||||||
|
}
|
||||||
user.IncludedWriteKeys = RemoveDuplicateEntries(user.IncludedWriteKeys, "allKeys")
|
user.IncludedWriteKeys = RemoveDuplicateEntries(user.IncludedWriteKeys, "allKeys")
|
||||||
|
if len(user.IncludedWriteKeys) == 0 {
|
||||||
|
user.IncludedWriteKeys = []string{"*"}
|
||||||
|
}
|
||||||
|
|
||||||
user.IncludedPubSubChannels = RemoveDuplicateEntries(user.IncludedPubSubChannels, "allChannels")
|
user.IncludedPubSubChannels = RemoveDuplicateEntries(user.IncludedPubSubChannels, "allChannels")
|
||||||
|
if len(user.IncludedPubSubChannels) == 0 {
|
||||||
|
user.IncludedPubSubChannels = []string{"*"}
|
||||||
|
}
|
||||||
user.ExcludedPubSubChannels = RemoveDuplicateEntries(user.ExcludedPubSubChannels, "allChannels")
|
user.ExcludedPubSubChannels = RemoveDuplicateEntries(user.ExcludedPubSubChannels, "allChannels")
|
||||||
|
if utils.Contains(user.ExcludedPubSubChannels, "*") {
|
||||||
|
user.IncludedPubSubChannels = []string{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveDuplicateEntries(entries []string, allAlias string) (res []string) {
|
func RemoveDuplicateEntries(entries []string, allAlias string) (res []string) {
|
||||||
|
Reference in New Issue
Block a user