From 535e85051f92088ec2112ba68a6f6efee72772c0 Mon Sep 17 00:00:00 2001 From: delthas Date: Mon, 8 Jun 2020 20:30:09 +0000 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. git-svn-id: file:///srv/svn/repo/suika/trunk@330 f0ae65fe-ee39-954e-97ec-027ff2717ef4 --- 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)