()
| 32 | } |
| 33 | |
| 34 | func verifyUserCmd() *cli.Command { |
| 35 | tCfg := NewVerifyUserConfig() |
| 36 | |
| 37 | loaders := []cli.ResourceLoader{ |
| 38 | &cli.FlagLoader{}, |
| 39 | } |
| 40 | |
| 41 | return &cli.Command{ |
| 42 | Name: "verify", |
| 43 | Description: "Verify a user is set up correctly", |
| 44 | Configuration: tCfg, |
| 45 | Resources: loaders, |
| 46 | Run: func(_ []string) error { |
| 47 | tlog.NewSimpleLogger().Init() |
| 48 | |
| 49 | if tCfg.Interactive { |
| 50 | form := huh.NewForm( |
| 51 | huh.NewGroup( |
| 52 | huh.NewInput().Title("User (username:hash:totp)").Value(&tCfg.User).Validate((func(s string) error { |
| 53 | if s == "" { |
| 54 | return errors.New("user cannot be empty") |
| 55 | } |
| 56 | return nil |
| 57 | })), |
| 58 | huh.NewInput().Title("Username").Value(&tCfg.Username).Validate((func(s string) error { |
| 59 | if s == "" { |
| 60 | return errors.New("username cannot be empty") |
| 61 | } |
| 62 | return nil |
| 63 | })), |
| 64 | huh.NewInput().Title("Password").Value(&tCfg.Password).Validate((func(s string) error { |
| 65 | if s == "" { |
| 66 | return errors.New("password cannot be empty") |
| 67 | } |
| 68 | return nil |
| 69 | })), |
| 70 | huh.NewInput().Title("TOTP Code (optional)").Value(&tCfg.Totp), |
| 71 | ), |
| 72 | ) |
| 73 | |
| 74 | theme := new(themeBase) |
| 75 | err := form.WithTheme(theme).Run() |
| 76 | |
| 77 | if err != nil { |
| 78 | return fmt.Errorf("failed to run interactive prompt: %w", err) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | user, err := utils.ParseUser(tCfg.User) |
| 83 | |
| 84 | if err != nil { |
| 85 | return fmt.Errorf("failed to parse user: %w", err) |
| 86 | } |
| 87 | |
| 88 | if user.Username != tCfg.Username { |
| 89 | return fmt.Errorf("username is incorrect") |
| 90 | } |
| 91 |
no test coverage detected