Skip to content

Commit

Permalink
Added embedded parameter in handleCommand method which will cause han…
Browse files Browse the repository at this point in the history
…dleCommand to skip ACL auth when it's true
  • Loading branch information
kelvinmwinuka committed Apr 20, 2024
1 parent bef3377 commit fce0258
Show file tree
Hide file tree
Showing 12 changed files with 1,813 additions and 1,881 deletions.
3,410 changes: 1,705 additions & 1,705 deletions coverage/coverage.out

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions pkg/echovault/api_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (server *EchoVault) ACL_CAT(category ...string) ([]string, error) {
if len(category) > 0 {
cmd = append(cmd, category[0])
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)

Check warning on line 130 in pkg/echovault/api_acl.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_acl.go#L130

Added line #L130 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -136,7 +136,7 @@ func (server *EchoVault) ACL_CAT(category ...string) ([]string, error) {

// 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) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "USERS"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "USERS"}), nil, false, true)

Check warning on line 139 in pkg/echovault/api_acl.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_acl.go#L139

Added line #L139 was not covered by tests
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -236,7 +236,7 @@ func (server *EchoVault) ACL_SETUSER(user User) (string, error) {
cmd = append(cmd, fmt.Sprintf("-&%s", channel))
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)

Check warning on line 239 in pkg/echovault/api_acl.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_acl.go#L239

Added line #L239 was not covered by tests
if err != nil {
return "", err
}
Expand Down Expand Up @@ -289,7 +289,7 @@ func (server *EchoVault) ACL_SETUSER(user User) (string, error) {
//
// "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) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "GETUSER", username}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "GETUSER", username}), nil, false, true)

Check warning on line 292 in pkg/echovault/api_acl.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_acl.go#L292

Added line #L292 was not covered by tests
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -326,7 +326,7 @@ func (server *EchoVault) ACL_GETUSER(username string) (map[string][]string, erro
// Returns: "OK" if the deletion is successful.
func (server *EchoVault) ACL_DELUSER(usernames ...string) (string, error) {
cmd := append([]string{"ACL", "DELUSER"}, usernames...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)

Check warning on line 329 in pkg/echovault/api_acl.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_acl.go#L329

Added line #L329 was not covered by tests
if err != nil {
return "", err
}
Expand All @@ -335,7 +335,7 @@ func (server *EchoVault) ACL_DELUSER(usernames ...string) (string, error) {

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

Check warning on line 338 in pkg/echovault/api_acl.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_acl.go#L338

Added line #L338 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -361,7 +361,7 @@ func (server *EchoVault) ACL_LOAD(options ACLLOADOptions) (string, error) {
cmd = append(cmd, "REPLACE")
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)

Check warning on line 364 in pkg/echovault/api_acl.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_acl.go#L364

Added line #L364 was not covered by tests
if err != nil {
return "", err
}
Expand All @@ -373,7 +373,7 @@ func (server *EchoVault) ACL_LOAD(options ACLLOADOptions) (string, error) {
//
// Returns: "OK" if the save is successful.
func (server *EchoVault) ACL_SAVE() (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "SAVE"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "SAVE"}), nil, false, true)

Check warning on line 376 in pkg/echovault/api_acl.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_acl.go#L376

Added line #L376 was not covered by tests
if err != nil {
return "", err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/echovault/api_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (server *EchoVault) COMMAND_LIST(options CommandListOptions) ([]string, err
cmd = append(cmd, []string{"FILTERBY", "MODULE", options.MODULE}...)
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)

Check warning on line 51 in pkg/echovault/api_admin.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_admin.go#L51

Added line #L51 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -60,7 +60,7 @@ func (server *EchoVault) COMMAND_LIST(options CommandListOptions) ([]string, err
//
// Returns: integer representing the count of all available commands.
func (server *EchoVault) COMMAND_COUNT() (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"COMMAND", "COUNT"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"COMMAND", "COUNT"}), nil, false, true)

Check warning on line 63 in pkg/echovault/api_admin.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_admin.go#L63

Added line #L63 was not covered by tests
if err != nil {
return 0, err
}
Expand All @@ -69,7 +69,7 @@ func (server *EchoVault) COMMAND_COUNT() (int, error) {

// SAVE triggers a new snapshot.
func (server *EchoVault) SAVE() (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SAVE"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SAVE"}), nil, false, true)

Check warning on line 72 in pkg/echovault/api_admin.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_admin.go#L72

Added line #L72 was not covered by tests
if err != nil {
return "", err
}
Expand All @@ -78,7 +78,7 @@ func (server *EchoVault) SAVE() (string, error) {

// LASTSAVE returns the unix epoch milliseconds timestamp of the last save.
func (server *EchoVault) LASTSAVE() (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LASTSAVE"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LASTSAVE"}), nil, false, true)

Check warning on line 81 in pkg/echovault/api_admin.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_admin.go#L81

Added line #L81 was not covered by tests
if err != nil {
return 0, err
}
Expand All @@ -87,7 +87,7 @@ func (server *EchoVault) LASTSAVE() (int, error) {

// REWRITEAOF triggers a compaction of the AOF file.
func (server *EchoVault) REWRITEAOF() (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"REWRITEAOF"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"REWRITEAOF"}), nil, false, true)

Check warning on line 90 in pkg/echovault/api_admin.go

View check run for this annotation

Codecov / codecov/patch

pkg/echovault/api_admin.go#L90

Added line #L90 was not covered by tests
if err != nil {
return "", err
}
Expand Down
28 changes: 14 additions & 14 deletions pkg/echovault/api_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (server *EchoVault) SET(key, value string, options SETOptions) (string, err
cmd = append(cmd, "GET")
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return "", err
}
Expand All @@ -136,7 +136,7 @@ func (server *EchoVault) MSET(kvPairs map[string]string) (string, error) {
cmd = append(cmd, []string{k, v}...)
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return "", err
}
Expand All @@ -153,7 +153,7 @@ func (server *EchoVault) MSET(kvPairs map[string]string) (string, error) {
// Returns: A string representing the value at the specified key. If the value does not exist, an empty
// string is returned.
func (server *EchoVault) GET(key string) (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"GET", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"GET", key}), nil, false, true)
if err != nil {
return "", err
}
Expand All @@ -169,7 +169,7 @@ func (server *EchoVault) GET(key string) (string, error) {
//
// Returns: a string slice of all the values.
func (server *EchoVault) MGET(keys ...string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand(append([]string{"MGET"}, keys...)), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(append([]string{"MGET"}, keys...)), nil, false, true)
if err != nil {
return []string{}, err
}
Expand All @@ -184,7 +184,7 @@ func (server *EchoVault) MGET(keys ...string) ([]string, error) {
//
// Returns: The number of keys that were successfully deleted.
func (server *EchoVault) DEL(keys ...string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand(append([]string{"DEL"}, keys...)), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(append([]string{"DEL"}, keys...)), nil, false, true)
if err != nil {
return 0, err
}
Expand All @@ -200,7 +200,7 @@ func (server *EchoVault) DEL(keys ...string) (int, error) {
//
// Returns: true if the keys is successfully persisted.
func (server *EchoVault) PERSIST(key string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PERSIST", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PERSIST", key}), nil, false, true)
if err != nil {
return false, err
}
Expand All @@ -215,7 +215,7 @@ func (server *EchoVault) PERSIST(key string) (bool, error) {
//
// Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.
func (server *EchoVault) EXPIRETIME(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"EXPIRETIME", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"EXPIRETIME", key}), nil, false, true)
if err != nil {
return 0, err
}
Expand All @@ -230,7 +230,7 @@ func (server *EchoVault) EXPIRETIME(key string) (int, error) {
//
// Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.
func (server *EchoVault) PEXPIRETIME(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PEXPIRETIME", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PEXPIRETIME", key}), nil, false, true)
if err != nil {
return 0, err
}
Expand All @@ -245,7 +245,7 @@ func (server *EchoVault) PEXPIRETIME(key string) (int, error) {
//
// Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.
func (server *EchoVault) TTL(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"TTL", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"TTL", key}), nil, false, true)
if err != nil {
return 0, err
}
Expand All @@ -260,7 +260,7 @@ func (server *EchoVault) TTL(key string) (int, error) {
//
// Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.
func (server *EchoVault) PTTL(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PTTL", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PTTL", key}), nil, false, true)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -293,7 +293,7 @@ func (server *EchoVault) EXPIRE(key string, seconds int, options EXPIREOptions)
cmd = append(cmd, "GT")
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -327,7 +327,7 @@ func (server *EchoVault) PEXPIRE(key string, milliseconds int, options PEXPIREOp
cmd = append(cmd, "GT")
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -361,7 +361,7 @@ func (server *EchoVault) EXPIREAT(key string, unixSeconds int, options EXPIREATO
cmd = append(cmd, "GT")
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -395,7 +395,7 @@ func (server *EchoVault) PEXPIREAT(key string, unixMilliseconds int, options PEX
cmd = append(cmd, "GT")
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
Expand Down
34 changes: 12 additions & 22 deletions pkg/echovault/api_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (server *EchoVault) HSET(key string, fieldValuePairs map[string]string) (in
cmd = append(cmd, []string{k, v}...)
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func (server *EchoVault) HSETNX(key string, fieldValuePairs map[string]string) (
cmd = append(cmd, []string{k, v}...)
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
Expand All @@ -105,7 +105,7 @@ func (server *EchoVault) HSETNX(key string, fieldValuePairs map[string]string) (
func (server *EchoVault) HSTRLEN(key string, fields ...string) ([]int, error) {
cmd := append([]string{"HSTRLEN", key}, fields...)

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
Expand All @@ -125,7 +125,7 @@ func (server *EchoVault) HSTRLEN(key string, fields ...string) ([]int, error) {
//
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HVALS(key string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HVALS", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HVALS", key}), nil, false, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func (server *EchoVault) HRANDFIELD(key string, options HRANDFIELDOptions) ([]st
cmd = append(cmd, "WITHVALUES")
}

b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
Expand All @@ -178,7 +178,7 @@ func (server *EchoVault) HRANDFIELD(key string, options HRANDFIELDOptions) ([]st
//
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HLEN(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HLEN", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HLEN", key}), nil, false, true)
if err != nil {
return 0, err
}
Expand All @@ -197,7 +197,7 @@ func (server *EchoVault) HLEN(key string) (int, error) {
//
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HKEYS(key string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HKEYS", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HKEYS", key}), nil, false, true)
if err != nil {
return nil, err
}
Expand All @@ -221,12 +221,7 @@ func (server *EchoVault) HKEYS(key string) ([]string, error) {
//
// "value at field <field> is not a number" - when the field holds a value that is not a number.
func (server *EchoVault) HINCRBY(key, field string, increment int) (float64, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"HINCRBY", key, field, strconv.Itoa(increment)}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HINCRBY", key, field, strconv.Itoa(increment)}), nil, false, true)
if err != nil {
return 0, err
}
Expand All @@ -235,12 +230,7 @@ func (server *EchoVault) HINCRBY(key, field string, increment int) (float64, err

// HINCRBYFLOAT behaves like HINCRBY but with a float increment instead of an integer increment.
func (server *EchoVault) HINCRBYFLOAT(key, field string, increment float64) (float64, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"HINCRBYFLOAT", key, field, strconv.FormatFloat(increment, 'f', -1, 64)}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HINCRBYFLOAT", key, field, strconv.FormatFloat(increment, 'f', -1, 64)}), nil, false, true)
if err != nil {
return 0, err
}
Expand All @@ -260,7 +250,7 @@ func (server *EchoVault) HINCRBYFLOAT(key, field string, increment float64) (flo
//
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HGETALL(key string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HGETALL", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HGETALL", key}), nil, false, true)
if err != nil {
return nil, err
}
Expand All @@ -281,7 +271,7 @@ func (server *EchoVault) HGETALL(key string) ([]string, error) {
//
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HEXISTS(key, field string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HEXISTS", key, field}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HEXISTS", key, field}), nil, false, true)
if err != nil {
return false, err
}
Expand All @@ -303,7 +293,7 @@ func (server *EchoVault) HEXISTS(key, field string) (bool, error) {
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HDEL(key string, fields ...string) (int, error) {
cmd := append([]string{"HDEL", key}, fields...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
Expand Down
Loading

0 comments on commit fce0258

Please sign in to comment.