Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
- `v1api`:
- **Improvement**: Improve http error handling
- `postgresflex`:
- [v1.11.0](services/postgresflex/CHANGELOG.md#v1110)
- `v3beta1api`: **New:** New package which can be used for communication with the PostgreSQL Flex v3beta1 API
- `v1api`: **Deprecated:** `v1api` is deprecated, use instead `v2api`
- `v3alpha1api`: **Deprecated:** `v3alpha1api` is deprecated, use instead `v3beta1api`
- [v1.10.0](services/postgresflex/CHANGELOG.md#v1100)
- `v3alpha1api`: Align package to latest API specification
- `rabbitmq`:
Expand Down
6 changes: 4 additions & 2 deletions examples/postgresflex/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ go 1.25
// 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.
replace github.com/stackitcloud/stackit-sdk-go/services/postgresflex => ../../services/postgresflex

require github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.10.0
require (
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.10.0
)

require (
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/stackitcloud/stackit-sdk-go/core v0.26.0 // indirect
)
165 changes: 165 additions & 0 deletions examples/postgresflex/v3beta1/postgresflex_v3beta1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package main

import (
"context"
"fmt"
"os"

"github.com/stackitcloud/stackit-sdk-go/core/utils"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3beta1api"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3beta1api/wait"
)

func main() {
const (
projectId = "PROJECT_ID" // the uuid of your STACKIT project
region = "eu01" // Specify the region
// Specify instance configuration options
version = "VERSION"
// 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
// or using postgresflexClient.DefaultAPI.ListFlavors(ctx, projectId, region).Execute()
flavorId = "FLAVOR_ID"
)

ctx := context.Background()

// Create a new API client, that uses default authentication and configuration
postgresflexClient, err := postgresflex.NewAPIClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err)
os.Exit(1)
}

// List the PostgreSQL Flex instances for your project
getInstancesResp, err := postgresflexClient.DefaultAPI.ListInstances(ctx, projectId, region).Execute()

if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `ListInstances`: %v\n", err)
os.Exit(1)
}
fmt.Printf("Number of instances: %v\n", len(getInstancesResp.Instances))

// Create an instance
createInstancePayload := postgresflex.CreateInstancePayload{
Name: "my-instance",
FlavorId: flavorId,
Version: version,
BackupSchedule: "0 2 * * *",
RetentionDays: *postgresflex.NewNullableInt32(utils.Ptr(int32(35))),
Network: postgresflex.InstanceNetworkCreate{
Acl: []string{"1.2.3.4/32"},
},
Storage: postgresflex.StorageCreate{
Class: utils.Ptr("premium-perf2-stackit"),
Size: 5,
},
}
instance, err := postgresflexClient.DefaultAPI.CreateInstance(ctx, projectId, region).CreateInstancePayload(createInstancePayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating PostgreSQL Flex instance: %v\n", err)
os.Exit(1)
}
fmt.Printf("Triggered PostgreSQL Flex instance creation %q.\n", instance.Id)

// Wait for the instance to become active
_, err = wait.CreateInstanceWaitHandler(ctx, postgresflexClient.DefaultAPI, projectId, region, instance.Id).WaitWithContext(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex instance creation: %v\n", err)
os.Exit(1)
}

fmt.Printf("Created PostgreSQL Flex instance %q.\n", instance.Id)

// Get an instance
instanceResp, err := postgresflexClient.DefaultAPI.GetInstance(ctx, projectId, region, instance.Id).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `GetInstance`: %v\n", err)
os.Exit(1)
}

fmt.Printf("Get instance %+v.\n", instanceResp)

// Create a user associated to an instance
instanceId := instanceResp.Id
username := "myUser"
createUserPayload := postgresflex.CreateUserPayload{
Name: username,
Roles: []string{"login"},
}
user, err := postgresflexClient.DefaultAPI.CreateUser(ctx, projectId, region, instanceId).CreateUserPayload(createUserPayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CreateUser`: %v\n", err)
os.Exit(1)
}

fmt.Printf("Triggered creation of user %q associated to instance %q.\n", username, instanceResp.Name)

// Wait for the user to become active
_, err = wait.CreateUserWaitHandler(ctx, postgresflexClient.DefaultAPI, projectId, region, instance.Id, user.Id).WaitWithContext(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex user creation: %v\n", err)
os.Exit(1)
}

fmt.Printf("Created PostgreSQL Flex user %q.\n", user.Id)

// Get a user
userResp, err := postgresflexClient.DefaultAPI.GetUser(ctx, projectId, region, instance.Id, user.Id).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `GetUser`: %v\n", err)
os.Exit(1)
}

fmt.Printf("Get user %+v.\n", userResp)

// Delete a user
err = postgresflexClient.DefaultAPI.DeleteUser(ctx, projectId, region, instanceId, user.Id).Execute()

if err != nil {
fmt.Fprintf(os.Stderr, "Error when deleting PostgreSQL Flex user: %v", err)
os.Exit(1)
}

_, err = wait.DeleteUserWaitHandler(ctx, postgresflexClient.DefaultAPI, projectId, region, instanceId, user.Id).WaitWithContext(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex user deletion: %v", err)
}

fmt.Printf("Deleted PostgreSQL Flex user %q.\n", instanceId)

// Update an instance
updateInstancePayload := postgresflex.PartialUpdateInstancePayload{
Name: utils.Ptr("updated-instance"),
}
err = postgresflexClient.DefaultAPI.PartialUpdateInstance(ctx, projectId, region, instanceId).PartialUpdateInstancePayload(updateInstancePayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error updating PostgreSQL Flex instance: %v\n", err)
os.Exit(1)
}
fmt.Printf("Triggered PostgreSQL Flex instance update %q.\n", instance.Id)

// Wait for the instance to become active
_, err = wait.PartialUpdateInstanceWaitHandler(ctx, postgresflexClient.DefaultAPI, projectId, region, instanceId).WaitWithContext(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex instance update: %v\n", err)
os.Exit(1)
}

fmt.Printf("Updated PostgreSQL Flex instance %q.\n", instance.Id)

// Delete an instance
err = postgresflexClient.DefaultAPI.DeleteInstance(ctx, projectId, region, instanceId).Execute()

if err != nil {
fmt.Fprintf(os.Stderr, "Error when deleting PostgreSQL Flex instance: %v", err)
os.Exit(1)
}

_, err = wait.DeleteInstanceWaitHandler(ctx, postgresflexClient.DefaultAPI, projectId, region, instanceId).WaitWithContext(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex instance deletion: %v", err)
os.Exit(1)
}

fmt.Printf("Deleted PostgreSQL Flex instance %q.\n", instanceId)
}
5 changes: 5 additions & 0 deletions services/postgresflex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v1.11.0
- `v3beta1api`: **New:** New package which can be used for communication with the PostgreSQL Flex v3beta1 API
- `v1api`: **Deprecated:** `v1api` is deprecated, use instead `v2api`
- `v3alpha1api`: **Deprecated:** `v3alpha1api` is deprecated, use instead `v3beta1api`

## v1.10.0
- `v3alpha1api`: Align package to latest API specification

Expand Down
2 changes: 1 addition & 1 deletion services/postgresflex/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.10.0
v1.11.0
2 changes: 1 addition & 1 deletion services/postgresflex/oas_commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9873a8f7a4120017699e43baba2e8b2af7bca93e
72230b88b02a415757a997174c27da16db266be6
4 changes: 2 additions & 2 deletions services/postgresflex/v1api/api_default.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions services/postgresflex/v1api/api_default_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions services/postgresflex/v1api/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions services/postgresflex/v1api/configuration.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions services/postgresflex/v1api/model_acl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions services/postgresflex/v1api/model_api_configuration.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions services/postgresflex/v1api/model_api_extension_list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions services/postgresflex/v1api/model_api_install_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions services/postgresflex/v1api/model_backup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions services/postgresflex/v1api/model_clone_instance_payload.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading