Skip to content

Commit 78506a8

Browse files
author
Jan Sternagel
committed
Added EnumValues to the flag options
1 parent 9824515 commit 78506a8

File tree

8 files changed

+61
-12
lines changed

8 files changed

+61
-12
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const (
3131
importOnlyFlag = "import-only"
3232
purposeFlag = "purpose"
3333
protectionFlag = "protection"
34+
35+
defaultAlgorithm = kms.ALGORITHM_RSA_2048_OAEP_SHA256
36+
defaultPurpose = kms.PURPOSE_ASYMMETRIC_ENCRYPT_DECRYPT
37+
defaultProtection = kms.PROTECTION_SOFTWARE
3438
)
3539

3640
type inputModel struct {
@@ -174,13 +178,32 @@ func outputResult(p *print.Printer, model *inputModel, resp *kms.Key) error {
174178
}
175179

176180
func configureFlags(cmd *cobra.Command) {
181+
// Algorithm
182+
var algorithmFlagOptions []string
183+
for _, val := range kms.AllowedAlgorithmEnumValues {
184+
algorithmFlagOptions = append(algorithmFlagOptions, string(val))
185+
}
186+
cmd.Flags().Var(flags.EnumFlag(false, string(defaultAlgorithm), algorithmFlagOptions...), algorithmFlag, fmt.Sprintf("En-/Decryption / signing algorithm. Possible values: %q", algorithmFlagOptions))
187+
188+
// Purpose
189+
var purposeFlagOptions []string
190+
for _, val := range kms.AllowedPurposeEnumValues {
191+
purposeFlagOptions = append(purposeFlagOptions, string(val))
192+
}
193+
cmd.Flags().Var(flags.EnumFlag(false, string(defaultPurpose), purposeFlagOptions...), purposeFlag, fmt.Sprintf("Purpose of the key. Possible values: %q", purposeFlagOptions))
194+
195+
// Protection
196+
var protectionFlagOptions []string
197+
for _, val := range kms.AllowedProtectionEnumValues {
198+
protectionFlagOptions = append(protectionFlagOptions, string(val))
199+
}
200+
cmd.Flags().Var(flags.EnumFlag(false, string(defaultProtection), protectionFlagOptions...), protectionFlag, fmt.Sprintf("The underlying system that is responsible for protecting the key material. Possible values: %q", purposeFlagOptions))
201+
202+
// All further non Enum Flags
177203
cmd.Flags().Var(flags.UUIDFlag(), keyRingIdFlag, "ID of the KMS key ring")
178-
cmd.Flags().String(algorithmFlag, "", "En-/Decryption / signing algorithm")
179204
cmd.Flags().String(displayNameFlag, "", "The display name to distinguish multiple keys")
180205
cmd.Flags().String(descriptionFlag, "", "Optional description of the key")
181206
cmd.Flags().Bool(importOnlyFlag, false, "States whether versions can be created or only imported")
182-
cmd.Flags().String(purposeFlag, "", "Purpose of the key. Enum: 'symmetric_encrypt_decrypt', 'asymmetric_encrypt_decrypt', 'message_authentication_code', 'asymmetric_sign_verify' ")
183-
cmd.Flags().String(protectionFlag, "", "The underlying system that is responsible for protecting the key material. Value: 'software'")
184207

185208
err := flags.MarkFlagsRequired(cmd, keyRingIdFlag, algorithmFlag, purposeFlag, displayNameFlag, protectionFlag)
186209
cobra.CheckErr(err)

internal/cmd/beta/kms/key/create/create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
const (
1919
testRegion = "eu01"
20-
testAlgorithm = "some_rsa_2048"
20+
testAlgorithm = "rsa_2048_oaep_sha256"
2121
testDisplayName = "my-key"
2222
testPurpose = "asymmetric_encrypt_decrypt"
2323
testDescription = "my key description"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *kms.APIClie
118118

119119
func configureFlags(cmd *cobra.Command) {
120120
cmd.Flags().Var(flags.UUIDFlag(), keyRingIdFlag, "ID of the KMS Key Ring where the Key is stored")
121+
121122
err := flags.MarkFlagsRequired(cmd, keyRingIdFlag)
122123
cobra.CheckErr(err)
123124
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *kms.APIClie
9393

9494
func configureFlags(cmd *cobra.Command) {
9595
cmd.Flags().Var(flags.UUIDFlag(), keyRingIdFlag, "ID of the KMS Key Ring where the Key is stored")
96+
9697
err := flags.MarkFlagsRequired(cmd, keyRingIdFlag)
9798
cobra.CheckErr(err)
9899
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *kms.APIClie
117117

118118
func configureFlags(cmd *cobra.Command) {
119119
cmd.Flags().Var(flags.UUIDFlag(), keyRingIdFlag, "ID of the KMS Key Ring where the Key is stored")
120+
120121
err := flags.MarkFlagsRequired(cmd, keyRingIdFlag)
121122
cobra.CheckErr(err)
122123
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *kms.APIClie
111111

112112
func configureFlags(cmd *cobra.Command) {
113113
cmd.Flags().Var(flags.UUIDFlag(), keyRingIdFlag, "ID of the KMS key Ring where the key is stored")
114+
114115
err := flags.MarkFlagsRequired(cmd, keyRingIdFlag)
115116
cobra.CheckErr(err)
116117
}

internal/cmd/beta/kms/wrappingkey/create/create.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const (
3030
displayNameFlag = "name"
3131
purposeFlag = "purpose"
3232
protectionFlag = "protection"
33+
34+
defaultWrappingAlgorithm = kms.WRAPPINGALGORITHM__2048_OAEP_SHA256
35+
defaultWrappingPurpose = kms.WRAPPINGPURPOSE_ASYMMETRIC_KEY
36+
defaultProtection = kms.PROTECTION_SOFTWARE
3337
)
3438

3539
type inputModel struct {
@@ -52,7 +56,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
5256
Example: examples.Build(
5357
examples.NewExample(
5458
`Create a Symmetric KMS wrapping key`,
55-
`$ stackit beta kms wrapping-key create --keyring-id "my-keyring-id" --algorithm "rsa_2048_oaep_sha256" --name "my-wrapping-key-name" --purpose "wrap_symmetric_key" --protection "software"`),
59+
`$ stackit beta kms wrapping-key create --keyring-id "my-keyring-id" --algorithm "rsa_2048_oaep_sha256" --name "my-wrapping-key-name" --purpose "wrap_asymmetric_key" --protection "software"`),
5660
examples.NewExample(
5761
`Create an Asymmetric KMS wrapping key with a description`,
5862
`$ stackit beta kms wrapping-key create --keyring-id "my-keyring-id" --algorithm "hmac_sha256" --name "my-wrapping-key-name" --description "my-description" --purpose "wrap_asymmetric_key" --protection "software"`),
@@ -172,14 +176,32 @@ func outputResult(p *print.Printer, model *inputModel, resp *kms.WrappingKey) er
172176
}
173177

174178
func configureFlags(cmd *cobra.Command) {
179+
// Algorithm
180+
var algorithmFlagOptions []string
181+
for _, val := range kms.AllowedWrappingAlgorithmEnumValues {
182+
algorithmFlagOptions = append(algorithmFlagOptions, string(val))
183+
}
184+
cmd.Flags().Var(flags.EnumFlag(false, string(defaultWrappingAlgorithm), algorithmFlagOptions...), algorithmFlag, fmt.Sprintf("En-/Decryption / signing algorithm. Possible values: %q", algorithmFlagOptions))
185+
186+
// Purpose
187+
var purposeFlagOptions []string
188+
for _, val := range kms.AllowedWrappingPurposeEnumValues {
189+
purposeFlagOptions = append(purposeFlagOptions, string(val))
190+
}
191+
cmd.Flags().Var(flags.EnumFlag(false, string(defaultWrappingPurpose), purposeFlagOptions...), purposeFlag, fmt.Sprintf("Purpose of the wrapping key. Possible values: %q", purposeFlagOptions))
192+
193+
// Protection
194+
// backend was deprectaed in /v1beta, but protection is a required attribute with value "software"
195+
var protectionFlagOptions []string
196+
for _, val := range kms.AllowedProtectionEnumValues {
197+
protectionFlagOptions = append(protectionFlagOptions, string(val))
198+
}
199+
cmd.Flags().Var(flags.EnumFlag(false, string(defaultProtection), protectionFlagOptions...), protectionFlag, fmt.Sprintf("The underlying system that is responsible for protecting the wrapping key material. Possible values: %q", purposeFlagOptions))
200+
201+
// All further non Enum Flags
175202
cmd.Flags().Var(flags.UUIDFlag(), keyRingIdFlag, "ID of the KMS key ring")
176-
cmd.Flags().String(algorithmFlag, "", "En-/Decryption algorithm")
177203
cmd.Flags().String(displayNameFlag, "", "The display name to distinguish multiple wrapping keys")
178204
cmd.Flags().String(descriptionFlag, "", "Optional description of the wrapping key")
179-
cmd.Flags().String(purposeFlag, "", "Purpose of the wrapping key. Enum: 'wrap_symmetric_key', 'wrap_asymmetric_key' ")
180-
181-
// backend was deprectaed in /v1beta, but protection is a required attribute with value "software"
182-
cmd.Flags().String(protectionFlag, "", "Protection of the wrapping key. Value: 'software' ")
183205

184206
err := flags.MarkFlagsRequired(cmd, keyRingIdFlag, algorithmFlag, purposeFlag, displayNameFlag, protectionFlag)
185207
cobra.CheckErr(err)

internal/cmd/beta/kms/wrappingkey/create/create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717

1818
const (
1919
testRegion = "eu01"
20-
testAlgorithm = "some_rsa_2048"
20+
testAlgorithm = "rsa_2048_oaep_sha256"
2121
testDisplayName = "my-key"
22-
testPurpose = "asymmetric_encrypt_decrypt"
22+
testPurpose = "wrap_asymmetric_key"
2323
testDescription = "my key description"
2424
testProtection = "software"
2525
)

0 commit comments

Comments
 (0)