Pass context to DeleteUser and AuthenticateUser

This commit is contained in:
Kelvin Clement Mwinuka
2023-12-18 05:12:29 +08:00
parent 29b7d808eb
commit f4432a4d0e
2 changed files with 5 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
package acl
import (
"context"
"crypto/sha256"
"encoding/json"
"errors"
@@ -134,7 +135,7 @@ func (acl *ACL) RegisterConnection(conn *net.Conn) {
}
}
func (acl *ACL) DeleteUser(usernames []string) error {
func (acl *ACL) DeleteUser(ctx context.Context, usernames []string) error {
var user User
for _, username := range usernames {
if username == "default" {
@@ -165,7 +166,7 @@ func (acl *ACL) DeleteUser(usernames []string) error {
return nil
}
func (acl *ACL) AuthenticateConnection(conn *net.Conn, cmd []string) error {
func (acl *ACL) AuthenticateConnection(ctx context.Context, conn *net.Conn, cmd []string) error {
var passwords []Password
var user User

View File

@@ -64,7 +64,7 @@ func (p Plugin) handleAuth(ctx context.Context, cmd []string, server utils.Serve
if len(cmd) < 2 || len(cmd) > 3 {
return nil, errors.New(utils.WRONG_ARGS_RESPONSE)
}
if err := p.acl.AuthenticateConnection(conn, cmd); err != nil {
if err := p.acl.AuthenticateConnection(ctx, conn, cmd); err != nil {
return nil, err
}
return []byte(utils.OK_RESPONSE), nil
@@ -240,7 +240,7 @@ func (p Plugin) handleDelUser(ctx context.Context, cmd []string, server utils.Se
if len(cmd) < 3 {
return nil, errors.New(utils.WRONG_ARGS_RESPONSE)
}
if err := p.acl.DeleteUser(cmd[2:]); err != nil {
if err := p.acl.DeleteUser(ctx, cmd[2:]); err != nil {
return nil, err
}
return []byte(utils.OK_RESPONSE), nil