Skip to content

Commit

Permalink
Merge pull request #10 from EchoVault/enhancement/redis-client-compat…
Browse files Browse the repository at this point in the history
…ibility

Enhancement/redis client compatibility
  • Loading branch information
kelvinmwinuka authored Feb 28, 2024
2 parents 42154fe + 62ef29c commit dbeacc7
Show file tree
Hide file tree
Showing 26 changed files with 779 additions and 519 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Go Coverage](https://github.com/EchoVault/EchoVault/wiki/coverage.svg)](https://raw.githack.com/wiki/EchoVault/EchoVault/coverage.html)
[![GitHub Release](https://img.shields.io/github/v/release/EchoVault/EchoVault)]()
<br/>
[![License: GPL v2](https://img.shields.io/badge/License-GPL_v2-blue.svg)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
[![License: GPL v3](https://img.shields.io/badge/License-GPL_v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)
<br/>
[![Discord](https://img.shields.io/discord/1211815152291414037?style=flat&logo=discord&link=https%3A%2F%2Fdiscord.gg%2Fvt45CKfF)](https://discord.gg/vt45CKfF)

Expand Down
14 changes: 7 additions & 7 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
- DATA_DIR=/var/lib/echovault
- IN_MEMORY=false
- TLS=true
- MTLS=true
- MTLS=false
- BOOTSTRAP_CLUSTER=false
- ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=true
Expand All @@ -36,7 +36,7 @@ services:
# List of client certificate authorities
- CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
ports:
- "7479:7480"
- "7480:7480"
- "7946:7946"
- "7999:8000"
volumes:
Expand Down Expand Up @@ -76,7 +76,7 @@ services:
# List of client certificate authorities
- CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
ports:
- "7480:7480"
- "7481:7480"
- "7945:7946"
- "8000:8000"
volumes:
Expand Down Expand Up @@ -117,7 +117,7 @@ services:
# List of client certificate authorities
- CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
ports:
- "7481:7480"
- "7482:7480"
- "7947:7946"
- "8001:8000"
volumes:
Expand Down Expand Up @@ -158,7 +158,7 @@ services:
# List of client certificate authorities
- CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
ports:
- "7482:7480"
- "7483:7480"
- "7948:7946"
- "8002:8000"
volumes:
Expand Down Expand Up @@ -199,7 +199,7 @@ services:
# List of client certificate authorities
- CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
ports:
- "7483:7480"
- "7484:7480"
- "7949:7946"
- "8003:8000"
volumes:
Expand Down Expand Up @@ -240,7 +240,7 @@ services:
# List of client certificate authorities
- CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
ports:
- "7484:7480"
- "7485:7480"
- "7950:7946"
- "8004:8000"
volumes:
Expand Down
7 changes: 3 additions & 4 deletions src/memberlist/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/echovault/echovault/src/utils"
"github.com/hashicorp/memberlist"
"github.com/hashicorp/raft"
"log"
"time"
)

Expand Down Expand Up @@ -79,14 +80,12 @@ func (delegate *Delegate) NotifyMsg(msgBytes []byte) {

cmd, err := utils.Decode(msg.Content)
if err != nil {
// TODO: Log error to configured logger
fmt.Println(err)
log.Println(err)
return
}

if _, err := delegate.options.applyMutate(ctx, cmd); err != nil {
// TODO: Log error to configured logger
fmt.Println(err)
log.Println(err)
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/modules/acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ func NewACL(config utils.Config) *ACL {

func (acl *ACL) RegisterConnection(conn *net.Conn) {
// This is called only when a connection is established.
defaultUser := utils.Filter(acl.Users, func(elem *User) bool {
return elem.Username == "default"
})[0]
defaultUserIdx := slices.IndexFunc(acl.Users, func(user *User) bool {
return user.Username == "default"
})
defaultUser := acl.Users[defaultUserIdx]
acl.Connections[conn] = Connection{
Authenticated: defaultUser.NoPassword,
User: defaultUser,
Expand Down Expand Up @@ -167,7 +168,7 @@ func (acl *ACL) DeleteUser(ctx context.Context, usernames []string) error {
}
}
// Delete the user from the ACL
acl.Users = utils.Filter(acl.Users, func(u *User) bool {
acl.Users = slices.DeleteFunc(acl.Users, func(u *User) bool {
return u.Username != user.Username
})
}
Expand All @@ -188,9 +189,10 @@ func (acl *ACL) AuthenticateConnection(ctx context.Context, conn *net.Conn, cmd
{PasswordType: "SHA256", PasswordValue: string(h.Sum(nil))},
}
// Authenticate with default user
user = utils.Filter(acl.Users, func(user *User) bool {
idx := slices.IndexFunc(acl.Users, func(user *User) bool {
return user.Username == "default"
})[0]
})
user = acl.Users[idx]
}
if len(cmd) == 3 {
// Process AUTH <username> <password>
Expand Down
12 changes: 6 additions & 6 deletions src/modules/acl/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func handleGetUser(ctx context.Context, cmd []string, server utils.Server, conn
res = res + fmt.Sprintf("\r\n+-&%s", channel)
}

res += "\r\n\r\n"
res += "\r\n"

return []byte(res), nil
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func handleCat(ctx context.Context, cmd []string, server utils.Server, conn *net
for i, cat := range cats {
res = fmt.Sprintf("%s\r\n+%s", res, cat)
if i == len(cats)-1 {
res = res + "\r\n\r\n"
res = res + "\r\n"
}
}
return []byte(res), nil
Expand All @@ -193,7 +193,7 @@ func handleCat(ctx context.Context, cmd []string, server utils.Server, conn *net
for i, command := range commands {
res = fmt.Sprintf("%s\r\n+%s", res, command)
if i == len(commands)-1 {
res = res + "\r\n\r\n"
res = res + "\r\n"
}
}
return []byte(res), nil
Expand All @@ -213,7 +213,7 @@ func handleUsers(ctx context.Context, cmd []string, server utils.Server, conn *n
for _, user := range acl.Users {
res += fmt.Sprintf("\r\n$%d\r\n%s", len(user.Username), user.Username)
}
res += "\r\n\r\n"
res += "\r\n"
return []byte(res), nil
}

Expand Down Expand Up @@ -248,7 +248,7 @@ func handleWhoAmI(ctx context.Context, cmd []string, server utils.Server, conn *
return nil, errors.New("could not load ACL")
}
connectionInfo := acl.Connections[conn]
return []byte(fmt.Sprintf("+%s\r\n\r\n", connectionInfo.User.Username)), nil
return []byte(fmt.Sprintf("+%s\r\n", connectionInfo.User.Username)), nil
}

func handleList(ctx context.Context, cmd []string, server utils.Server, conn *net.Conn) ([]byte, error) {
Expand Down Expand Up @@ -343,7 +343,7 @@ func handleList(ctx context.Context, cmd []string, server utils.Server, conn *ne
res = res + fmt.Sprintf("\r\n$%d\r\n%s", len(s), s)
}

res = res + "\r\n\r\n"
res = res + "\r\n"
return []byte(res), nil
}

Expand Down
9 changes: 4 additions & 5 deletions src/modules/acl/user.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package acl

import (
"github.com/echovault/echovault/src/utils"
"slices"
"strings"
)
Expand Down Expand Up @@ -105,18 +104,18 @@ func (user *User) UpdateUser(cmd []string) error {
continue
}
if str[0] == '<' {
user.Passwords = utils.Filter(user.Passwords, func(password Password) bool {
user.Passwords = slices.DeleteFunc(user.Passwords, func(password Password) bool {
if strings.EqualFold(password.PasswordType, "SHA256") {
return true
return false
}
return password.PasswordValue == str[1:]
})
continue
}
if str[0] == '!' {
user.Passwords = utils.Filter(user.Passwords, func(password Password) bool {
user.Passwords = slices.DeleteFunc(user.Passwords, func(password Password) bool {
if strings.EqualFold(password.PasswordType, "plaintext") {
return true
return false
}
return password.PasswordValue == str[1:]
})
Expand Down
Loading

0 comments on commit dbeacc7

Please sign in to comment.