@@ -7,33 +7,47 @@ import (
77 "os"
88
99 "github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
10+ "github.com/replicatedhq/embedded-cluster/pkg/prompts"
1011 rcutil "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig/util"
1112 "github.com/sirupsen/logrus"
1213 "github.com/spf13/cobra"
1314)
1415
1516func AdminConsoleResetPasswordCmd (ctx context.Context , name string ) * cobra.Command {
1617 cmd := & cobra.Command {
17- Use : "reset-password" ,
18- Short : fmt .Sprintf ("Reset the %s Admin Console password" , name ),
18+ Use : "reset-password [password] " ,
19+ Short : fmt .Sprintf ("Reset the %s Admin Console password. If no password is provided, you will be prompted to enter a new one. " , name ),
1920 PreRunE : func (cmd * cobra.Command , args []string ) error {
2021 if os .Getuid () != 0 {
2122 return fmt .Errorf ("reset-password command must be run as root" )
2223 }
23- if len (args ) != 1 {
24- return fmt .Errorf ("expected admin console password as argument " )
24+ if len (args ) > 1 {
25+ return fmt .Errorf ("too many arguments provided " )
2526 }
26-
2727 return nil
2828 },
2929 RunE : func (cmd * cobra.Command , args []string ) error {
3030 if err := rcutil .InitRuntimeConfigFromCluster (ctx ); err != nil {
3131 return fmt .Errorf ("failed to init runtime config from cluster: %w" , err )
3232 }
3333
34- password := args [0 ]
35- if ! validateAdminConsolePassword (password , password ) {
36- return NewErrorNothingElseToAdd (errors .New ("password is not valid" ))
34+ var password string
35+ if len (args ) == 1 {
36+ password = args [0 ]
37+ } else {
38+ maxTries := 3
39+ for i := 0 ; i < maxTries ; i ++ {
40+ promptA := prompts .New ().Password (fmt .Sprintf ("Set the Admin Console password (minimum %d characters):" , minAdminPasswordLength ))
41+ promptB := prompts .New ().Password ("Confirm the Admin Console password:" )
42+
43+ if validateAdminConsolePassword (promptA , promptB ) {
44+ password = promptA
45+ break
46+ }
47+ }
48+ if password == "" {
49+ return NewErrorNothingElseToAdd (errors .New ("password is not valid" ))
50+ }
3751 }
3852
3953 if err := kotscli .ResetPassword (password ); err != nil {
0 commit comments