Skip to content

Commit ba91df3

Browse files
committed
review fixes
1 parent 3a44de0 commit ba91df3

14 files changed

Lines changed: 54 additions & 31 deletions

File tree

‎docs/stackit_beta_intake_user_create.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ stackit beta intake user create [flags]
1313
### Examples
1414

1515
```
16-
Create a new Intake User with required parameters
16+
Create a new Intake User with required parameters, reading the password from stdin
1717
$ stackit beta intake user create --display-name intake-user --intake-id xxx --password -
1818
1919
Create a new Intake User for the dead-letter queue with labels

‎internal/cmd/beta/alb/observability-credentials/add/add.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
9393
Username: flags.FlagToStringPointer(p, cmd, usernameFlag),
9494
Displayname: flags.FlagToStringPointer(p, cmd, displaynameFlag),
9595
}
96-
pw, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, passwordFlag) //nolint:staticcheck // preserve existing functionality until deprecation period is over
96+
pw, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, passwordFlag) //nolint:staticcheck // Deprecated: preserve automatic prompting until 2027-04 (STACKITCLI-549).
9797
if err != nil {
9898
return nil, err
9999
}

‎internal/cmd/beta/alb/observability-credentials/add/add_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func TestParseInput(t *testing.T) {
118118
}),
119119
},
120120
{
121+
// Deprecated compatibility behavior; remove this case when automatic prompting is removed in 2027-04 (STACKITCLI-549).
121122
description: "password from implicit stdin",
122123
stdin: "stdin-pw\n",
123124
flagValues: fixtureFlagValues(func(flagValues map[string]string) {

‎internal/cmd/beta/cdn/distribution/create/create.go‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,18 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
219219
bucketURL := flags.FlagToStringValue(p, cmd, flagBucketURL)
220220
accessKeyID := flags.FlagToStringValue(p, cmd, flagBucketCredentialsAccessKeyID)
221221
region := flags.FlagToStringValue(p, cmd, flagBucketRegion)
222-
password, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, flagBucketPassword) //nolint:staticcheck // preserve existing functionality until deprecation period is over
222+
password, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, flagBucketPassword) //nolint:staticcheck // Deprecated: preserve automatic prompting until 2027-04 (STACKITCLI-549).
223223
if err != nil {
224224
return nil, err
225225
}
226+
if password == nil || *password == "" {
227+
return nil, fmt.Errorf("--%s must not be empty", flagBucketPassword)
228+
}
226229

227230
bucket = &bucketInputModel{
228231
URL: bucketURL,
229232
AccessKeyID: accessKeyID,
230-
Password: utils.PtrString(password),
233+
Password: *password,
231234
Region: region,
232235
}
233236
}
@@ -243,11 +246,14 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
243246
Username: flags.FlagToStringValue(p, cmd, flagLokiUsername),
244247
PushURL: flags.FlagToStringValue(p, cmd, flagLokiPushURL),
245248
}
246-
password, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, flagLokiPassword) //nolint:staticcheck // preserve existing functionality until deprecation period is over
249+
password, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, flagLokiPassword) //nolint:staticcheck // Deprecated: preserve automatic prompting until 2027-04 (STACKITCLI-549).
247250
if err != nil {
248251
return nil, err
249252
}
250-
loki.Password = utils.PtrString(password)
253+
if password == nil || *password == "" {
254+
return nil, fmt.Errorf("--%s must not be empty", flagLokiPassword)
255+
}
256+
loki.Password = *password
251257
}
252258

253259
optimizer := flags.FlagToBoolValue(p, cmd, flagOptimizer)

‎internal/cmd/beta/cdn/distribution/create/create_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ func TestParseInput(t *testing.T) {
296296
),
297297
},
298298
{
299+
// Deprecated compatibility behavior; remove this case when automatic prompting is removed in 2027-04 (STACKITCLI-549).
299300
description: "bucket backend password implicit stdin",
300301
flagValues: fixtureFlagValues(
301302
flagsBucketBackend(),
@@ -461,6 +462,7 @@ func TestParseInput(t *testing.T) {
461462
),
462463
},
463464
{
465+
// Deprecated compatibility behavior; remove this case when automatic prompting is removed in 2027-04 (STACKITCLI-549).
464466
description: "loki password implicit stdin",
465467
flagValues: fixtureFlagValues(
466468
flagsLoki(),

‎internal/cmd/beta/cdn/distribution/update/update.go‎

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
164164

165165
regions := flagRegions.Get()
166166

167+
// Reject passwords that would otherwise be silently omitted from the API payload,
168+
// before resolving secrets or reading stdin.
169+
if cmd.Flags().Changed(flagBucketPassword) && (!flags.FlagToBoolValue(p, cmd, flagBucket) || flags.FlagToStringValue(p, cmd, flagBucketCredentialsAccessKeyID) == "") {
170+
return nil, fmt.Errorf("--%s requires --%s and a non-empty --%s", flagBucketPassword, flagBucket, flagBucketCredentialsAccessKeyID)
171+
}
172+
if cmd.Flags().Changed(flagLokiPassword) && (!flags.FlagToBoolValue(p, cmd, flagLoki) || flags.FlagToStringValue(p, cmd, flagLokiUsername) == "") {
173+
return nil, fmt.Errorf("--%s requires --%s and a non-empty --%s", flagLokiPassword, flagLoki, flagLokiUsername)
174+
}
175+
167176
var http *httpInputModel
168177
if flags.FlagToBoolValue(p, cmd, flagHTTP) {
169178
originURL := flags.FlagToStringValue(p, cmd, flagHTTPOriginURL)
@@ -192,23 +201,22 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
192201
bucketURL := flags.FlagToStringValue(p, cmd, flagBucketURL)
193202
accessKeyID := flags.FlagToStringValue(p, cmd, flagBucketCredentialsAccessKeyID)
194203
region := flags.FlagToStringValue(p, cmd, flagBucketRegion)
195-
// Only credential replacements need an implicit password. Other bucket
196-
// patches must not read stdin when the password is omitted.
197-
resolvePassword := flags.ResolveSecretFlag
198-
if accessKeyID != "" {
199-
resolvePassword = flags.ResolveSecretFlagWithAutoPrompt //nolint:staticcheck // preserve existing functionality until deprecation period is over
200-
}
201-
password, err := resolvePassword(p, cmd, flagBucketPassword)
202-
if err != nil {
203-
return nil, err
204-
}
205-
206204
bucket = &bucketInputModel{
207205
URL: bucketURL,
208206
AccessKeyID: accessKeyID,
209-
Password: utils.PtrString(password),
210207
Region: region,
211208
}
209+
// Only credential replacements need a password. Other bucket patches must not read stdin.
210+
if accessKeyID != "" {
211+
password, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, flagBucketPassword) //nolint:staticcheck // Deprecated: preserve automatic prompting until 2027-04 (STACKITCLI-549).
212+
if err != nil {
213+
return nil, err
214+
}
215+
if password == nil || *password == "" {
216+
return nil, fmt.Errorf("--%s must not be empty", flagBucketPassword)
217+
}
218+
bucket.Password = *password
219+
}
212220
}
213221

214222
blockedCountries := flags.FlagToStringSliceValue(p, cmd, flagBlockedCountries)
@@ -223,15 +231,16 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
223231
PushURL: flags.FlagToStringValue(p, cmd, flagLokiPushURL),
224232
}
225233
// A push URL patch does not replace credentials unless a username is set.
226-
resolvePassword := flags.ResolveSecretFlag
227234
if loki.Username != "" {
228-
resolvePassword = flags.ResolveSecretFlagWithAutoPrompt //nolint:staticcheck // preserve existing functionality until deprecation period is over
229-
}
230-
password, err := resolvePassword(p, cmd, flagLokiPassword)
231-
if err != nil {
232-
return nil, err
235+
password, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, flagLokiPassword) //nolint:staticcheck // Deprecated: preserve automatic prompting until 2027-04 (STACKITCLI-549).
236+
if err != nil {
237+
return nil, err
238+
}
239+
if password == nil || *password == "" {
240+
return nil, fmt.Errorf("--%s must not be empty", flagLokiPassword)
241+
}
242+
loki.Password = *password
233243
}
234-
loki.Password = utils.PtrString(password)
235244
}
236245

237246
var optimizer *bool

‎internal/cmd/beta/cdn/distribution/update/update_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ func TestParseInput(t *testing.T) {
184184
}),
185185
},
186186
{
187+
// Deprecated compatibility behavior; remove this case when automatic prompting is removed in 2027-04 (STACKITCLI-549).
187188
description: "loki password implicit stdin",
188189
argValues: []string{testDistributionID},
189190
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
@@ -289,6 +290,7 @@ func TestParseInput(t *testing.T) {
289290
),
290291
},
291292
{
293+
// Deprecated compatibility behavior; remove this case when automatic prompting is removed in 2027-04 (STACKITCLI-549).
292294
description: "bucket password implicit stdin",
293295
argValues: []string{testDistributionID},
294296
flagValues: fixtureFlagValues(

‎internal/cmd/beta/intake/user/create/create.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewCmd(p *types.CmdParams) *cobra.Command {
4949
Args: args.NoArgs,
5050
Example: examples.Build(
5151
examples.NewExample(
52-
`Create a new Intake User with required parameters`,
52+
`Create a new Intake User with required parameters, reading the password from stdin`,
5353
`$ stackit beta intake user create --display-name intake-user --intake-id xxx --password -`),
5454
examples.NewExample(
5555
`Create a new Intake User for the dead-letter queue with labels`,
@@ -132,7 +132,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
132132
Description: flags.FlagToStringPointer(p, cmd, descriptionFlag),
133133
Labels: flags.FlagToStringToStringPointer(p, cmd, labelsFlag),
134134
}
135-
pw, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, passwordFlag) //nolint:staticcheck // preserve existing functionality until deprecation period is over
135+
pw, err := flags.ResolveSecretFlag(p, cmd, passwordFlag)
136136
if err != nil {
137137
return nil, err
138138
}

‎internal/cmd/beta/intake/user/create/create_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func TestParseInput(t *testing.T) {
166166
globalflags.RegionFlag: testRegion,
167167
displayNameFlag: testDisplayName,
168168
intakeIdFlag: testIntakeId,
169-
passwordFlag: "@pw.txt",
169+
passwordFlag: "@" + testPwFile,
170170
userTypeFlag: testUserType,
171171
},
172172
isValid: true,

‎internal/cmd/load-balancer/observability-credentials/add/add.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
109109
DisplayName: flags.FlagToStringPointer(p, cmd, displayNameFlag),
110110
Username: flags.FlagToStringPointer(p, cmd, usernameFlag),
111111
}
112-
pw, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, passwordFlag) //nolint:staticcheck // preserve existing functionality until deprecation period is over
112+
pw, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, passwordFlag) //nolint:staticcheck // Deprecated: preserve automatic prompting until 2027-04 (STACKITCLI-549).
113113
if err != nil {
114114
return nil, err
115115
}

0 commit comments

Comments
 (0)