diff --git a/docs/stackit_beta_intake_user_create.md b/docs/stackit_beta_intake_user_create.md index fd7b6a93f..320acea7c 100644 --- a/docs/stackit_beta_intake_user_create.md +++ b/docs/stackit_beta_intake_user_create.md @@ -13,11 +13,14 @@ stackit beta intake user create [flags] ### Examples ``` - Create a new Intake User with required parameters - $ stackit beta intake user create --display-name intake-user --intake-id xxx --password "SuperSafepass123\!" + Create a new Intake User. The password is entered interactively in the terminal + $ stackit beta intake user create --display-name intake-user --intake-id xxx + + Create a new Intake User providing the password from a file + $ stackit beta intake user create --display-name intake-user --intake-id xxx --password @./secret.txt Create a new Intake User for the dead-letter queue with labels - $ stackit beta intake user create --display-name dlq-user --intake-id xxx --password "SuperSafepass123\!" --type dead-letter --labels "env=prod" + $ stackit beta intake user create --display-name dlq-user --intake-id xxx --password @./secret.txt --type dead-letter --labels "env=prod" ``` ### Options @@ -28,7 +31,7 @@ stackit beta intake user create [flags] -h, --help Help for "stackit beta intake user create" --intake-id string The UUID of the Intake to associate the user with --labels stringToString Labels in key=value format, separated by commas (default []) - --password string Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty. Must contain lower, upper, number, and special characters (min 12 chars) + --password string Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty. Must contain lower, upper, digits, and special characters (min 12 chars). --type string Type of user. One of 'intake' (default) or 'dead-letter' (default "intake") ``` diff --git a/docs/stackit_beta_intake_user_update.md b/docs/stackit_beta_intake_user_update.md index c33b57d06..cb01e2616 100644 --- a/docs/stackit_beta_intake_user_update.md +++ b/docs/stackit_beta_intake_user_update.md @@ -16,20 +16,23 @@ stackit beta intake user update USER_ID [flags] Update the display name of an Intake User $ stackit beta intake user update xxx --intake-id yyy --display-name "new-user-name" - Update the password and description for an Intake User - $ stackit beta intake user update xxx --intake-id yyy --password "NewSecret123\!" --description "Updated description" + Update the password interactively for an Intake User + $ stackit beta intake user update xxx --intake-id yyy --password + + Update the password and description for an Intake User from a file + $ stackit beta intake user update xxx --intake-id yyy --password @./secret.txt --description "Updated description" ``` ### Options ``` - --description string Description - --display-name string Display name - -h, --help Help for "stackit beta intake user update" - --intake-id string Intake ID - --labels stringToString Labels in key=value format, separated by commas. Example: --labels "key1=value1,key2=value2". (default []) - --password string Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty. Must contain lower, upper, number, and special characters (min 12 chars) - --type string Type of user. One of 'intake' or 'dead-letter' + --description string Description + --display-name string Display name + -h, --help Help for "stackit beta intake user update" + --intake-id string Intake ID + --labels stringToString Labels in key=value format, separated by commas. Example: --labels "key1=value1,key2=value2". (default []) + --password string[="__INTERACTIVE__"] Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). If provided without a value, you will be prompted interactively. Must contain lower, upper, digits, and special characters (min 12 chars). + --type string Type of user. One of 'intake' or 'dead-letter' ``` ### Options inherited from parent commands diff --git a/internal/cmd/beta/intake/user/create/create.go b/internal/cmd/beta/intake/user/create/create.go index 3ee5f9f46..fed2fde2e 100644 --- a/internal/cmd/beta/intake/user/create/create.go +++ b/internal/cmd/beta/intake/user/create/create.go @@ -49,11 +49,14 @@ func NewCmd(p *types.CmdParams) *cobra.Command { Args: args.NoArgs, Example: examples.Build( examples.NewExample( - `Create a new Intake User with required parameters`, - `$ stackit beta intake user create --display-name intake-user --intake-id xxx --password "SuperSafepass123\!"`), + `Create a new Intake User. The password is entered interactively in the terminal`, + `$ stackit beta intake user create --display-name intake-user --intake-id xxx`), + examples.NewExample( + `Create a new Intake User providing the password from a file`, + `$ stackit beta intake user create --display-name intake-user --intake-id xxx --password @./secret.txt`), examples.NewExample( `Create a new Intake User for the dead-letter queue with labels`, - `$ stackit beta intake user create --display-name dlq-user --intake-id xxx --password "SuperSafepass123\!" --type dead-letter --labels "env=prod"`), + `$ stackit beta intake user create --display-name dlq-user --intake-id xxx --password @./secret.txt --type dead-letter --labels "env=prod"`), ), RunE: func(cmd *cobra.Command, _ []string) error { ctx := context.Background() @@ -109,12 +112,12 @@ func configureFlags(cmd *cobra.Command, params *types.CmdParams) { cmd.Flags().String(displayNameFlag, "", "Display name") cmd.Flags().Var(flags.UUIDFlag(), intakeIdFlag, "The UUID of the Intake to associate the user with") password := flags.SecretFlag(passwordFlag, params) - cmd.Flags().Var(password, passwordFlag, password.Usage()+" Must contain lower, upper, number, and special characters (min 12 chars)") + cmd.Flags().Var(password, passwordFlag, password.Usage()+" Must contain lower, upper, digits, and special characters (min 12 chars).") cmd.Flags().String(userTypeFlag, string(intake.USERTYPE_INTAKE), "Type of user. One of 'intake' (default) or 'dead-letter'") cmd.Flags().String(descriptionFlag, "", "Description") cmd.Flags().StringToString(labelsFlag, nil, "Labels in key=value format, separated by commas") - err := flags.MarkFlagsRequired(cmd, displayNameFlag, intakeIdFlag, passwordFlag) + err := flags.MarkFlagsRequired(cmd, displayNameFlag, intakeIdFlag) cobra.CheckErr(err) } diff --git a/internal/cmd/beta/intake/user/create/create_test.go b/internal/cmd/beta/intake/user/create/create_test.go index e8babf6d0..b1b308959 100644 --- a/internal/cmd/beta/intake/user/create/create_test.go +++ b/internal/cmd/beta/intake/user/create/create_test.go @@ -152,7 +152,10 @@ func TestParseInput(t *testing.T) { flagValues: fixtureFlagValues(func(flagValues map[string]string) { delete(flagValues, passwordFlag) }), - isValid: false, + isValid: true, + expectedModel: fixtureInputModel(func(model *inputModel) { + model.Password = nil + }), }, { description: "required fields only", diff --git a/internal/cmd/beta/intake/user/update/update.go b/internal/cmd/beta/intake/user/update/update.go index 5890a806d..5d793f828 100644 --- a/internal/cmd/beta/intake/user/update/update.go +++ b/internal/cmd/beta/intake/user/update/update.go @@ -53,8 +53,11 @@ func NewCmd(p *types.CmdParams) *cobra.Command { `Update the display name of an Intake User`, `$ stackit beta intake user update xxx --intake-id yyy --display-name "new-user-name"`), examples.NewExample( - `Update the password and description for an Intake User`, - `$ stackit beta intake user update xxx --intake-id yyy --password "NewSecret123\!" --description "Updated description"`), + `Update the password interactively for an Intake User`, + `$ stackit beta intake user update xxx --intake-id yyy --password`), + examples.NewExample( + `Update the password and description for an Intake User from a file`, + `$ stackit beta intake user update xxx --intake-id yyy --password @./secret.txt --description "Updated description"`), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() @@ -82,7 +85,6 @@ func NewCmd(p *types.CmdParams) *cobra.Command { _, err = wait.UpdateIntakeUserWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.IntakeId, model.UserId).WaitWithContext(ctx) return err }) - if err != nil { return fmt.Errorf("wait for STACKIT Intake User update: %w", err) } @@ -95,12 +97,12 @@ func NewCmd(p *types.CmdParams) *cobra.Command { return cmd } -func configureFlags(cmd *cobra.Command, p *types.CmdParams) { +func configureFlags(cmd *cobra.Command, params *types.CmdParams) { cmd.Flags().Var(flags.UUIDFlag(), intakeIdFlag, "Intake ID") cmd.Flags().String(displayNameFlag, "", "Display name") cmd.Flags().String(descriptionFlag, "", "Description") - password := flags.SecretFlag(passwordFlag, p) - cmd.Flags().Var(password, passwordFlag, password.Usage()+" Must contain lower, upper, number, and special characters (min 12 chars)") + password := flags.SecretFlag(passwordFlag, params) + cmd.Flags().Var(password, passwordFlag, password.Usage()) cmd.Flags().String(userTypeFlag, "", "Type of user. One of 'intake' or 'dead-letter'") cmd.Flags().StringToString(labelsFlag, nil, `Labels in key=value format, separated by commas. Example: --labels "key1=value1,key2=value2".`) @@ -156,16 +158,11 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *intake.APIC func outputResult(p *print.Printer, model *inputModel, resp *intake.IntakeUserResponse) error { return p.OutputResult(model.OutputFormat, resp, func() error { - if resp == nil { - p.Outputf("Triggered update of Intake User for intake %q, but no user ID was returned.\n", model.IntakeId) - return nil - } - operationState := "Updated" if model.Async { operationState = "Triggered update of" } - p.Outputf("%s Intake User for intake %q. User ID: %s\n", operationState, model.IntakeId, resp.Id) + p.Outputf("%s Intake User %s\n", operationState, model.UserId) return nil }) }