mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-15 04:20:57 +08:00
Reset NoKeys when keys are added
This commit is contained in:
@@ -341,7 +341,12 @@ func (acl *ACL) AuthorizeConnection(conn *net.Conn, cmd []string, command utils.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. Check if keys are in IncludedKeys
|
// 7. Check if nokeys is true
|
||||||
|
if connection.User.NoKeys {
|
||||||
|
return errors.New("not authorised to access any keys")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8. Check if keys are in IncludedKeys
|
||||||
if len(keys) > 0 && !slices.ContainsFunc(keys, func(key string) bool {
|
if len(keys) > 0 && !slices.ContainsFunc(keys, func(key string) bool {
|
||||||
return slices.ContainsFunc(connection.User.IncludedKeys, func(includedKeyGlob string) bool {
|
return slices.ContainsFunc(connection.User.IncludedKeys, func(includedKeyGlob string) bool {
|
||||||
if acl.GlobPatterns[includedKeyGlob].Match(key) {
|
if acl.GlobPatterns[includedKeyGlob].Match(key) {
|
||||||
@@ -354,7 +359,7 @@ func (acl *ACL) AuthorizeConnection(conn *net.Conn, cmd []string, command utils.
|
|||||||
return fmt.Errorf("not authorised to access the following keys %+v", notAllowed)
|
return fmt.Errorf("not authorised to access the following keys %+v", notAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8. If @read is in the list of categories, check if keys are in IncludedReadKeys
|
// 9. If @read is in the list of categories, check if keys are in IncludedReadKeys
|
||||||
if len(keys) > 0 && slices.Contains(categories, utils.ReadCategory) && !slices.ContainsFunc(keys, func(key string) bool {
|
if len(keys) > 0 && slices.Contains(categories, utils.ReadCategory) && !slices.ContainsFunc(keys, func(key string) bool {
|
||||||
return slices.ContainsFunc(connection.User.IncludedReadKeys, func(readKeyGlob string) bool {
|
return slices.ContainsFunc(connection.User.IncludedReadKeys, func(readKeyGlob string) bool {
|
||||||
if acl.GlobPatterns[readKeyGlob].Match(key) {
|
if acl.GlobPatterns[readKeyGlob].Match(key) {
|
||||||
@@ -367,7 +372,7 @@ func (acl *ACL) AuthorizeConnection(conn *net.Conn, cmd []string, command utils.
|
|||||||
return fmt.Errorf("not authorised to access the following keys %+v", notAllowed)
|
return fmt.Errorf("not authorised to access the following keys %+v", notAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9. If @write is in the list of categories, check if keys are in IncludedWriteKeys
|
// 10. If @write is in the list of categories, check if keys are in IncludedWriteKeys
|
||||||
if len(keys) > 0 && slices.Contains(categories, utils.WriteCategory) && !slices.ContainsFunc(keys, func(key string) bool {
|
if len(keys) > 0 && slices.Contains(categories, utils.WriteCategory) && !slices.ContainsFunc(keys, func(key string) bool {
|
||||||
return slices.ContainsFunc(connection.User.IncludedWriteKeys, func(writeKeyGlob string) bool {
|
return slices.ContainsFunc(connection.User.IncludedWriteKeys, func(writeKeyGlob string) bool {
|
||||||
if acl.GlobPatterns[writeKeyGlob].Match(key) {
|
if acl.GlobPatterns[writeKeyGlob].Match(key) {
|
||||||
@@ -403,10 +408,7 @@ func (acl *ACL) CompileGlobs() {
|
|||||||
// Compile the globs that have not been compiled yet
|
// Compile the globs that have not been compiled yet
|
||||||
for _, g := range allGlobs {
|
for _, g := range allGlobs {
|
||||||
if acl.GlobPatterns[g] == nil {
|
if acl.GlobPatterns[g] == nil {
|
||||||
fmt.Println("COMPILING GLOB ", g)
|
|
||||||
acl.GlobPatterns[g] = glob.MustCompile(g)
|
acl.GlobPatterns[g] = glob.MustCompile(g)
|
||||||
} else {
|
|
||||||
fmt.Println("GLOB ", g, "ALREADY COMPILED, SKIPPING...")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -152,22 +152,27 @@ func (user *User) UpdateUser(cmd []string) error {
|
|||||||
user.IncludedKeys = []string{"*"}
|
user.IncludedKeys = []string{"*"}
|
||||||
user.IncludedReadKeys = []string{"*"}
|
user.IncludedReadKeys = []string{"*"}
|
||||||
user.IncludedWriteKeys = []string{"*"}
|
user.IncludedWriteKeys = []string{"*"}
|
||||||
|
user.NoKeys = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(str) > 1 && str[0] == '~' {
|
if len(str) > 1 && str[0] == '~' {
|
||||||
user.IncludedKeys = append(user.IncludedKeys, str[1:])
|
user.IncludedKeys = append(user.IncludedKeys, str[1:])
|
||||||
|
user.NoKeys = false
|
||||||
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[4:])
|
user.IncludedKeys = append(user.IncludedKeys, str[4:])
|
||||||
|
user.NoKeys = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(str) > 3 && strings.EqualFold(str[0:3], "%R~") {
|
if len(str) > 3 && strings.EqualFold(str[0:3], "%R~") {
|
||||||
user.IncludedReadKeys = append(user.IncludedReadKeys, str[3:])
|
user.IncludedReadKeys = append(user.IncludedReadKeys, str[3:])
|
||||||
|
user.NoKeys = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(str) > 3 && strings.EqualFold(str[0:3], "%W~") {
|
if len(str) > 3 && strings.EqualFold(str[0:3], "%W~") {
|
||||||
user.IncludedWriteKeys = append(user.IncludedWriteKeys, str[3:])
|
user.IncludedWriteKeys = append(user.IncludedWriteKeys, str[3:])
|
||||||
|
user.NoKeys = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Parse channels
|
// Parse channels
|
||||||
|
Reference in New Issue
Block a user