Skip to content

Commit 26490c9

Browse files
author
Jan Sternagel
committed
removed uuid validation in parseInput
1 parent 6581f82 commit 26490c9

File tree

3 files changed

+29
-55
lines changed

3 files changed

+29
-55
lines changed

internal/cmd/beta/kms/key/delete/delete.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
kmsUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/kms/utils"
1919

2020
"github.com/stackitcloud/stackit-cli/internal/pkg/services/kms/client"
21-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
2221
"github.com/stackitcloud/stackit-sdk-go/services/kms"
2322
)
2423

@@ -36,12 +35,12 @@ type inputModel struct {
3635
func NewCmd(params *params.CmdParams) *cobra.Command {
3736
cmd := &cobra.Command{
3837
Use: "delete",
39-
Short: "Deletes a KMS Key",
40-
Long: "Deletes a KMS Key inside a specific Key Ring.",
38+
Short: "Deletes a KMS key",
39+
Long: "Deletes a KMS key inside a specific key ring.",
4140
Args: args.NoArgs,
4241
Example: examples.Build(
4342
examples.NewExample(
44-
`Delete a KMS Key "my-key-id" inside the Key Ring "my-key-ring-id"`,
43+
`Delete a KMS key "my-key-id" inside the key ring "my-key-ring-id"`,
4544
`$ stackit beta kms keyring delete --key-ring "my-key-ring-id" --key "my-key-id"`),
4645
),
4746
RunE: func(cmd *cobra.Command, _ []string) error {
@@ -75,7 +74,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
7574
req := buildRequest(ctx, model, apiClient)
7675
err = req.Execute()
7776
if err != nil {
78-
return fmt.Errorf("delete KMS Key: %w", err)
77+
return fmt.Errorf("delete KMS key: %w", err)
7978
}
8079

8180
// Don't wait for a month until the deletion was performed.
@@ -99,22 +98,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
9998
return nil, &errors.ProjectIdError{}
10099
}
101100

102-
keyRingId := flags.FlagToStringValue(p, cmd, keyRingIdFlag)
103-
keyId := flags.FlagToStringValue(p, cmd, keyIdFlag)
104-
105-
// Validate the uuid format of the IDs
106-
errKeyRing := utils.ValidateUUID(keyRingId)
107-
errKey := utils.ValidateUUID(keyId)
108-
if errKeyRing != nil || errKey != nil {
109-
return nil, &errors.DSAInputPlanError{
110-
Cmd: cmd,
111-
}
112-
}
113-
114101
model := inputModel{
115102
GlobalFlagModel: globalFlags,
116-
KeyRingId: keyRingId,
117-
KeyId: keyId,
103+
KeyRingId: flags.FlagToStringValue(p, cmd, keyRingIdFlag),
104+
KeyId: flags.FlagToStringValue(p, cmd, keyIdFlag),
118105
}
119106

120107
if p.IsVerbosityDebug() {
@@ -182,7 +169,7 @@ func outputResult(p *print.Printer, outputFormat, keyId, keyName string, deletio
182169
return nil
183170

184171
default:
185-
p.Outputf("Deletion of KMS Key %q scheduled successfully for the deletion date: %q\n", keyName, deletionDate)
172+
p.Outputf("Deletion of KMS key %q scheduled successfully for the deletion date: %q\n", keyName, deletionDate)
186173
return nil
187174
}
188175
}

internal/cmd/beta/kms/key/importKey/importKey.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ type inputModel struct {
4141
func NewCmd(params *params.CmdParams) *cobra.Command {
4242
cmd := &cobra.Command{
4343
Use: "import",
44-
Short: "Import a KMS Key Version",
44+
Short: "Import a KMS key",
4545
Long: "Import a new version to the given KMS key.",
4646
Args: args.NoArgs,
4747
Example: examples.Build(
4848
examples.NewExample(
49-
`Import a new version for the given KMS Key "my-key"`,
49+
`Import a new version for the given KMS key "my-key"`,
5050
`$ stakit beta kms key import --key-ring "my-keyring-id" --key "my-key-id" --wrapped-key "base64-encoded-wrapped-key-material" --wrapping-key-id "my-wrapping-key-id"`),
5151
),
5252
RunE: func(cmd *cobra.Command, _ []string) error {
@@ -64,17 +64,17 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
6464

6565
keyName, err := kmsUtils.GetKeyName(ctx, apiClient, model.ProjectId, model.Region, model.KeyRingId, model.KeyId)
6666
if err != nil {
67-
params.Printer.Debug(print.ErrorLevel, "get Key name: %v", err)
67+
params.Printer.Debug(print.ErrorLevel, "get key name: %v", err)
6868
keyName = model.KeyId
6969
}
7070
keyRingName, err := kmsUtils.GetKeyRingName(ctx, apiClient, model.ProjectId, model.KeyRingId, model.Region)
7171
if err != nil {
72-
params.Printer.Debug(print.ErrorLevel, "get Key Ring name: %v", err)
72+
params.Printer.Debug(print.ErrorLevel, "get key ring name: %v", err)
7373
keyRingName = model.KeyRingId
7474
}
7575

7676
if !model.AssumeYes {
77-
prompt := fmt.Sprintf("Are you sure you want to import a new version for the KMS Key %q inside the Key Ring %q?", keyName, keyRingName)
77+
prompt := fmt.Sprintf("Are you sure you want to import a new version for the KMS Key %q inside the key ring %q?", keyName, keyRingName)
7878
err = params.Printer.PromptForConfirmation(prompt)
7979
if err != nil {
8080
return err
@@ -89,10 +89,9 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
8989

9090
keyVersion, err := req.Execute()
9191
if err != nil {
92-
return fmt.Errorf("import KMS Key: %w", err)
92+
return fmt.Errorf("import KMS key: %w", err)
9393
}
9494

95-
// No wait exists for the wrapped key import
9695
return outputResult(params.Printer, model.OutputFormat, keyRingName, keyName, keyVersion)
9796
},
9897
}
@@ -160,30 +159,30 @@ func outputResult(p *print.Printer, outputFormat, keyRingName, keyName string, r
160159
case print.JSONOutputFormat:
161160
details, err := json.MarshalIndent(resp, "", " ")
162161
if err != nil {
163-
return fmt.Errorf("marshal KMS Key: %w", err)
162+
return fmt.Errorf("marshal KMS key: %w", err)
164163
}
165164
p.Outputln(string(details))
166165
return nil
167166

168167
case print.YAMLOutputFormat:
169168
details, err := yaml.MarshalWithOptions(resp, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
170169
if err != nil {
171-
return fmt.Errorf("marshal KMS Key: %w", err)
170+
return fmt.Errorf("marshal KMS key: %w", err)
172171
}
173172
p.Outputln(string(details))
174173
return nil
175174

176175
default:
177-
p.Outputf("Imported a new version for the Key %q inside the Key Ring %q\n", keyName, keyRingName)
176+
p.Outputf("Imported a new version for the key %q inside the key ring %q\n", keyName, keyRingName)
178177
return nil
179178
}
180179
}
181180

182181
func configureFlags(cmd *cobra.Command) {
183-
cmd.Flags().Var(flags.UUIDFlag(), keyRingIdFlag, "ID of the KMS Key Ring")
184-
cmd.Flags().Var(flags.UUIDFlag(), keyIdFlag, "ID of the KMS Key")
182+
cmd.Flags().Var(flags.UUIDFlag(), keyRingIdFlag, "ID of the KMS key ring")
183+
cmd.Flags().Var(flags.UUIDFlag(), keyIdFlag, "ID of the KMS key")
185184
cmd.Flags().String(wrappedKeyFlag, "", "The wrapped key material that has to be imported. Encoded in base64")
186-
cmd.Flags().Var(flags.UUIDFlag(), wrappingKeyIdFlag, "he unique id of the wrapping key the key material has been wrapped with")
185+
cmd.Flags().Var(flags.UUIDFlag(), wrappingKeyIdFlag, "The unique id of the wrapping key the key material has been wrapped with")
187186

188187
err := flags.MarkFlagsRequired(cmd, keyRingIdFlag, keyIdFlag, wrappedKeyFlag, wrappingKeyIdFlag)
189188
cobra.CheckErr(err)

internal/cmd/beta/kms/key/rotate/rotate.go

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
4040
Args: args.NoArgs,
4141
Example: examples.Build(
4242
examples.NewExample(
43-
`Rotate a KMS Key "my-key-id" and increase it's version inside the Key Ring "my-key-ring-id".`,
44-
`$ stackit beta kms keyring rotate --key-ring "my-key-ring-id" --key "my-key-id"`),
43+
`Rotate a KMS key "my-key-id" and increase it's version inside the key ring "my-key-ring-id".`,
44+
`$ stackit beta kms key rotate --key-ring "my-key-ring-id" --key "my-key-id"`),
4545
),
4646
RunE: func(cmd *cobra.Command, _ []string) error {
4747
ctx := context.Background()
@@ -74,7 +74,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
7474
req := buildRequest(ctx, model, apiClient)
7575
resp, err := req.Execute()
7676
if err != nil {
77-
return fmt.Errorf("rotate KMS Key: %w", err)
77+
return fmt.Errorf("rotate KMS key: %w", err)
7878
}
7979

8080
return outputResult(params.Printer, model.OutputFormat, resp)
@@ -91,22 +91,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
9191
return nil, &errors.ProjectIdError{}
9292
}
9393

94-
keyRingId := flags.FlagToStringValue(p, cmd, keyRingIdFlag)
95-
keyId := flags.FlagToStringValue(p, cmd, keyIdFlag)
96-
97-
// Validate the uuid format of the IDs
98-
errKeyRing := utils.ValidateUUID(keyRingId)
99-
errKey := utils.ValidateUUID(keyId)
100-
if errKeyRing != nil || errKey != nil {
101-
return nil, &errors.DSAInputPlanError{
102-
Cmd: cmd,
103-
}
104-
}
105-
10694
model := inputModel{
10795
GlobalFlagModel: globalFlags,
108-
KeyRingId: keyRingId,
109-
KeyId: keyId,
96+
KeyRingId: flags.FlagToStringValue(p, cmd, keyRingIdFlag),
97+
KeyId: flags.FlagToStringValue(p, cmd, keyIdFlag),
11098
}
11199

112100
if p.IsVerbosityDebug() {
@@ -127,8 +115,8 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *kms.APIClie
127115
}
128116

129117
func configureFlags(cmd *cobra.Command) {
130-
cmd.Flags().Var(flags.UUIDFlag(), keyRingIdFlag, "ID of the KMS Key Ring where the Key is stored")
131-
cmd.Flags().Var(flags.UUIDFlag(), keyIdFlag, "ID of the actual Key")
118+
cmd.Flags().Var(flags.UUIDFlag(), keyRingIdFlag, "ID of the KMS key Ring where the key is stored")
119+
cmd.Flags().Var(flags.UUIDFlag(), keyIdFlag, "ID of the actual key")
132120
err := flags.MarkFlagsRequired(cmd, keyRingIdFlag, keyIdFlag)
133121
cobra.CheckErr(err)
134122
}
@@ -142,21 +130,21 @@ func outputResult(p *print.Printer, outputFormat string, resp *kms.Version) erro
142130
case print.JSONOutputFormat:
143131
details, err := json.MarshalIndent(resp, "", " ")
144132
if err != nil {
145-
return fmt.Errorf("marshal KMS Key Version: %w", err)
133+
return fmt.Errorf("marshal KMS key version: %w", err)
146134
}
147135
p.Outputln(string(details))
148136
return nil
149137

150138
case print.YAMLOutputFormat:
151139
details, err := yaml.MarshalWithOptions(resp, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
152140
if err != nil {
153-
return fmt.Errorf("marshal KMS Key Version: %w", err)
141+
return fmt.Errorf("marshal KMS key version: %w", err)
154142
}
155143
p.Outputln(string(details))
156144
return nil
157145

158146
default:
159-
p.Outputf("Rotated Key %s\n", utils.PtrString(resp.KeyId))
147+
p.Outputf("Rotated key %s\n", utils.PtrString(resp.KeyId))
160148
return nil
161149
}
162150
}

0 commit comments

Comments
 (0)