Skip to content
Open
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
11 changes: 7 additions & 4 deletions docs/stackit_beta_intake_user_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
```

Expand Down
9 changes: 6 additions & 3 deletions docs/stackit_beta_intake_user_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ 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
Expand All @@ -28,7 +31,7 @@ stackit beta intake user update USER_ID [flags]
-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)
--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.
--type string Type of user. One of 'intake' or 'dead-letter'
```

Expand Down
20 changes: 15 additions & 5 deletions internal/cmd/beta/intake/user/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Comment thread
devanshcache marked this conversation as resolved.
cobra.CheckErr(err)
}

Expand All @@ -134,6 +137,13 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
Labels: flags.FlagToStringToStringPointer(p, cmd, labelsFlag),
}

if model.Password == nil || *model.Password == "" {
return nil, &cliErr.FlagValidationError{
Flag: passwordFlag,
Details: "password is required and cannot be empty",
}
}

p.DebugInputModel(model)
return &model, nil
}
Expand Down
35 changes: 28 additions & 7 deletions internal/cmd/beta/intake/user/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package update
import (
"context"
"fmt"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
"github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi/wait"

Expand Down Expand Up @@ -53,8 +55,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`),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't work:

$ stackit beta intake user update $USER_ID --intake-id $INTAKE_ID --password      
Error: flag needs an argument: --password

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@marceljk please check the proposed solution for it

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()
Expand Down Expand Up @@ -82,7 +87,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)
}
Expand All @@ -95,12 +99,24 @@ func NewCmd(p *types.CmdParams) *cobra.Command {
return cmd
}

func configureFlags(cmd *cobra.Command, p *types.CmdParams) {
type updateSecretFlag struct {
pflag.Value
}

func (f *updateSecretFlag) Set(val string) error {
if strings.TrimSpace(val) == "" {
return nil
}
return f.Value.Set(val)
}

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(&updateSecretFlag{Value: password}, passwordFlag, password.Usage())
cmd.Flag(passwordFlag).NoOptDefVal = " "
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".`)

Expand All @@ -116,13 +132,18 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
return nil, &cliErr.ProjectIdError{}
}

var password *string
if cmd.Flag(passwordFlag).Changed {
password = flags.SecretFlagToStringPointer(p, cmd, passwordFlag)
}

model := &inputModel{
GlobalFlagModel: globalFlags,
IntakeId: flags.FlagToStringValue(p, cmd, intakeIdFlag),
UserId: userId,
DisplayName: flags.FlagToStringPointer(p, cmd, displayNameFlag),
Description: flags.FlagToStringPointer(p, cmd, descriptionFlag),
Password: flags.SecretFlagToStringPointer(p, cmd, passwordFlag),
Password: password,
UserType: flags.FlagToStringPointer(p, cmd, userTypeFlag),
Labels: flags.FlagToStringToStringPointer(p, cmd, labelsFlag),
}
Expand Down
Loading