Changes user add to use a NTFY_PASSWORD env var rather than NTFY_USER.
This commit is contained in:
parent
3dec7efadb
commit
1265e69eee
1 changed files with 14 additions and 26 deletions
40
cmd/user.go
40
cmd/user.go
|
@ -41,7 +41,7 @@ var cmdUser = &cli.Command{
|
||||||
Action: execUserAdd,
|
Action: execUserAdd,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{Name: "role", Aliases: []string{"r"}, Value: string(auth.RoleUser), Usage: "user role"},
|
&cli.StringFlag{Name: "role", Aliases: []string{"r"}, Value: string(auth.RoleUser), Usage: "user role"},
|
||||||
&cli.StringFlag{Name: "user", Aliases: []string{"u"}, EnvVars: []string{"NTFY_USER"}, Usage: "username[:password] used to auth against the server"},
|
&cli.StringFlag{Name: "password", Aliases: []string{"p"}, EnvVars: []string{"NTFY_PASSWORD"}, Usage: "user password"},
|
||||||
},
|
},
|
||||||
Description: `Add a new user to the ntfy user database.
|
Description: `Add a new user to the ntfy user database.
|
||||||
|
|
||||||
|
@ -137,39 +137,27 @@ Examples:
|
||||||
}
|
}
|
||||||
|
|
||||||
func execUserAdd(c *cli.Context) error {
|
func execUserAdd(c *cli.Context) error {
|
||||||
var username string
|
password := c.String("user")
|
||||||
var password string
|
|
||||||
userAndPass := c.String("user")
|
|
||||||
role := auth.Role(c.String("role"))
|
role := auth.Role(c.String("role"))
|
||||||
if userAndPass != "" {
|
username = c.Args().Get(0)
|
||||||
parts := strings.SplitN(userAndPass, ":", 2)
|
if username == "" {
|
||||||
if len(parts) == 2 {
|
return errors.New("username expected, type 'ntfy user add --help' for help")
|
||||||
username = parts[0]
|
} else if username == userEveryone {
|
||||||
password = parts[1]
|
return errors.New("username not allowed")
|
||||||
} else {
|
} else if !auth.AllowedRole(role) {
|
||||||
p, err := readPasswordAndConfirm(c)
|
return errors.New("role must be either 'user' or 'admin'")
|
||||||
if err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
|
||||||
username = userAndPass
|
|
||||||
password = p
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
username = c.Args().Get(0)
|
|
||||||
if username == "" {
|
|
||||||
return errors.New("username expected, type 'ntfy user add --help' for help")
|
|
||||||
} else if username == userEveryone {
|
|
||||||
return errors.New("username not allowed")
|
|
||||||
} else if !auth.AllowedRole(role) {
|
|
||||||
return errors.New("role must be either 'user' or 'admin'")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// If the password env var was not set, read it from stdin
|
||||||
|
if password == "" {
|
||||||
p, err := readPasswordAndConfirm(c)
|
p, err := readPasswordAndConfirm(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
password = p
|
password = p
|
||||||
}
|
}
|
||||||
|
|
||||||
manager, err := createAuthManager(c)
|
manager, err := createAuthManager(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue