mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-09 18:00:23 +08:00
Call ACL Authorize for command before processing. Call ACL Authenticate when auth command is triggered.
This commit is contained in:
13
src/main.go
13
src/main.go
@@ -173,8 +173,19 @@ func (server *Server) handleConnection(ctx context.Context, conn net.Conn) {
|
||||
|
||||
synchronize := command.Command.Sync
|
||||
|
||||
if subCommand, ok := utils.GetSubCommand(command, cmd).(utils.SubCommand); ok {
|
||||
subCommand, ok := utils.GetSubCommand(command, cmd).(utils.SubCommand)
|
||||
|
||||
if ok {
|
||||
synchronize = subCommand.Sync
|
||||
err = server.ACL.AuthorizeConnection(&conn, cmd, command.Command, subCommand)
|
||||
} else {
|
||||
err = server.ACL.AuthorizeConnection(&conn, cmd, command.Command, nil)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
connRW.WriteString(fmt.Sprintf("-%s\r\n\n", err.Error()))
|
||||
connRW.Flush()
|
||||
continue
|
||||
}
|
||||
|
||||
if !server.IsInCluster() || !synchronize {
|
||||
|
@@ -2,6 +2,7 @@ package acl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/kelvinmwinuka/memstore/src/utils"
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -133,10 +134,11 @@ func (acl *ACL) RegisterConnection(conn *net.Conn) {
|
||||
}
|
||||
|
||||
func (acl *ACL) AuthenticateConnection(conn *net.Conn, cmd []string) error {
|
||||
return nil
|
||||
return errors.New("could not authenticate user")
|
||||
}
|
||||
|
||||
func (acl *ACL) AuthorizeConnection(conn *net.Conn, cmd []string) error {
|
||||
func (acl *ACL) AuthorizeConnection(conn *net.Conn, cmd []string, command utils.Command, subCommand interface{}) error {
|
||||
fmt.Println("SUBCOMMAND: ", subCommand)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -63,7 +63,13 @@ func (p Plugin) HandleCommand(ctx context.Context, cmd []string, server utils.Se
|
||||
}
|
||||
|
||||
func (p Plugin) handleAuth(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
return nil, errors.New("AUTH not implemented")
|
||||
if len(cmd) < 2 || len(cmd) > 3 {
|
||||
return nil, errors.New("wrong number of arguments")
|
||||
}
|
||||
if err := p.acl.AuthenticateConnection(conn, cmd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []byte("+OK\r\n\n"), nil
|
||||
}
|
||||
|
||||
func (p Plugin) handleGetUser(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
|
||||
|
Reference in New Issue
Block a user