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.
This commit is contained in:
parent
5be25711c7
commit
21af06302a
@ -12,7 +12,7 @@ A user-friendly IRC bouncer.
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
go run ./cmd/sojuctl create-user <username>
|
go run ./cmd/sojuctl create-user <username> -admin
|
||||||
go run ./cmd/soju -listen irc+insecure://127.0.0.1:6667
|
go run ./cmd/soju -listen irc+insecure://127.0.0.1:6667
|
||||||
|
|
||||||
Then connect with username `<username>/chat.freenode.net` and join `#soju`.
|
Then connect with username `<username>/chat.freenode.net` and join `#soju`.
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
const usage = `usage: sojuctl [-config path] <action> [options...]
|
const usage = `usage: sojuctl [-config path] <action> [options...]
|
||||||
|
|
||||||
create-user <username> Create a new user
|
create-user <username> [-admin] Create a new user
|
||||||
change-password <username> Change password for a user
|
change-password <username> Change password for a user
|
||||||
help Show this help message
|
help Show this help message
|
||||||
`
|
`
|
||||||
@ -55,6 +55,10 @@ func main() {
|
|||||||
os.Exit(1)
|
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()
|
password, err := readPassword()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to read password: %v", err)
|
log.Fatalf("failed to read password: %v", err)
|
||||||
@ -68,6 +72,7 @@ func main() {
|
|||||||
user := soju.User{
|
user := soju.User{
|
||||||
Username: username,
|
Username: username,
|
||||||
Password: string(hashed),
|
Password: string(hashed),
|
||||||
|
Admin: *admin,
|
||||||
}
|
}
|
||||||
if err := db.StoreUser(&user); err != nil {
|
if err := db.StoreUser(&user); err != nil {
|
||||||
log.Fatalf("failed to create user: %v", err)
|
log.Fatalf("failed to create user: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user