Skip to content

Commit 3e76b81

Browse files
Generator: Update SDK /services/postgresflex (#8450)
* feat(postgresflex): add example and wait handlers, update changelogs, bump version relates to STACKITSDK-468
1 parent c263096 commit 3e76b81

206 files changed

Lines changed: 22064 additions & 306 deletions

File tree

Some content is hidden

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

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
- `v1api`:
5555
- **Improvement**: Improve http error handling
5656
- `postgresflex`:
57+
- [v1.11.0](services/postgresflex/CHANGELOG.md#v1110)
58+
- `v3beta1api`: **New:** New package which can be used for communication with the PostgreSQL Flex v3beta1 API
59+
- `v1api`: **Deprecated:** `v1api` is deprecated, use instead `v2api`
60+
- `v3alpha1api`: **Deprecated:** `v3alpha1api` is deprecated, use instead `v3beta1api`
5761
- [v1.10.0](services/postgresflex/CHANGELOG.md#v1100)
5862
- `v3alpha1api`: Align package to latest API specification
5963
- `rabbitmq`:

examples/postgresflex/go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ go 1.25
55
// This is not needed in production. This is only here to point the golangci linter to the local version instead of the last release on GitHub.
66
replace github.com/stackitcloud/stackit-sdk-go/services/postgresflex => ../../services/postgresflex
77

8-
require github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.10.0
8+
require (
9+
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
10+
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.10.0
11+
)
912

1013
require (
1114
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
1215
github.com/google/uuid v1.6.0 // indirect
13-
github.com/stackitcloud/stackit-sdk-go/core v0.26.0 // indirect
1416
)
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/stackitcloud/stackit-sdk-go/core/utils"
9+
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3beta1api"
10+
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3beta1api/wait"
11+
)
12+
13+
func main() {
14+
const (
15+
projectId = "PROJECT_ID" // the uuid of your STACKIT project
16+
region = "eu01" // Specify the region
17+
// Specify instance configuration options
18+
version = "VERSION"
19+
// You can find a valid flavorId, by calling this API https://docs.api.stackit.cloud/documentation/postgres-flex-service/version/v3alpha1#tag/Flavor/operation/getFlavorsRequest
20+
// or using postgresflexClient.DefaultAPI.ListFlavors(ctx, projectId, region).Execute()
21+
flavorId = "FLAVOR_ID"
22+
)
23+
24+
ctx := context.Background()
25+
26+
// Create a new API client, that uses default authentication and configuration
27+
postgresflexClient, err := postgresflex.NewAPIClient()
28+
if err != nil {
29+
fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err)
30+
os.Exit(1)
31+
}
32+
33+
// List the PostgreSQL Flex instances for your project
34+
getInstancesResp, err := postgresflexClient.DefaultAPI.ListInstances(ctx, projectId, region).Execute()
35+
36+
if err != nil {
37+
fmt.Fprintf(os.Stderr, "Error when calling `ListInstances`: %v\n", err)
38+
os.Exit(1)
39+
}
40+
fmt.Printf("Number of instances: %v\n", len(getInstancesResp.Instances))
41+
42+
// Create an instance
43+
createInstancePayload := postgresflex.CreateInstancePayload{
44+
Name: "my-instance",
45+
FlavorId: flavorId,
46+
Version: version,
47+
BackupSchedule: "0 2 * * *",
48+
RetentionDays: *postgresflex.NewNullableInt32(utils.Ptr(int32(35))),
49+
Network: postgresflex.InstanceNetworkCreate{
50+
Acl: []string{"1.2.3.4/32"},
51+
},
52+
Storage: postgresflex.StorageCreate{
53+
Class: utils.Ptr("premium-perf2-stackit"),
54+
Size: 5,
55+
},
56+
}
57+
instance, err := postgresflexClient.DefaultAPI.CreateInstance(ctx, projectId, region).CreateInstancePayload(createInstancePayload).Execute()
58+
if err != nil {
59+
fmt.Fprintf(os.Stderr, "Error creating PostgreSQL Flex instance: %v\n", err)
60+
os.Exit(1)
61+
}
62+
fmt.Printf("Triggered PostgreSQL Flex instance creation %q.\n", instance.Id)
63+
64+
// Wait for the instance to become active
65+
_, err = wait.CreateInstanceWaitHandler(ctx, postgresflexClient.DefaultAPI, projectId, region, instance.Id).WaitWithContext(ctx)
66+
if err != nil {
67+
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex instance creation: %v\n", err)
68+
os.Exit(1)
69+
}
70+
71+
fmt.Printf("Created PostgreSQL Flex instance %q.\n", instance.Id)
72+
73+
// Get an instance
74+
instanceResp, err := postgresflexClient.DefaultAPI.GetInstance(ctx, projectId, region, instance.Id).Execute()
75+
if err != nil {
76+
fmt.Fprintf(os.Stderr, "Error when calling `GetInstance`: %v\n", err)
77+
os.Exit(1)
78+
}
79+
80+
fmt.Printf("Get instance %+v.\n", instanceResp)
81+
82+
// Create a user associated to an instance
83+
instanceId := instanceResp.Id
84+
username := "myUser"
85+
createUserPayload := postgresflex.CreateUserPayload{
86+
Name: username,
87+
Roles: []string{"login"},
88+
}
89+
user, err := postgresflexClient.DefaultAPI.CreateUser(ctx, projectId, region, instanceId).CreateUserPayload(createUserPayload).Execute()
90+
if err != nil {
91+
fmt.Fprintf(os.Stderr, "Error when calling `CreateUser`: %v\n", err)
92+
os.Exit(1)
93+
}
94+
95+
fmt.Printf("Triggered creation of user %q associated to instance %q.\n", username, instanceResp.Name)
96+
97+
// Wait for the user to become active
98+
_, err = wait.CreateUserWaitHandler(ctx, postgresflexClient.DefaultAPI, projectId, region, instance.Id, user.Id).WaitWithContext(ctx)
99+
if err != nil {
100+
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex user creation: %v\n", err)
101+
os.Exit(1)
102+
}
103+
104+
fmt.Printf("Created PostgreSQL Flex user %q.\n", user.Id)
105+
106+
// Get a user
107+
userResp, err := postgresflexClient.DefaultAPI.GetUser(ctx, projectId, region, instance.Id, user.Id).Execute()
108+
if err != nil {
109+
fmt.Fprintf(os.Stderr, "Error when calling `GetUser`: %v\n", err)
110+
os.Exit(1)
111+
}
112+
113+
fmt.Printf("Get user %+v.\n", userResp)
114+
115+
// Delete a user
116+
err = postgresflexClient.DefaultAPI.DeleteUser(ctx, projectId, region, instanceId, user.Id).Execute()
117+
118+
if err != nil {
119+
fmt.Fprintf(os.Stderr, "Error when deleting PostgreSQL Flex user: %v", err)
120+
os.Exit(1)
121+
}
122+
123+
_, err = wait.DeleteUserWaitHandler(ctx, postgresflexClient.DefaultAPI, projectId, region, instanceId, user.Id).WaitWithContext(ctx)
124+
if err != nil {
125+
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex user deletion: %v", err)
126+
}
127+
128+
fmt.Printf("Deleted PostgreSQL Flex user %q.\n", instanceId)
129+
130+
// Update an instance
131+
updateInstancePayload := postgresflex.PartialUpdateInstancePayload{
132+
Name: utils.Ptr("updated-instance"),
133+
}
134+
err = postgresflexClient.DefaultAPI.PartialUpdateInstance(ctx, projectId, region, instanceId).PartialUpdateInstancePayload(updateInstancePayload).Execute()
135+
if err != nil {
136+
fmt.Fprintf(os.Stderr, "Error updating PostgreSQL Flex instance: %v\n", err)
137+
os.Exit(1)
138+
}
139+
fmt.Printf("Triggered PostgreSQL Flex instance update %q.\n", instance.Id)
140+
141+
// Wait for the instance to become active
142+
_, err = wait.PartialUpdateInstanceWaitHandler(ctx, postgresflexClient.DefaultAPI, projectId, region, instanceId).WaitWithContext(ctx)
143+
if err != nil {
144+
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex instance update: %v\n", err)
145+
os.Exit(1)
146+
}
147+
148+
fmt.Printf("Updated PostgreSQL Flex instance %q.\n", instance.Id)
149+
150+
// Delete an instance
151+
err = postgresflexClient.DefaultAPI.DeleteInstance(ctx, projectId, region, instanceId).Execute()
152+
153+
if err != nil {
154+
fmt.Fprintf(os.Stderr, "Error when deleting PostgreSQL Flex instance: %v", err)
155+
os.Exit(1)
156+
}
157+
158+
_, err = wait.DeleteInstanceWaitHandler(ctx, postgresflexClient.DefaultAPI, projectId, region, instanceId).WaitWithContext(ctx)
159+
if err != nil {
160+
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex instance deletion: %v", err)
161+
os.Exit(1)
162+
}
163+
164+
fmt.Printf("Deleted PostgreSQL Flex instance %q.\n", instanceId)
165+
}

services/postgresflex/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v1.11.0
2+
- `v3beta1api`: **New:** New package which can be used for communication with the PostgreSQL Flex v3beta1 API
3+
- `v1api`: **Deprecated:** `v1api` is deprecated, use instead `v2api`
4+
- `v3alpha1api`: **Deprecated:** `v3alpha1api` is deprecated, use instead `v3beta1api`
5+
16
## v1.10.0
27
- `v3alpha1api`: Align package to latest API specification
38

services/postgresflex/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.10.0
1+
v1.11.0

services/postgresflex/oas_commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9873a8f7a4120017699e43baba2e8b2af7bca93e
1+
72230b88b02a415757a997174c27da16db266be6

services/postgresflex/v1api/api_default.go

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

services/postgresflex/v1api/api_default_mock.go

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

services/postgresflex/v1api/client.go

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

0 commit comments

Comments
 (0)