Skip to content

Commit d8a168a

Browse files
authored
feat: Update kms (#2994)
* generate kms * adjusted waiters * adjusted example * Update CHANGELOG.md
1 parent 76d2ee6 commit d8a168a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1040
-180
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@
7070
- Add `required:"true"` tags to model structs
7171
- `serviceaccount`: [v0.9.0](services/serviceaccount/CHANGELOG.md#v090)
7272
- Add `required:"true"` tags to model structs
73+
- `kms` [v0.3.0](services/kms/CHANGELOG.md#v030)
74+
- **Feature:** New method `DeleteWrappingKey`
75+
- **Breaking change:** Enum `KEYSTATE_VERSION_NOT_READY` removed. Use instead `KEYSTATE_CREATING`
76+
- **Breaking change:** Enum `VERSIONSTATE_KEY_MATERIAL_NOT_READY` removed. Use instead `VERSIONSTATE_CREATING`
77+
- **Breaking change:** Enum `WRAPPINGKEYSTATE_KEY_MATERIAL_NOT_READY` removed. Use instead `WRAPPINGKEYSTATE_CREATING`
78+
- **Feature:** New enums for `KEYSTATE`, `KEYRINGSTATE`, `VERSIONSTATE` and `WRAPPINGKEYSTATE`
79+
- **Feature:** Add `required:"true"` tags to model structs
7380

7481
## Release (2025-06-16)
7582
- `iaas`:

examples/kms/kms.go

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"os"
7-
"time"
87

98
"github.com/stackitcloud/stackit-sdk-go/core/utils"
109
"github.com/stackitcloud/stackit-sdk-go/services/kms"
@@ -19,63 +18,67 @@ func main() {
1918
// Create a new API client, that uses default authentication and configuration
2019
kmsClient, err := kms.NewAPIClient()
2120
if err != nil {
22-
fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err)
21+
fmt.Fprintf(os.Stderr, "[kms API] Creating API client: %v\n", err)
2322
os.Exit(1)
2423
}
25-
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
26-
defer cancel()
2724

28-
keyRing, err := kmsClient.CreateKeyRing(ctx, projectId, region).CreateKeyRingPayload(kms.CreateKeyRingPayload{
29-
Description: utils.Ptr("a test keyring"),
30-
DisplayName: utils.Ptr("test-keyring"),
31-
}).Execute()
25+
ctx := context.Background()
26+
27+
keyRing, err := kmsClient.CreateKeyRing(ctx, projectId, region).
28+
CreateKeyRingPayload(
29+
kms.CreateKeyRingPayload{
30+
Description: utils.Ptr("a test keyring"),
31+
DisplayName: utils.Ptr("test-keyring"),
32+
},
33+
).Execute()
3234
if err != nil {
33-
fmt.Fprintf(os.Stderr, "cannot create keyring: %v\n", err)
34-
return
35+
fmt.Fprintf(os.Stderr, "[kms API] Cannot create keyring: %v\n", err)
36+
os.Exit(1)
3537
}
3638

37-
key, err := kmsClient.CreateKey(ctx, projectId, region, *keyRing.Id).CreateKeyPayload(kms.CreateKeyPayload{
38-
Algorithm: kms.ALGORITHM_AES_256_GCM.Ptr(),
39-
Backend: kms.BACKEND_SOFTWARE.Ptr(),
40-
Description: utils.Ptr("A test key"),
41-
DisplayName: utils.Ptr("test-key"),
42-
Purpose: kms.PURPOSE_SYMMETRIC_ENCRYPT_DECRYPT.Ptr(),
43-
}).Execute()
39+
// Create a key
40+
key, err := kmsClient.CreateKey(ctx, projectId, region, *keyRing.Id).
41+
CreateKeyPayload(
42+
kms.CreateKeyPayload{
43+
Algorithm: kms.ALGORITHM_AES_256_GCM.Ptr(),
44+
Backend: kms.BACKEND_SOFTWARE.Ptr(),
45+
Description: utils.Ptr("A test key"),
46+
DisplayName: utils.Ptr("test-key"),
47+
Purpose: kms.PURPOSE_SYMMETRIC_ENCRYPT_DECRYPT.Ptr(),
48+
}).Execute()
4449
if err != nil {
45-
fmt.Fprintf(os.Stderr, "cannot create key: %v\n", err)
46-
return
50+
fmt.Fprintf(os.Stderr, "[kms API] Cannot create key: %v\n", err)
51+
os.Exit(1)
4752
}
48-
if err := wait.CreateOrUpdateKeyWaitHandler(ctx, kmsClient, projectId, region, *key.KeyRingId, *key.Id); err != nil {
49-
fmt.Fprintf(os.Stderr, "failed to create key: %v", err)
50-
return
53+
fmt.Printf("[kms API] Triggered creation of key: %v\n", *key.Id)
54+
55+
// Wait for creation of key
56+
key, err = wait.CreateOrUpdateKeyWaitHandler(ctx, kmsClient, projectId, region, *key.KeyRingId, *key.Id).WaitWithContext(ctx)
57+
if err != nil {
58+
fmt.Fprintf(os.Stderr, "[kms API] Error when waiting for creation: %v\n", err)
59+
os.Exit(1)
5160
}
52-
fmt.Printf("created key %s\n", *key.Id)
61+
fmt.Printf("[kms API] Created key %s\n", *key.Id)
5362

63+
// List key rings
5464
keyRings, err := kmsClient.ListKeyRingsExecute(ctx, projectId, region)
5565
if err != nil {
56-
fmt.Fprintf(os.Stderr, "cannot list keyrings: %v\n", err)
57-
return
66+
fmt.Fprintf(os.Stderr, "[kms API] Cannot list keyrings: %v\n", err)
67+
os.Exit(1)
5868
}
69+
5970
if keyrings := keyRings.KeyRings; keyrings != nil {
60-
if len(*keyrings) == 0 {
61-
fmt.Printf("no keyrings defined\n")
62-
} else {
63-
for _, keyring := range *keyrings {
64-
fmt.Printf("id=%s displayname=%s status=%s\n", *keyring.Id, *keyring.DisplayName, *keyring.State)
65-
keylist, err := kmsClient.ListKeysExecute(ctx, projectId, region, *key.KeyRingId)
66-
if err != nil {
67-
fmt.Fprintf(os.Stderr, "cannot list keys: %v", err)
68-
return
69-
}
70-
if keys := keylist.Keys; keys != nil {
71-
if len(*keys) == 0 {
72-
fmt.Printf("no keys\n")
73-
} else {
74-
for _, key := range *keys {
75-
fmt.Printf("key id=%s key name=%s key status=%s\n", *key.Id, *key.DisplayName, *key.State)
76-
}
77-
}
78-
}
71+
fmt.Printf("[kms API] Number of keyrings: %v\n", len(*keyrings))
72+
73+
for _, keyring := range *keyrings {
74+
keylist, err := kmsClient.ListKeysExecute(ctx, projectId, region, *keyring.Id)
75+
if err != nil {
76+
fmt.Fprintf(os.Stderr, "[kms API] Cannot list keys: %v\n", err)
77+
os.Exit(1)
78+
}
79+
80+
if keys := keylist.Keys; keys != nil {
81+
fmt.Printf("[kms API] Keys in Keyring %s: %v\n", *keyring.Id, len(*keys))
7982
}
8083
}
8184
}

services/kms/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v0.3.0
2+
- **Feature:** New method `DeleteWrappingKey`
3+
- **Breaking change:** Enum `KEYSTATE_VERSION_NOT_READY` removed. Use instead `KEYSTATE_CREATING`
4+
- **Breaking change:** Enum `VERSIONSTATE_KEY_MATERIAL_NOT_READY` removed. Use instead `VERSIONSTATE_CREATING`
5+
- **Breaking change:** Enum `WRAPPINGKEYSTATE_KEY_MATERIAL_NOT_READY` removed. Use instead `WRAPPINGKEYSTATE_CREATING`
6+
- **Feature:** New enums for `KEYSTATE`, `KEYRINGSTATE`, `VERSIONSTATE` and `WRAPPINGKEYSTATE`
7+
- **Feature:** Add `required:"true"` tags to model structs
8+
19
## v0.2.0 (2025-05-15)
210
- **Breaking change:** Introduce interfaces for `APIClient` and the request structs
311

services/kms/api_default.go

Lines changed: 189 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)