Skip to content

CLI flag and password prompt improvements #769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 44 additions & 31 deletions cmd/embedded-cluster/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,23 +529,31 @@ func runOutro(c *cli.Context, cfg *k0sconfig.ClusterConfig, adminConsolePwd stri
}

func askAdminConsolePassword(c *cli.Context) (string, error) {
defaultPass := "password"
defaultPassword := "password"
userProvidedPassword := c.String("admin-console-password")
if c.Bool("no-prompt") {
logrus.Infof("Admin Console password set to: %s", defaultPass)
return defaultPass, nil
if userProvidedPassword != "" {
return userProvidedPassword, nil
} else {
logrus.Infof("The Admin Console password is set to %s", defaultPassword)
return defaultPassword, nil
}
}
if userProvidedPassword != "" {
return userProvidedPassword, nil
}
maxTries := 3
for i := 0; i < maxTries; i++ {
promptA := prompts.New().Password("Enter an Admin Console password:")
promptB := prompts.New().Password("Confirm password:")
promptA := prompts.New().Password("Set the Admin Console password:")
promptB := prompts.New().Password("Confirm the Admin Console password:")

if promptA == promptB {
// TODO: Should we add extra password validation here? e.g length, complexity etc
return promptA, nil
}
logrus.Info("Passwords don't match, please try again.")
logrus.Info("Passwords don't match. Please try again.")
}
return "", fmt.Errorf("unable to set Admin Console password after %d tries", maxTries)
return "", fmt.Errorf("unable to set the Admin Console password after %d tries", maxTries)
}

// installCommands executes the "install" command. This will ensure that a k0s.yaml file exists
Expand All @@ -564,60 +572,65 @@ var installCommand = &cli.Command{
return nil
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "no-prompt",
Usage: "Disable interactive prompts. Admin console password will be set to password.",
Value: false,
},
&cli.StringFlag{
Name: "overrides",
Usage: "File with an EmbeddedClusterConfig object to override the default configuration",
Hidden: true,
},
&cli.StringFlag{
Name: "license",
Aliases: []string{"l"},
Usage: "Path to the application license file",
Hidden: false,
Name: "admin-console-password",
Usage: "Password for the Admin Console",
Hidden: false,
},
&cli.StringFlag{
Name: "airgap-bundle",
Usage: "Path to the airgap bundle. If set, the installation will be completed without internet access.",
Usage: "Path to the air gap bundle. If set, the installation will complete without internet access.",
Hidden: true,
},
&cli.StringFlag{
Name: "http-proxy",
Usage: "HTTP proxy to use for the installation",
Usage: "Proxy server to use for HTTP",
Hidden: false,
},
&cli.StringFlag{
Name: "https-proxy",
Usage: "HTTPS proxy to use for the installation",
Usage: "Proxy server to use for HTTPS",
Hidden: false,
},
&cli.StringFlag{
Name: "license",
Aliases: []string{"l"},
Usage: "Path to the license file",
Hidden: false,
},
&cli.BoolFlag{
Name: "no-prompt",
Usage: "Disable interactive prompts. The Admin Console password will be set to password.",
Value: false,
},
&cli.StringFlag{
Name: "no-proxy",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this flag be right below the http-proxy and https-proxy flags?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered grouping those together but did it alphabetically, which seems fairly standard.

Usage: "Comma separated list of hosts to bypass the proxy for",
Usage: "Comma-separated list of hosts for which not to use a proxy",
Hidden: false,
},
&cli.BoolFlag{
Name: "proxy",
Usage: "Use the system proxy settings for the install operation. These variables are currently only passed through to Velero and the Admin Console.",
&cli.StringFlag{
Name: "overrides",
Usage: "File with an EmbeddedClusterConfig object to override the default configuration",
Hidden: true,
},
&cli.StringFlag{
Name: "pod-cidr",
Usage: "pod CIDR range to use for the installation",
Usage: "IP address range for pods",
Hidden: false,
},
&cli.BoolFlag{
Name: "proxy",
Usage: "Use the system proxy settings for the install operation. These variables are currently only passed through to Velero and the Admin Console.",
Hidden: true,
},
&cli.StringFlag{
Name: "service-cidr",
Usage: "service CIDR range to use for the installation",
Usage: "IP address range for services",
Hidden: false,
},
&cli.BoolFlag{
Name: "skip-host-preflights",
Usage: "Skip host preflight checks. This is not recommended unless you are sure your system is compatible.",
Usage: "Skip host preflight checks. This is not recommended.",
Value: false,
},
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/embedded-cluster/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ var joinCommand = &cli.Command{
Flags: []cli.Flag{
&cli.StringFlag{
Name: "airgap-bundle",
Usage: "Path to the airgap bundle. If set, the installation will be completed without internet access.",
Usage: "Path to the air gap bundle. If set, the installation will complete without internet access.",
Hidden: true,
},
&cli.BoolFlag{
Expand All @@ -146,7 +146,7 @@ var joinCommand = &cli.Command{
},
&cli.BoolFlag{
Name: "skip-host-preflights",
Usage: "Skip host preflight checks. This is not recommended unless you are sure your system is compatible.",
Usage: "Skip host preflight checks. This is not recommended.",
Value: false,
},
},
Expand Down
14 changes: 7 additions & 7 deletions cmd/embedded-cluster/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,22 +898,22 @@ var restoreCommand = &cli.Command{
Flags: []cli.Flag{
&cli.StringFlag{
Name: "airgap-bundle",
Usage: "Path to the airgap bundle. If set, the restore will be completed without internet access.",
Usage: "Path to the air gap bundle. If set, the restore will complete without internet access.",
Hidden: true,
},
&cli.StringFlag{
Name: "http-proxy",
Usage: "HTTP proxy to use for the restore",
Usage: "Proxy server to use for HTTP",
Hidden: false,
},
&cli.StringFlag{
Name: "https-proxy",
Usage: "HTTPS proxy to use for the restore",
Usage: "Proxy server to use for HTTPS",
Hidden: false,
},
&cli.StringFlag{
Name: "no-proxy",
Usage: "Comma separated list of hosts to bypass the proxy for",
Usage: "Comma-separated list of hosts for which not to use a proxy",
Hidden: false,
},
&cli.BoolFlag{
Expand All @@ -923,17 +923,17 @@ var restoreCommand = &cli.Command{
},
&cli.StringFlag{
Name: "pod-cidr",
Usage: "pod CIDR range to use for the installation",
Usage: "IP address range for pods. Must match range provided during install.",
Hidden: false,
},
&cli.StringFlag{
Name: "service-cidr",
Usage: "service CIDR range to use for the installation",
Usage: "IP address range for services. Must match range provided during install.",
Hidden: false,
},
&cli.BoolFlag{
Name: "skip-host-preflights",
Usage: "Skip host preflight checks. This is not recommended unless you are sure your system is compatible.",
Usage: "Skip host preflight checks. This is not recommended.",
Value: false,
},
},
Expand Down
10 changes: 5 additions & 5 deletions cmd/embedded-cluster/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,17 @@ var resetCommand = &cli.Command{
},
Args: false,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "no-prompt",
Usage: "Disable interactive prompts",
Value: false,
},
&cli.BoolFlag{
Name: "force",
Aliases: []string{"f"},
Usage: "Ignore errors encountered when resetting the node (implies --no-prompt)",
Value: false,
},
&cli.BoolFlag{
Name: "no-prompt",
Usage: "Disable interactive prompts",
Value: false,
},
&cli.BoolFlag{
Name: "reboot",
Usage: "Reboot system after resetting the node",
Expand Down