mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-24 06:28:42 +01:00
feat: improves generate with confirm to catch typos (#3794)
This commit is contained in:
@@ -6,22 +6,36 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/amir20/dozzle/internal/auth"
|
"github.com/amir20/dozzle/internal/auth"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GenerateCmd struct {
|
type GenerateCmd struct {
|
||||||
Username string `arg:"positional"`
|
Username string `arg:"positional"`
|
||||||
Password string `arg:"--password, -p" help:"sets the password for the user"`
|
Password string `arg:"--password, -p" help:"sets the password for the user"`
|
||||||
Name string `arg:"--name, -n" help:"sets the display name for the user"`
|
SkipConfirm bool `arg:"--skip-confirm" help:"skip password confirmation prompt"`
|
||||||
Email string `arg:"--email, -e" help:"sets the email for the user"`
|
Name string `arg:"--name, -n" help:"sets the display name for the user"`
|
||||||
Filter string `arg:"--user-filter" help:"sets the filter for the user. This can be a comma separated list of filters."`
|
Email string `arg:"--email, -e" help:"sets the email for the user"`
|
||||||
|
Filter string `arg:"--user-filter" help:"sets the filter for the user. This can be a comma separated list of filters."`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GenerateCmd) Run(args Args, embeddedCerts embed.FS) error {
|
func (g *GenerateCmd) Run(args Args, embeddedCerts embed.FS) error {
|
||||||
|
writer := zerolog.NewConsoleWriter()
|
||||||
|
log.Logger = log.Output(writer)
|
||||||
StartEvent(args, "", nil, "generate")
|
StartEvent(args, "", nil, "generate")
|
||||||
if args.Generate.Username == "" || args.Generate.Password == "" {
|
if args.Generate.Username == "" || args.Generate.Password == "" {
|
||||||
return fmt.Errorf("username and password are required")
|
return fmt.Errorf("username and password are required")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !args.Generate.SkipConfirm {
|
||||||
|
fmt.Print("Confirm password: ")
|
||||||
|
var confirmPassword string
|
||||||
|
fmt.Scanln(&confirmPassword)
|
||||||
|
if confirmPassword != args.Generate.Password {
|
||||||
|
return fmt.Errorf("passwords do not match")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buffer := auth.GenerateUsers(auth.User{
|
buffer := auth.GenerateUsers(auth.User{
|
||||||
Username: args.Generate.Username,
|
Username: args.Generate.Username,
|
||||||
Password: args.Generate.Password,
|
Password: args.Generate.Password,
|
||||||
|
|||||||
Reference in New Issue
Block a user