Repository navigation
fix(intake): enable interactive and file-based password input for intake user #1574
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
Open
devanshcache
wants to merge
9
commits into
stackitcloud:main
Choose a base branch
from
stackit-intake:fix/intake-user-password-handling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
59e2195
fix(intake): enable interactive and file-based password input for int…
9d762eb
Merge branch 'stackitcloud:main' into fix/intake-user-password-handling
devanshcache 3eae549
make generate-docs
7badd90
updated to internal secret pkg
a2e0484
make generate-docs
fadf239
Merge branch 'main' into fix/intake-user-password-handling
devanshcache 74ebc51
fix(intake/user): address review comments on user create and update
6ba6437
make generate-docs
da8f37a
Update user create unit test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
||
|
|
@@ -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`), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
|
@@ -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) | ||
| } | ||
|
|
@@ -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".`) | ||
|
|
||
|
|
@@ -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), | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.