From 2ca765de07a91a943020007e131b5249068a0d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Ferr=C3=A3o?= Date: Mon, 6 May 2024 16:08:15 +0100 Subject: [PATCH] flip hide-password to show-password (#285) --- docs/stackit_argus_grafana_describe.md | 8 ++++---- docs/stackit_logme_credentials_create.md | 6 +++--- docs/stackit_mariadb_credentials_create.md | 6 +++--- docs/stackit_opensearch_credentials_create.md | 6 +++--- docs/stackit_rabbitmq_credentials_create.md | 6 +++--- docs/stackit_redis_credentials_create.md | 6 +++--- internal/cmd/argus/grafana/describe/describe.go | 16 ++++++++-------- .../cmd/argus/grafana/describe/describe_test.go | 6 +++--- internal/cmd/logme/credentials/create/create.go | 14 +++++++------- .../cmd/logme/credentials/create/create_test.go | 10 ++++++++++ .../cmd/mariadb/credentials/create/create.go | 14 +++++++------- .../mariadb/credentials/create/create_test.go | 10 ++++++++++ .../cmd/opensearch/credentials/create/create.go | 14 +++++++------- .../opensearch/credentials/create/create_test.go | 10 ++++++++++ .../cmd/rabbitmq/credentials/create/create.go | 14 +++++++------- .../rabbitmq/credentials/create/create_test.go | 10 ++++++++++ internal/cmd/redis/credentials/create/create.go | 14 +++++++------- .../cmd/redis/credentials/create/create_test.go | 10 ++++++++++ 18 files changed, 115 insertions(+), 65 deletions(-) diff --git a/docs/stackit_argus_grafana_describe.md b/docs/stackit_argus_grafana_describe.md index a9c2c3fa2..13177bfa8 100644 --- a/docs/stackit_argus_grafana_describe.md +++ b/docs/stackit_argus_grafana_describe.md @@ -6,7 +6,7 @@ Shows details of the Grafana configuration of an Argus instance Shows details of the Grafana configuration of an Argus instance. The Grafana dashboard URL and initial credentials (admin user and password) will be shown in the "pretty" output format. These credentials are only valid for first login. Please change the password after first login. After changing, the initial password is no longer valid. -The initial password is shown by default, if you want to hide it use the "--hide-password" flag. +The initial password is hidden by default, if you want to show it use the "--show-password" flag. ``` stackit argus grafana describe INSTANCE_ID [flags] @@ -21,15 +21,15 @@ stackit argus grafana describe INSTANCE_ID [flags] Get details of the Grafana configuration of an Argus instance with ID "xxx" in a table format $ stackit argus credentials describe xxx --output-format pretty - Get details of the Grafana configuration of an Argus instance with ID "xxx" and hide the initial admin password - $ stackit argus credentials describe xxx --output-format pretty --hide-password + Get details of the Grafana configuration of an Argus instance with ID "xxx" and show the initial admin password + $ stackit argus credentials describe xxx --output-format pretty --show-password ``` ### Options ``` -h, --help Help for "stackit argus grafana describe" - --hide-password Show the initial admin password in the "pretty" output format + --show-password Show the initial admin password in the "pretty" output format ``` ### Options inherited from parent commands diff --git a/docs/stackit_logme_credentials_create.md b/docs/stackit_logme_credentials_create.md index 40b1e9489..d8e8eb5d3 100644 --- a/docs/stackit_logme_credentials_create.md +++ b/docs/stackit_logme_credentials_create.md @@ -16,16 +16,16 @@ stackit logme credentials create [flags] Create credentials for a LogMe instance $ stackit logme credentials create --instance-id xxx - Create credentials for a LogMe instance and hide the password in the output - $ stackit logme credentials create --instance-id xxx --hide-password + Create credentials for a LogMe instance and show the password in the output + $ stackit logme credentials create --instance-id xxx --show-password ``` ### Options ``` -h, --help Help for "stackit logme credentials create" - --hide-password Hide password in output --instance-id string Instance ID + --show-password Show password in output ``` ### Options inherited from parent commands diff --git a/docs/stackit_mariadb_credentials_create.md b/docs/stackit_mariadb_credentials_create.md index f6ad6d7c8..845e2255d 100644 --- a/docs/stackit_mariadb_credentials_create.md +++ b/docs/stackit_mariadb_credentials_create.md @@ -16,16 +16,16 @@ stackit mariadb credentials create [flags] Create credentials for a MariaDB instance $ stackit mariadb credentials create --instance-id xxx - Create credentials for a MariaDB instance and hide the password in the output - $ stackit mariadb credentials create --instance-id xxx --hide-password + Create credentials for a MariaDB instance and show the password in the output + $ stackit mariadb credentials create --instance-id xxx --show-password ``` ### Options ``` -h, --help Help for "stackit mariadb credentials create" - --hide-password Hide password in output --instance-id string Instance ID + --show-password Show password in output ``` ### Options inherited from parent commands diff --git a/docs/stackit_opensearch_credentials_create.md b/docs/stackit_opensearch_credentials_create.md index 3ca1ce306..a2f8dae4d 100644 --- a/docs/stackit_opensearch_credentials_create.md +++ b/docs/stackit_opensearch_credentials_create.md @@ -16,16 +16,16 @@ stackit opensearch credentials create [flags] Create credentials for an OpenSearch instance $ stackit opensearch credentials create --instance-id xxx - Create credentials for an OpenSearch instance and hide the password in the output - $ stackit opensearch credentials create --instance-id xxx --hide-password + Create credentials for an OpenSearch instance and show the password in the output + $ stackit opensearch credentials create --instance-id xxx --show-password ``` ### Options ``` -h, --help Help for "stackit opensearch credentials create" - --hide-password Hide password in output --instance-id string Instance ID + --show-password Show password in output ``` ### Options inherited from parent commands diff --git a/docs/stackit_rabbitmq_credentials_create.md b/docs/stackit_rabbitmq_credentials_create.md index 512ee227b..bf0ceab5f 100644 --- a/docs/stackit_rabbitmq_credentials_create.md +++ b/docs/stackit_rabbitmq_credentials_create.md @@ -16,16 +16,16 @@ stackit rabbitmq credentials create [flags] Create credentials for a RabbitMQ instance $ stackit rabbitmq credentials create --instance-id xxx - Create credentials for a RabbitMQ instance and hide the password in the output - $ stackit rabbitmq credentials create --instance-id xxx --hide-password + Create credentials for a RabbitMQ instance and show the password in the output + $ stackit rabbitmq credentials create --instance-id xxx --show-password ``` ### Options ``` -h, --help Help for "stackit rabbitmq credentials create" - --hide-password Hide password in output --instance-id string Instance ID + --show-password Show password in output ``` ### Options inherited from parent commands diff --git a/docs/stackit_redis_credentials_create.md b/docs/stackit_redis_credentials_create.md index 377791b5b..a2c2933e3 100644 --- a/docs/stackit_redis_credentials_create.md +++ b/docs/stackit_redis_credentials_create.md @@ -16,16 +16,16 @@ stackit redis credentials create [flags] Create credentials for a Redis instance $ stackit redis credentials create --instance-id xxx - Create credentials for a Redis instance and hide the password in the output - $ stackit redis credentials create --instance-id xxx --hide-password + Create credentials for a Redis instance and show the password in the output + $ stackit redis credentials create --instance-id xxx --show-password ``` ### Options ``` -h, --help Help for "stackit redis credentials create" - --hide-password Hide password in output --instance-id string Instance ID + --show-password Show password in output ``` ### Options inherited from parent commands diff --git a/internal/cmd/argus/grafana/describe/describe.go b/internal/cmd/argus/grafana/describe/describe.go index baa75cab9..63460dec9 100644 --- a/internal/cmd/argus/grafana/describe/describe.go +++ b/internal/cmd/argus/grafana/describe/describe.go @@ -21,13 +21,13 @@ import ( const ( instanceIdArg = "INSTANCE_ID" - hidePasswordFlag = "hide-password" + showPasswordFlag = "show-password" ) type inputModel struct { *globalflags.GlobalFlagModel InstanceId string - HidePassword bool + ShowPassword bool } func NewCmd(p *print.Printer) *cobra.Command { @@ -37,7 +37,7 @@ func NewCmd(p *print.Printer) *cobra.Command { Long: fmt.Sprintf("%s\n%s\n%s", "Shows details of the Grafana configuration of an Argus instance.", `The Grafana dashboard URL and initial credentials (admin user and password) will be shown in the "pretty" output format. These credentials are only valid for first login. Please change the password after first login. After changing, the initial password is no longer valid.`, - `The initial password is shown by default, if you want to hide it use the "--hide-password" flag.`, + `The initial password is hidden by default, if you want to show it use the "--show-password" flag.`, ), Args: args.SingleArg(instanceIdArg, utils.ValidateUUID), Example: examples.Build( @@ -48,8 +48,8 @@ func NewCmd(p *print.Printer) *cobra.Command { `Get details of the Grafana configuration of an Argus instance with ID "xxx" in a table format`, "$ stackit argus credentials describe xxx --output-format pretty"), examples.NewExample( - `Get details of the Grafana configuration of an Argus instance with ID "xxx" and hide the initial admin password`, - "$ stackit argus credentials describe xxx --output-format pretty --hide-password"), + `Get details of the Grafana configuration of an Argus instance with ID "xxx" and show the initial admin password`, + "$ stackit argus credentials describe xxx --output-format pretty --show-password"), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() @@ -84,7 +84,7 @@ func NewCmd(p *print.Printer) *cobra.Command { } func configureFlags(cmd *cobra.Command) { - cmd.Flags().Bool(hidePasswordFlag, false, `Show the initial admin password in the "pretty" output format`) + cmd.Flags().Bool(showPasswordFlag, false, `Show the initial admin password in the "pretty" output format`) } func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) { @@ -98,7 +98,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu model := inputModel{ GlobalFlagModel: globalFlags, InstanceId: instanceId, - HidePassword: flags.FlagToBoolValue(p, cmd, hidePasswordFlag), + ShowPassword: flags.FlagToBoolValue(p, cmd, showPasswordFlag), } if p.IsVerbosityDebug() { @@ -127,7 +127,7 @@ func outputResult(p *print.Printer, inputModel *inputModel, grafanaConfigs *argu switch inputModel.OutputFormat { case print.PrettyOutputFormat: initialAdminPassword := *instance.Instance.GrafanaAdminPassword - if inputModel.HidePassword { + if !inputModel.ShowPassword { initialAdminPassword = "" } diff --git a/internal/cmd/argus/grafana/describe/describe_test.go b/internal/cmd/argus/grafana/describe/describe_test.go index ea5e53538..2bc97589b 100644 --- a/internal/cmd/argus/grafana/describe/describe_test.go +++ b/internal/cmd/argus/grafana/describe/describe_test.go @@ -94,14 +94,14 @@ func TestParseInput(t *testing.T) { isValid: false, }, { - description: "hide password", + description: "show password", argValues: fixtureArgValues(), flagValues: fixtureFlagValues(func(flagValues map[string]string) { - flagValues[hidePasswordFlag] = "true" + flagValues[showPasswordFlag] = "true" }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.HidePassword = true + model.ShowPassword = true }), }, { diff --git a/internal/cmd/logme/credentials/create/create.go b/internal/cmd/logme/credentials/create/create.go index 5899b972f..16cf81285 100644 --- a/internal/cmd/logme/credentials/create/create.go +++ b/internal/cmd/logme/credentials/create/create.go @@ -20,13 +20,13 @@ import ( const ( instanceIdFlag = "instance-id" - hidePasswordFlag = "hide-password" + showPasswordFlag = "show-password" ) type inputModel struct { *globalflags.GlobalFlagModel InstanceId string - HidePassword bool + ShowPassword bool } func NewCmd(p *print.Printer) *cobra.Command { @@ -40,8 +40,8 @@ func NewCmd(p *print.Printer) *cobra.Command { `Create credentials for a LogMe instance`, "$ stackit logme credentials create --instance-id xxx"), examples.NewExample( - `Create credentials for a LogMe instance and hide the password in the output`, - "$ stackit logme credentials create --instance-id xxx --hide-password"), + `Create credentials for a LogMe instance and show the password in the output`, + "$ stackit logme credentials create --instance-id xxx --show-password"), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() @@ -86,7 +86,7 @@ func NewCmd(p *print.Printer) *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") - cmd.Flags().Bool(hidePasswordFlag, false, "Hide password in output") + cmd.Flags().Bool(showPasswordFlag, false, "Show password in output") err := flags.MarkFlagsRequired(cmd, instanceIdFlag) cobra.CheckErr(err) @@ -101,7 +101,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { model := inputModel{ GlobalFlagModel: globalFlags, InstanceId: flags.FlagToStringValue(p, cmd, instanceIdFlag), - HidePassword: flags.FlagToBoolValue(p, cmd, hidePasswordFlag), + ShowPassword: flags.FlagToBoolValue(p, cmd, showPasswordFlag), } if p.IsVerbosityDebug() { @@ -138,7 +138,7 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res if username != "" { p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) } - if model.HidePassword { + if !model.ShowPassword { p.Outputf("Password: \n") } else { p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) diff --git a/internal/cmd/logme/credentials/create/create_test.go b/internal/cmd/logme/credentials/create/create_test.go index 0ff6c8872..ff0d16fbd 100644 --- a/internal/cmd/logme/credentials/create/create_test.go +++ b/internal/cmd/logme/credentials/create/create_test.go @@ -73,6 +73,16 @@ func TestParseInput(t *testing.T) { flagValues: map[string]string{}, isValid: false, }, + { + description: "show password", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[showPasswordFlag] = "true" + }), + isValid: true, + expectedModel: fixtureInputModel(func(model *inputModel) { + model.ShowPassword = true + }), + }, { description: "project id missing", flagValues: fixtureFlagValues(func(flagValues map[string]string) { diff --git a/internal/cmd/mariadb/credentials/create/create.go b/internal/cmd/mariadb/credentials/create/create.go index 49c909c28..6668897f5 100644 --- a/internal/cmd/mariadb/credentials/create/create.go +++ b/internal/cmd/mariadb/credentials/create/create.go @@ -20,13 +20,13 @@ import ( const ( instanceIdFlag = "instance-id" - hidePasswordFlag = "hide-password" + showPasswordFlag = "show-password" ) type inputModel struct { *globalflags.GlobalFlagModel InstanceId string - HidePassword bool + ShowPassword bool } func NewCmd(p *print.Printer) *cobra.Command { @@ -40,8 +40,8 @@ func NewCmd(p *print.Printer) *cobra.Command { `Create credentials for a MariaDB instance`, "$ stackit mariadb credentials create --instance-id xxx"), examples.NewExample( - `Create credentials for a MariaDB instance and hide the password in the output`, - "$ stackit mariadb credentials create --instance-id xxx --hide-password"), + `Create credentials for a MariaDB instance and show the password in the output`, + "$ stackit mariadb credentials create --instance-id xxx --show-password"), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() @@ -86,7 +86,7 @@ func NewCmd(p *print.Printer) *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") - cmd.Flags().Bool(hidePasswordFlag, false, "Hide password in output") + cmd.Flags().Bool(showPasswordFlag, false, "Show password in output") err := flags.MarkFlagsRequired(cmd, instanceIdFlag) cobra.CheckErr(err) @@ -101,7 +101,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { model := inputModel{ GlobalFlagModel: globalFlags, InstanceId: flags.FlagToStringValue(p, cmd, instanceIdFlag), - HidePassword: flags.FlagToBoolValue(p, cmd, hidePasswordFlag), + ShowPassword: flags.FlagToBoolValue(p, cmd, showPasswordFlag), } if p.IsVerbosityDebug() { @@ -138,7 +138,7 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res if username != "" { p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) } - if model.HidePassword { + if !model.ShowPassword { p.Outputf("Password: \n") } else { p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) diff --git a/internal/cmd/mariadb/credentials/create/create_test.go b/internal/cmd/mariadb/credentials/create/create_test.go index d9604beec..9d012577b 100644 --- a/internal/cmd/mariadb/credentials/create/create_test.go +++ b/internal/cmd/mariadb/credentials/create/create_test.go @@ -73,6 +73,16 @@ func TestParseInput(t *testing.T) { flagValues: map[string]string{}, isValid: false, }, + { + description: "show password", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[showPasswordFlag] = "true" + }), + isValid: true, + expectedModel: fixtureInputModel(func(model *inputModel) { + model.ShowPassword = true + }), + }, { description: "project id missing", flagValues: fixtureFlagValues(func(flagValues map[string]string) { diff --git a/internal/cmd/opensearch/credentials/create/create.go b/internal/cmd/opensearch/credentials/create/create.go index 0a922ac5c..e02c89d9b 100644 --- a/internal/cmd/opensearch/credentials/create/create.go +++ b/internal/cmd/opensearch/credentials/create/create.go @@ -20,13 +20,13 @@ import ( const ( instanceIdFlag = "instance-id" - hidePasswordFlag = "hide-password" + showPasswordFlag = "show-password" ) type inputModel struct { *globalflags.GlobalFlagModel InstanceId string - HidePassword bool + ShowPassword bool } func NewCmd(p *print.Printer) *cobra.Command { @@ -40,8 +40,8 @@ func NewCmd(p *print.Printer) *cobra.Command { `Create credentials for an OpenSearch instance`, "$ stackit opensearch credentials create --instance-id xxx"), examples.NewExample( - `Create credentials for an OpenSearch instance and hide the password in the output`, - "$ stackit opensearch credentials create --instance-id xxx --hide-password"), + `Create credentials for an OpenSearch instance and show the password in the output`, + "$ stackit opensearch credentials create --instance-id xxx --show-password"), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() @@ -86,7 +86,7 @@ func NewCmd(p *print.Printer) *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") - cmd.Flags().Bool(hidePasswordFlag, false, "Hide password in output") + cmd.Flags().Bool(showPasswordFlag, false, "Show password in output") err := flags.MarkFlagsRequired(cmd, instanceIdFlag) cobra.CheckErr(err) @@ -101,7 +101,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { model := inputModel{ GlobalFlagModel: globalFlags, InstanceId: flags.FlagToStringValue(p, cmd, instanceIdFlag), - HidePassword: flags.FlagToBoolValue(p, cmd, hidePasswordFlag), + ShowPassword: flags.FlagToBoolValue(p, cmd, showPasswordFlag), } if p.IsVerbosityDebug() { @@ -137,7 +137,7 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res if username != "" { p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) } - if model.HidePassword { + if !model.ShowPassword { p.Outputf("Password: \n") } else { p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) diff --git a/internal/cmd/opensearch/credentials/create/create_test.go b/internal/cmd/opensearch/credentials/create/create_test.go index 77d9aa38e..cd8559b64 100644 --- a/internal/cmd/opensearch/credentials/create/create_test.go +++ b/internal/cmd/opensearch/credentials/create/create_test.go @@ -73,6 +73,16 @@ func TestParseInput(t *testing.T) { flagValues: map[string]string{}, isValid: false, }, + { + description: "show password", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[showPasswordFlag] = "true" + }), + isValid: true, + expectedModel: fixtureInputModel(func(model *inputModel) { + model.ShowPassword = true + }), + }, { description: "project id missing", flagValues: fixtureFlagValues(func(flagValues map[string]string) { diff --git a/internal/cmd/rabbitmq/credentials/create/create.go b/internal/cmd/rabbitmq/credentials/create/create.go index ee6f27a99..2da1dcfee 100644 --- a/internal/cmd/rabbitmq/credentials/create/create.go +++ b/internal/cmd/rabbitmq/credentials/create/create.go @@ -20,13 +20,13 @@ import ( const ( instanceIdFlag = "instance-id" - hidePasswordFlag = "hide-password" + showPasswordFlag = "show-password" ) type inputModel struct { *globalflags.GlobalFlagModel InstanceId string - HidePassword bool + ShowPassword bool } func NewCmd(p *print.Printer) *cobra.Command { @@ -40,8 +40,8 @@ func NewCmd(p *print.Printer) *cobra.Command { `Create credentials for a RabbitMQ instance`, "$ stackit rabbitmq credentials create --instance-id xxx"), examples.NewExample( - `Create credentials for a RabbitMQ instance and hide the password in the output`, - "$ stackit rabbitmq credentials create --instance-id xxx --hide-password"), + `Create credentials for a RabbitMQ instance and show the password in the output`, + "$ stackit rabbitmq credentials create --instance-id xxx --show-password"), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() @@ -86,7 +86,7 @@ func NewCmd(p *print.Printer) *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") - cmd.Flags().Bool(hidePasswordFlag, false, "Hide password in output") + cmd.Flags().Bool(showPasswordFlag, false, "Show password in output") err := flags.MarkFlagsRequired(cmd, instanceIdFlag) cobra.CheckErr(err) @@ -101,7 +101,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { model := inputModel{ GlobalFlagModel: globalFlags, InstanceId: flags.FlagToStringValue(p, cmd, instanceIdFlag), - HidePassword: flags.FlagToBoolValue(p, cmd, hidePasswordFlag), + ShowPassword: flags.FlagToBoolValue(p, cmd, showPasswordFlag), } if p.IsVerbosityDebug() { @@ -138,7 +138,7 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res if username != "" { p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) } - if model.HidePassword { + if !model.ShowPassword { p.Outputf("Password: \n") } else { p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) diff --git a/internal/cmd/rabbitmq/credentials/create/create_test.go b/internal/cmd/rabbitmq/credentials/create/create_test.go index 8106c2cc8..494647b00 100644 --- a/internal/cmd/rabbitmq/credentials/create/create_test.go +++ b/internal/cmd/rabbitmq/credentials/create/create_test.go @@ -73,6 +73,16 @@ func TestParseInput(t *testing.T) { flagValues: map[string]string{}, isValid: false, }, + { + description: "show password", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[showPasswordFlag] = "true" + }), + isValid: true, + expectedModel: fixtureInputModel(func(model *inputModel) { + model.ShowPassword = true + }), + }, { description: "project id missing", flagValues: fixtureFlagValues(func(flagValues map[string]string) { diff --git a/internal/cmd/redis/credentials/create/create.go b/internal/cmd/redis/credentials/create/create.go index 109c7793a..5028fd013 100644 --- a/internal/cmd/redis/credentials/create/create.go +++ b/internal/cmd/redis/credentials/create/create.go @@ -20,13 +20,13 @@ import ( const ( instanceIdFlag = "instance-id" - hidePasswordFlag = "hide-password" + showPasswordFlag = "show-password" ) type inputModel struct { *globalflags.GlobalFlagModel InstanceId string - HidePassword bool + ShowPassword bool } func NewCmd(p *print.Printer) *cobra.Command { @@ -40,8 +40,8 @@ func NewCmd(p *print.Printer) *cobra.Command { `Create credentials for a Redis instance`, "$ stackit redis credentials create --instance-id xxx"), examples.NewExample( - `Create credentials for a Redis instance and hide the password in the output`, - "$ stackit redis credentials create --instance-id xxx --hide-password"), + `Create credentials for a Redis instance and show the password in the output`, + "$ stackit redis credentials create --instance-id xxx --show-password"), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() @@ -86,7 +86,7 @@ func NewCmd(p *print.Printer) *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") - cmd.Flags().Bool(hidePasswordFlag, false, "Hide password in output") + cmd.Flags().Bool(showPasswordFlag, false, "Show password in output") err := flags.MarkFlagsRequired(cmd, instanceIdFlag) cobra.CheckErr(err) @@ -101,7 +101,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { model := inputModel{ GlobalFlagModel: globalFlags, InstanceId: flags.FlagToStringValue(p, cmd, instanceIdFlag), - HidePassword: flags.FlagToBoolValue(p, cmd, hidePasswordFlag), + ShowPassword: flags.FlagToBoolValue(p, cmd, showPasswordFlag), } if p.IsVerbosityDebug() { @@ -138,7 +138,7 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res if username != "" { p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) } - if model.HidePassword { + if !model.ShowPassword { p.Outputf("Password: \n") } else { p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) diff --git a/internal/cmd/redis/credentials/create/create_test.go b/internal/cmd/redis/credentials/create/create_test.go index 9c4707e54..bb1ee454a 100644 --- a/internal/cmd/redis/credentials/create/create_test.go +++ b/internal/cmd/redis/credentials/create/create_test.go @@ -73,6 +73,16 @@ func TestParseInput(t *testing.T) { flagValues: map[string]string{}, isValid: false, }, + { + description: "show password", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[showPasswordFlag] = "true" + }), + isValid: true, + expectedModel: fixtureInputModel(func(model *inputModel) { + model.ShowPassword = true + }), + }, { description: "project id missing", flagValues: fixtureFlagValues(func(flagValues map[string]string) {