-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from PapePathe/acl
Merge pull request #9 from PapePathe/hash-commands
- Loading branch information
Showing
32 changed files
with
995 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defaultPlatforms: | ||
- linux/arm64 | ||
- linux/amd64 | ||
- linux/arm64/v8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
clean: | ||
rm -rf /tmp/pedis* | ||
|
||
build-image: | ||
ko build | ||
|
||
start-primary: | ||
go run main.go --cluster http://127.0.0.1:12379 | ||
|
||
start-secondary: | ||
go run main.go --id 2 --join --pedis 127.0.0.1:6389 --cluster http://127.0.0.1:12379,http://127.0.0.1:12380 | ||
|
||
start-tertiary: | ||
go run main.go --id 3 --pedis 127.0.0.1:6390 --cluster http://127.0.0.1:12379,http://127.0.0.1:12380,http://127.0.0.1:12381 | ||
|
||
test: | ||
go test -v ./... -race |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,28 @@ | ||
version: "3.4" | ||
x-app: &default-pedis | ||
image: ko.local/ppathe/pedis/pedis-9e6a4042beefc3cd7105eec240e5b3ab:c3cb180cc2aba05bc6202089b4d76c334f18c7a2a5fdf9e2f53691d1bfcce727 | ||
healthcheck: | ||
test: /ko-app/pedis --health | ||
interval: 1s | ||
retries: 5 | ||
start_period: 1s | ||
timeout: 10s | ||
services: | ||
## memtier: | ||
## image: redis | ||
## command: redis-benchmark -h pedis-a | ||
## depends_on: | ||
## - pedis-a | ||
## | ||
memtier: | ||
image: redislabs/memtier_benchmark | ||
command: memtier_benchmark -s pedis-a -p 6379 -R -n allkeys -d 50 -n 10 --command="hset __key__ name Pathe country Senegal" --command-ratio=2 --command-key-pattern=G | ||
pedis-a: | ||
build: . | ||
environment: | ||
ID: 1 | ||
PEDIS: :6379 | ||
PORT: 12380 | ||
CLUSTER: http://pedis-a:12379,http://pedis-b:12379,http://pedis-c:12379 | ||
<<: *default-pedis | ||
container_name: pedis-a | ||
entrypoint: /ko-app/pedis --cluster http://pedis-a:12379 | ||
ports: | ||
- "6379:6379" | ||
pedis-b: | ||
environment: | ||
ID: 2 | ||
PEDIS: :6379 | ||
PORT: 12380 | ||
CLUSTER: http://pedis-a:12379,http://pedis-b:12379,http://pedis-c:12379 | ||
build: . | ||
<<: *default-pedis | ||
container_name: pedis-b | ||
entrypoint: /ko-app/pedis --id 2 --join --cluster http://pedis-a:12379,http://pedis-b:12379 | ||
depends_on: | ||
- pedis-a | ||
ports: | ||
- "6389:6389" | ||
pedis-c: | ||
environment: | ||
ID: 3 | ||
PEDIS: :6379 | ||
PORT: 12380 | ||
CLUSTER: http://pedis-a:12379,http://pedis-b:12379,http://pedis-c:12379 | ||
build: . | ||
<<: *default-pedis | ||
container_name: pedis-c | ||
entrypoint: /ko-app/pedis --id 3 --join --cluster http://pedis-a:12379,http://pedis-b:12379,http://pedis-c:12379 | ||
depends_on: | ||
- pedis-a | ||
ports: | ||
- "6399:6399" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
package commands | ||
|
||
type CommandHandler func(ClientRequest) | ||
type CommandHandler interface { | ||
// Runs the request and write response to client | ||
Handle(ClientRequest) | ||
// Checks that calling user has the permissions required by the command | ||
Authorize(ClientRequest) error | ||
// Returns the list of permissions required to run the command | ||
Permissions() []string | ||
// Returns true if the command is going to persist data | ||
Persistent() bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"pedis/internal/storage" | ||
) | ||
|
||
type AclHandler struct{} | ||
|
||
func (ch AclHandler) Authorize(ClientRequest) error { | ||
return nil | ||
} | ||
|
||
func (ch AclHandler) Permissions() []string { | ||
return nil | ||
} | ||
|
||
func (ch AclHandler) Persistent() bool { | ||
return false | ||
} | ||
|
||
func (ch AclHandler) Handle(r ClientRequest) { | ||
data := r.DataRaw.ReadArray() | ||
r.Logger. | ||
Debug(). | ||
Interface("Data", data). | ||
Interface("RawData", r.DataRaw.String()). | ||
Msg("") | ||
|
||
svc := aclService{} | ||
|
||
switch data[0] { | ||
case "setuser": | ||
_ = svc.setuser(r) | ||
case "deluser": | ||
_ = svc.deluser(r) | ||
case "users": | ||
_ = svc.users(r) | ||
default: | ||
r.WriteError(fmt.Sprintf("(%s) not implemented by devin", data[0])) | ||
} | ||
} | ||
|
||
type aclService struct{} | ||
|
||
func (aclService) deluser(r ClientRequest) error { | ||
data := r.DataRaw.ReadArray() | ||
r.Logger.Debug().Interface("usernames", data[1:]).Msg("Going to delete") | ||
delCount := 0 | ||
|
||
for _, u := range data[1:] { | ||
err := r.Store.DelUser(u) | ||
|
||
if err == nil { | ||
delCount++ | ||
} | ||
} | ||
|
||
r.WriteNumber(fmt.Sprintf("%d", delCount)) | ||
|
||
return nil | ||
} | ||
|
||
func (aclService) setuser(r ClientRequest) error { | ||
data := r.DataRaw.ReadArray() | ||
r.Logger.Debug().Msg("Going to create or update existing user") | ||
username := data[1] | ||
rules := []storage.AclRule{} | ||
|
||
if len(data) >= 2 { | ||
for _, elem := range data[2:] { | ||
switch elem { | ||
case "on": | ||
rules = append(rules, storage.AclRule{Type: storage.AclActivateUser}) | ||
case "off": | ||
rules = append(rules, storage.AclRule{Type: storage.AclDisableUser}) | ||
case "nopass": | ||
rules = append(rules, storage.AclRule{Type: storage.AclDisableUser}) | ||
case "reset": | ||
rules = append(rules, storage.AclRule{Type: storage.AclResetUser}) | ||
default: | ||
switch elem[0] { | ||
case '>': | ||
rules = append(rules, storage.AclRule{Type: storage.AclSetUserPassword, Value: elem[1 : len(elem)-1]}) | ||
default: | ||
r.WriteError(fmt.Sprintf("acl rule (%s) not supported", elem)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
_ = r.Store.SetUser(username, rules) | ||
r.WriteOK() | ||
return nil | ||
} | ||
|
||
func (aclService) users(r ClientRequest) error { | ||
r.Logger.Debug().Msg("Going to list users") | ||
|
||
users := r.Store.Users() | ||
r.Logger.Debug().Interface("Users list", users).Msg("") | ||
r.WriteArray(users) | ||
|
||
return nil | ||
} |
Oops, something went wrong.