From 21af06302aaefa6c7b4f0f4381b003bce249765b Mon Sep 17 00:00:00 2001 From: delthas Date: Sun, 7 Jun 2020 01:32:50 +0200 Subject: [PATCH] sojuctl: Add support for creating admin users This adds a new flag, `-admin` for creating admin users, which can access admin service commands, among which create-user to create other users on-the-fly. Since the person running the commands in the README will be the local soju administrator, the user they create should be admin as well, hence the README update. --- README.md | 2 +- cmd/sojuctl/main.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 13af0a5..28fd431 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A user-friendly IRC bouncer. ## Usage - go run ./cmd/sojuctl create-user + go run ./cmd/sojuctl create-user -admin go run ./cmd/soju -listen irc+insecure://127.0.0.1:6667 Then connect with username `/chat.freenode.net` and join `#soju`. diff --git a/cmd/sojuctl/main.go b/cmd/sojuctl/main.go index d7bcdeb..334cfa1 100644 --- a/cmd/sojuctl/main.go +++ b/cmd/sojuctl/main.go @@ -15,9 +15,9 @@ import ( const usage = `usage: sojuctl [-config path] [options...] - create-user Create a new user - change-password Change password for a user - help Show this help message + create-user [-admin] Create a new user + change-password Change password for a user + help Show this help message ` func init() { @@ -55,6 +55,10 @@ func main() { os.Exit(1) } + fs := flag.NewFlagSet("", flag.ExitOnError) + admin := fs.Bool("admin", false, "make the new user admin") + fs.Parse(flag.Args()[2:]) + password, err := readPassword() if err != nil { log.Fatalf("failed to read password: %v", err) @@ -68,6 +72,7 @@ func main() { user := soju.User{ Username: username, Password: string(hashed), + Admin: *admin, } if err := db.StoreUser(&user); err != nil { log.Fatalf("failed to create user: %v", err)