Skip to content

Commit

Permalink
Merge pull request #33 from EchoVault/feature/embedded-extensions
Browse files Browse the repository at this point in the history
Allow extension of EchoVault commands using the embedded API
  • Loading branch information
kelvinmwinuka authored Apr 29, 2024
2 parents 8be29f7 + 281c4f2 commit f017d65
Show file tree
Hide file tree
Showing 61 changed files with 1,702 additions and 1,046 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ package main

import (
"context"
"github.com/echovault/echovault/echovault"
"github.com/echovault/echovault/internal"
"github.com/echovault/echovault/internal/config"
"github.com/echovault/echovault/pkg/echovault"
"log"
"os"
"os/signal"
Expand Down
24 changes: 12 additions & 12 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- TLS=false
- MTLS=false
- BOOTSTRAP_CLUSTER=false
- ACL_CONFIG=/etc/config/echovault/acl.yml
# - ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=false
- PASSWORD=password1
- FORWARD_COMMAND=false
Expand All @@ -44,7 +44,7 @@ services:
- "7946:7946"
- "7999:8000"
volumes:
- ./config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/standalone_node:/var/lib/echovault
networks:
- testnet
Expand All @@ -65,7 +65,7 @@ services:
- TLS=false
- MTLS=false
- BOOTSTRAP_CLUSTER=true
- ACL_CONFIG=/etc/config/echovault/acl.yml
# - ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=false
- FORWARD_COMMAND=true
- SNAPSHOT_THRESHOLD=1000
Expand All @@ -87,7 +87,7 @@ services:
- "7945:7946"
- "8000:8000"
volumes:
- ./config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/cluster_node_1:/var/lib/echovault
networks:
- testnet
Expand All @@ -108,7 +108,7 @@ services:
- TLS=false
- MTLS=false
- BOOTSTRAP_CLUSTER=false
- ACL_CONFIG=/etc/config/echovault/acl.yml
# - ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=false
- FORWARD_COMMAND=true
- SNAPSHOT_THRESHOLD=1000
Expand All @@ -130,7 +130,7 @@ services:
- "7947:7946"
- "8001:8000"
volumes:
- ./config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/cluster_node_2:/var/lib/echovault
networks:
- testnet
Expand All @@ -151,7 +151,7 @@ services:
- TLS=false
- MTLS=false
- BOOTSTRAP_CLUSTER=false
- ACL_CONFIG=/etc/config/echovault/acl.yml
# - ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=false
- FORWARD_COMMAND=true
- SNAPSHOT_THRESHOLD=1000
Expand All @@ -173,7 +173,7 @@ services:
- "7948:7946"
- "8002:8000"
volumes:
- ./config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/cluster_node_3:/var/lib/echovault
networks:
- testnet
Expand All @@ -194,7 +194,7 @@ services:
- TLS=false
- MTLS=false
- BOOTSTRAP_CLUSTER=false
- ACL_CONFIG=/etc/config/echovault/acl.yml
# - ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=false
- FORWARD_COMMAND=true
- SNAPSHOT_THRESHOLD=1000
Expand All @@ -216,7 +216,7 @@ services:
- "7949:7946"
- "8003:8000"
volumes:
- ./config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/cluster_node_4:/var/lib/echovault
networks:
- testnet
Expand All @@ -237,7 +237,7 @@ services:
- TLS=false
- MTLS=false
- BOOTSTRAP_CLUSTER=false
- ACL_CONFIG=/etc/config/echovault/acl.yml
# - ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=false
- FORWARD_COMMAND=true
- SNAPSHOT_THRESHOLD=1000
Expand All @@ -259,7 +259,7 @@ services:
- "7950:7946"
- "8004:8000"
volumes:
- ./config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/cluster_node_5:/var/lib/echovault
networks:
- testnet
44 changes: 22 additions & 22 deletions pkg/echovault/api_acl.go → echovault/api_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import (
"github.com/tidwall/resp"
)

// ACLLOADOptions modifies the behaviour of the ACL_LOAD function.
// ACLLoadOptions modifies the behaviour of the ACLLoad function.
// If Merge is true, the ACL configuration from the file will be merged with the in-memory ACL configuration.
// If Replace is set to true, the ACL configuration from the file will replace the in-memory ACL configuration.
// If both flags are set to true, Merge will be prioritised.
type ACLLOADOptions struct {
type ACLLoadOptions struct {
Merge bool
Replace bool
}

// User is the user object passed to the ACL_SETUSER function to update an existing user or create a new user.
// User is the user object passed to the ACLSetUser function to update an existing user or create a new user.
//
// Username - string - the user's username.
//
Expand Down Expand Up @@ -75,10 +75,10 @@ type ACLLOADOptions struct {
// IncludeWriteKeys - []string - the list of keys the user is allowed write access to. The default is all.
// This field accepts glob pattern strings.
//
// IncludeChannels - []string - the list of PubSub channels the user is allowed to access ("SUBSCRIBE" and "PUBLISH").
// IncludeChannels - []string - the list of PubSub channels the user is allowed to access ("Subscribe" and "Publish").
// This field accepts glob pattern strings.
//
// ExcludeChannels - []string - the list of PubSub channels the user cannot access ("SUBSCRIBE" and "PUBLISH").
// ExcludeChannels - []string - the list of PubSub channels the user cannot access ("Subscribe" and "Publish").
// This field accepts glob pattern strings.
type User struct {
Username string
Expand Down Expand Up @@ -109,7 +109,7 @@ type User struct {
ExcludeChannels []string
}

// ACL_CAT returns either the list of all categories or the list of commands within a specified category.
// ACLCat returns either the list of all categories or the list of commands within a specified category.
//
// Parameters:
//
Expand All @@ -122,7 +122,7 @@ type User struct {
// Errors:
//
// "category <category> not found" - when the provided category is not found in the loaded commands.
func (server *EchoVault) ACL_CAT(category ...string) ([]string, error) {
func (server *EchoVault) ACLCat(category ...string) ([]string, error) {
cmd := []string{"ACL", "CAT"}
if len(category) > 0 {
cmd = append(cmd, category[0])
Expand All @@ -134,24 +134,24 @@ func (server *EchoVault) ACL_CAT(category ...string) ([]string, error) {
return internal.ParseStringArrayResponse(b)
}

// ACL_USERS returns a string slice containing the usernames of all the loaded users in the ACL module.
func (server *EchoVault) ACL_USERS() ([]string, error) {
// ACLUsers returns a string slice containing the usernames of all the loaded users in the ACL module.
func (server *EchoVault) ACLUsers() ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "USERS"}), nil, false, true)
if err != nil {
return nil, err
}
return internal.ParseStringArrayResponse(b)
}

// ACL_SETUSER modifies or creates a new user. If the user with the specified username exists, the ACL user will be modified.
// ACLSetUser modifies or creates a new user. If the user with the specified username exists, the ACL user will be modified.
// Otherwise, a new User is created.
//
// Parameters:
//
// `user` - User - The user object to add/update.
//
// Returns: "OK" if the user is successfully created/updated.
func (server *EchoVault) ACL_SETUSER(user User) (string, error) {
func (server *EchoVault) ACLSetUser(user User) (string, error) {
cmd := []string{"ACL", "SETUSER", user.Username}

if user.Enabled {
Expand Down Expand Up @@ -244,7 +244,7 @@ func (server *EchoVault) ACL_SETUSER(user User) (string, error) {
return internal.ParseStringResponse(b)
}

// ACL_GETUSER gets the ACL configuration of the name with the given username.
// ACLGetUser gets the ACL configuration of the name with the given username.
//
// Parameters:
//
Expand Down Expand Up @@ -288,7 +288,7 @@ func (server *EchoVault) ACL_SETUSER(user User) (string, error) {
// Errors:
//
// "user not found" - if the user requested does not exist in the ACL rules.
func (server *EchoVault) ACL_GETUSER(username string) (map[string][]string, error) {
func (server *EchoVault) ACLGetUser(username string) (map[string][]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "GETUSER", username}), nil, false, true)
if err != nil {
return nil, err
Expand Down Expand Up @@ -317,14 +317,14 @@ func (server *EchoVault) ACL_GETUSER(username string) (map[string][]string, erro
return result, nil
}

// ACL_DELUSER deletes all the users with the specified usernames.
// ACLDelUser deletes all the users with the specified usernames.
//
// Parameters:
//
// `usernames` - ...string - A string of usernames to delete from the ACL module.
//
// Returns: "OK" if the deletion is successful.
func (server *EchoVault) ACL_DELUSER(usernames ...string) (string, error) {
func (server *EchoVault) ACLDelUser(usernames ...string) (string, error) {
cmd := append([]string{"ACL", "DELUSER"}, usernames...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
Expand All @@ -333,24 +333,24 @@ func (server *EchoVault) ACL_DELUSER(usernames ...string) (string, error) {
return internal.ParseStringResponse(b)
}

// ACL_LIST lists all the currently loaded ACL users and their rules.
func (server *EchoVault) ACL_LIST() ([]string, error) {
// ACLList lists all the currently loaded ACL users and their rules.
func (server *EchoVault) ACLList() ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "LIST"}), nil, false, true)
if err != nil {
return nil, err
}
return internal.ParseStringArrayResponse(b)
}

// ACL_LOAD loads the ACL configuration from the configured ACL file. The load function can either merge the loaded
// ACLLoad loads the ACL configuration from the configured ACL file. The load function can either merge the loaded
// config with the in-memory config, or replace the in-memory config with the loaded config entirely.
//
// Parameters:
//
// `options` - ACLLOADOptions - modifies the load behaviour.
// `options` - ACLLoadOptions - modifies the load behaviour.
//
// Returns: "OK" if the load is successful.
func (server *EchoVault) ACL_LOAD(options ACLLOADOptions) (string, error) {
func (server *EchoVault) ACLLoad(options ACLLoadOptions) (string, error) {
cmd := []string{"ACL", "LOAD"}
switch {
case options.Merge:
Expand All @@ -369,10 +369,10 @@ func (server *EchoVault) ACL_LOAD(options ACLLOADOptions) (string, error) {
return internal.ParseStringResponse(b)
}

// ACL_SAVE saves the current ACL configuration to the configured ACL file.
// ACLSave saves the current ACL configuration to the configured ACL file.
//
// Returns: "OK" if the save is successful.
func (server *EchoVault) ACL_SAVE() (string, error) {
func (server *EchoVault) ACLSave() (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "SAVE"}), nil, false, true)
if err != nil {
return "", err
Expand Down
Loading

0 comments on commit f017d65

Please sign in to comment.