@@ -11,6 +11,7 @@ import (
1111 "github.com/stackitcloud/stackit-cli/internal/pkg/args"
1212 cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1313 "github.com/stackitcloud/stackit-cli/internal/pkg/services/kms/client"
14+ "github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
1415
1516 "github.com/stackitcloud/stackit-cli/internal/pkg/examples"
1617 "github.com/stackitcloud/stackit-cli/internal/pkg/flags"
@@ -19,6 +20,7 @@ import (
1920 "github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
2021 "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
2122 "github.com/stackitcloud/stackit-sdk-go/services/kms"
23+ "github.com/stackitcloud/stackit-sdk-go/services/kms/wait"
2224)
2325
2426const (
@@ -45,16 +47,16 @@ type inputModel struct {
4547func NewCmd (params * params.CmdParams ) * cobra.Command {
4648 cmd := & cobra.Command {
4749 Use : "create" ,
48- Short : "Creates a KMS Key " ,
49- Long : "Creates a KMS Key ." ,
50+ Short : "Creates a KMS key " ,
51+ Long : "Creates a KMS key ." ,
5052 Args : args .NoArgs ,
5153 Example : examples .Build (
5254 examples .NewExample (
53- `Create a Symmetric KMS Key ` ,
54- `$ stakit beta kms key create --key-ring "my-keyring-id" --algorithm "rsa_2048_oaep_sha256" --name "my-key-name" --purpose "symmetric_encrypt_decrypt"` ),
55+ `Create a Symmetric KMS key ` ,
56+ `$ stackit beta kms key create --key-ring "my-keyring-id" --algorithm "rsa_2048_oaep_sha256" --name "my-key-name" --purpose "symmetric_encrypt_decrypt"` ),
5557 examples .NewExample (
56- `Create a Message Authentication KMS Key ` ,
57- `$ stakit beta kms key create --key-ring "my-keyring-id" --algorithm "hmac_sha512" --name "my-key-name" --purpose "message_authentication_code"` ),
58+ `Create a Message Authentication KMS key ` ,
59+ `$ stackit beta kms key create --key-ring "my-keyring-id" --algorithm "hmac_sha512" --name "my-key-name" --purpose "message_authentication_code"` ),
5860 ),
5961 RunE : func (cmd * cobra.Command , _ []string ) error {
6062 ctx := context .Background ()
@@ -91,10 +93,20 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
9193
9294 key , err := req .Execute ()
9395 if err != nil {
94- return fmt .Errorf ("create KMS Key: %w" , err )
96+ return fmt .Errorf ("create KMS key: %w" , err )
97+ }
98+
99+ // Wait for async operation, if async mode not enabled
100+ if ! model .Async {
101+ s := spinner .New (params .Printer )
102+ s .Start ("Creating key" )
103+ _ , err = wait .CreateOrUpdateKeyWaitHandler (ctx , apiClient , model .ProjectId , model .Region , model .KeyRingId , * key .Id ).WaitWithContext (ctx )
104+ if err != nil {
105+ return fmt .Errorf ("wait for KMS key creation: %w" , err )
106+ }
107+ s .Stop ()
95108 }
96109
97- // No wait exists for the key creation
98110 return outputResult (params .Printer , model .OutputFormat , projectLabel , key )
99111 },
100112 }
@@ -159,32 +171,32 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, resp *kms
159171 case print .JSONOutputFormat :
160172 details , err := json .MarshalIndent (resp , "" , " " )
161173 if err != nil {
162- return fmt .Errorf ("marshal KMS Key : %w" , err )
174+ return fmt .Errorf ("marshal KMS key : %w" , err )
163175 }
164176 p .Outputln (string (details ))
165177 return nil
166178
167179 case print .YAMLOutputFormat :
168180 details , err := yaml .MarshalWithOptions (resp , yaml .IndentSequence (true ), yaml .UseJSONMarshaler ())
169181 if err != nil {
170- return fmt .Errorf ("marshal KMS Key : %w" , err )
182+ return fmt .Errorf ("marshal KMS key : %w" , err )
171183 }
172184 p .Outputln (string (details ))
173185 return nil
174186
175187 default :
176- p .Outputf ("Created Key for project %q. Key ID: %s\n " , projectLabel , utils .PtrString (resp .Id ))
188+ p .Outputf ("Created key for project %q. key ID: %s\n " , projectLabel , utils .PtrString (resp .Id ))
177189 return nil
178190 }
179191}
180192
181193func configureFlags (cmd * cobra.Command ) {
182- cmd .Flags ().Var (flags .UUIDFlag (), keyRingIdFlag , "ID of the KMS Key Ring " )
194+ cmd .Flags ().Var (flags .UUIDFlag (), keyRingIdFlag , "ID of the KMS key ring " )
183195 cmd .Flags ().String (algorithmFlag , "" , "En-/Decryption / signing algorithm" )
184196 cmd .Flags ().String (displayNameFlag , "" , "The display name to distinguish multiple keys" )
185- cmd .Flags ().String (descriptionFlag , "" , "Optinal description of the Key " )
197+ cmd .Flags ().String (descriptionFlag , "" , "Optional description of the key " )
186198 cmd .Flags ().Bool (importOnlyFlag , false , "States whether versions can be created or only imported" )
187- cmd .Flags ().String (purposeFlag , "" , "Purpose of the Key . Enum: 'symmetric_encrypt_decrypt', 'asymmetric_encrypt_decrypt', 'message_authentication_code', 'asymmetric_sign_verify' " )
199+ cmd .Flags ().String (purposeFlag , "" , "Purpose of the key . Enum: 'symmetric_encrypt_decrypt', 'asymmetric_encrypt_decrypt', 'message_authentication_code', 'asymmetric_sign_verify' " )
188200
189201 err := flags .MarkFlagsRequired (cmd , keyRingIdFlag , algorithmFlag , purposeFlag , displayNameFlag )
190202 cobra .CheckErr (err )
0 commit comments