Skip to content

Commit e500da9

Browse files
authored
Merge branch 'main' into generator-bot-13518986874/sqlserverflex
2 parents 57da94e + f72dc31 commit e500da9

File tree

68 files changed

+784
-257
lines changed

Some content is hidden

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

68 files changed

+784
-257
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- **Feature:** Add method to create inquiries: `InquiriesCreateInquiry`
55
- **Feature:** Add `sort` property to `ApiListCatalogProductsRequest`
66
- **Feature:** Add payload `ApproveSubscriptionPayload` for `ApiApproveSubscriptionRequest`
7+
- `postgresflex`: [v1.0.0](services/postgresflex/CHANGELOG.md#v100-2025-02-24)
8+
- **Breaking Change:** The region is no longer specified within the client configuration. Instead, the region must be passed as a parameter to any region-specific request.
79
- `sqlserverflex`: [v1.0.0](services/sqlserverflex/CHANGELOG.md#v100-2025-02-25)
810
- **Breaking Change:** The region is no longer specified within the client configuration. Instead, the region must be passed as a parameter to any region-specific request.
911
- **Feature:** Add method to delete all instances for a project: `TerminateProject`

core/auth/auth.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const (
2727
privateKeyPathCredentialType credentialType = "private_key_path"
2828
)
2929

30+
var userHomeDir = os.UserHomeDir
31+
3032
// SetupAuth sets up authentication based on the configuration. The different options are
3133
// custom authentication, no authentication, explicit key flow, explicit token flow or default authentication
3234
func SetupAuth(cfg *config.Configuration) (rt http.RoundTripper, err error) {
@@ -195,7 +197,7 @@ func readCredentialsFile(path string) (*Credentials, error) {
195197
customPath, customPathSet := os.LookupEnv("STACKIT_CREDENTIALS_PATH")
196198
if !customPathSet || customPath == "" {
197199
path = credentialsFilePath
198-
home, err := os.UserHomeDir()
200+
home, err := userHomeDir()
199201
if err != nil {
200202
return nil, fmt.Errorf("getting home directory: %w", err)
201203
}

core/auth/auth_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ import (
1616
"github.com/stackitcloud/stackit-sdk-go/core/config"
1717
)
1818

19+
func setTemporaryHome(t *testing.T) {
20+
old := userHomeDir
21+
t.Cleanup(func() {
22+
userHomeDir = old
23+
})
24+
userHomeDir = func() (string, error) {
25+
return t.TempDir(), nil
26+
}
27+
}
28+
1929
func fixtureServiceAccountKey(mods ...func(*clients.ServiceAccountKeyResponse)) *clients.ServiceAccountKeyResponse {
2030
validUntil := time.Now().Add(time.Hour)
2131
serviceAccountKeyResponse := &clients.ServiceAccountKeyResponse{
@@ -150,6 +160,7 @@ func TestSetupAuth(t *testing.T) {
150160
},
151161
} {
152162
t.Run(test.desc, func(t *testing.T) {
163+
setTemporaryHome(t)
153164
if test.setKeys {
154165
t.Setenv("STACKIT_SERVICE_ACCOUNT_KEY_PATH", saKeyFile.Name())
155166
t.Setenv("STACKIT_PRIVATE_KEY_PATH", privateKeyFile.Name())
@@ -232,6 +243,7 @@ func TestReadCredentials(t *testing.T) {
232243
},
233244
} {
234245
t.Run(test.desc, func(t *testing.T) {
246+
setTemporaryHome(t)
235247
t.Setenv("STACKIT_CREDENTIALS_PATH", test.pathEnv)
236248

237249
var credential string
@@ -342,6 +354,7 @@ func TestDefaultAuth(t *testing.T) {
342354
},
343355
} {
344356
t.Run(test.desc, func(t *testing.T) {
357+
setTemporaryHome(t)
345358
if test.setKeys {
346359
t.Setenv("STACKIT_SERVICE_ACCOUNT_KEY_PATH", saKeyFile.Name())
347360
t.Setenv("STACKIT_PRIVATE_KEY_PATH", privateKeyFile.Name())
@@ -406,6 +419,7 @@ func TestTokenAuth(t *testing.T) {
406419
},
407420
} {
408421
t.Run(test.desc, func(t *testing.T) {
422+
setTemporaryHome(t)
409423
t.Setenv("STACKIT_SERVICE_ACCOUNT_TOKEN", "")
410424
t.Setenv("STACKIT_CREDENTIALS_PATH", "test-path")
411425

@@ -499,6 +513,7 @@ func TestKeyAuth(t *testing.T) {
499513
},
500514
} {
501515
t.Run(test.desc, func(t *testing.T) {
516+
setTemporaryHome(t)
502517
t.Setenv("STACKIT_SERVICE_ACCOUNT_KEY", "")
503518
t.Setenv("STACKIT_SERVICE_ACCOUNT_KEY_PATH", "")
504519
t.Setenv("STACKIT_PRIVATE_KEY", "")
@@ -557,7 +572,7 @@ func TestNoAuth(t *testing.T) {
557572
},
558573
} {
559574
t.Run(test.desc, func(t *testing.T) {
560-
// Get the default authentication client and ensure that it's not nil
575+
setTemporaryHome(t) // Get the default authentication client and ensure that it's not nil
561576
authClient, err := NoAuth()
562577
if err != nil {
563578
t.Fatalf("Test returned error on valid test case: %v", err)
@@ -624,6 +639,7 @@ func TestGetServiceAccountEmail(t *testing.T) {
624639
},
625640
} {
626641
t.Run(test.description, func(t *testing.T) {
642+
setTemporaryHome(t)
627643
if test.envEmailSet {
628644
t.Setenv("STACKIT_SERVICE_ACCOUNT_EMAIL", "env_email")
629645
} else {
@@ -742,6 +758,7 @@ func TestGetPrivateKey(t *testing.T) {
742758
},
743759
} {
744760
t.Run(test.name, func(t *testing.T) {
761+
setTemporaryHome(t)
745762
t.Setenv("STACKIT_CREDENTIALS_PATH", test.credentialsFilePath)
746763

747764
if test.envPrivateKeyPathSet {
@@ -843,6 +860,7 @@ func TestGetServiceAccountKey(t *testing.T) {
843860
},
844861
} {
845862
t.Run(test.name, func(t *testing.T) {
863+
setTemporaryHome(t)
846864
t.Setenv("STACKIT_CREDENTIALS_PATH", test.credentialsFilePath)
847865

848866
if test.envServiceAccountKeyPathSet {

examples/postgresflex/go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ module github.com/stackitcloud/stackit-sdk-go/examples/postgresflex
22

33
go 1.21
44

5-
require (
6-
github.com/stackitcloud/stackit-sdk-go/core v0.16.0
7-
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.18.0
8-
)
5+
require github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.18.0
96

107
require (
118
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
129
github.com/google/go-cmp v0.7.0 // indirect
1310
github.com/google/uuid v1.6.0 // indirect
11+
github.com/stackitcloud/stackit-sdk-go/core v0.16.0 // indirect
1412
)

examples/postgresflex/postgresflex.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/stackitcloud/stackit-sdk-go/core/config"
98
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
109
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait"
1110
)
@@ -14,17 +13,18 @@ func main() {
1413
// Specify the project ID
1514
projectId := "PROJECT_ID"
1615

16+
// Specify the region
17+
region := "REGION"
18+
1719
// Create a new API client, that uses default authentication and configuration
18-
postgresflexClient, err := postgresflex.NewAPIClient(
19-
config.WithRegion("eu01"),
20-
)
20+
postgresflexClient, err := postgresflex.NewAPIClient()
2121
if err != nil {
2222
fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err)
2323
os.Exit(1)
2424
}
2525

2626
// Get the postgresql instances for your project
27-
getInstancesResp, err := postgresflexClient.ListInstances(context.Background(), projectId).Execute()
27+
getInstancesResp, err := postgresflexClient.ListInstances(context.Background(), projectId, region).Execute()
2828
if err != nil {
2929
fmt.Fprintf(os.Stderr, "Error when calling `ListInstances`: %v\n", err)
3030
os.Exit(1)
@@ -44,7 +44,7 @@ func main() {
4444
Username: &username,
4545
Roles: &[]string{"login"},
4646
}
47-
_, err = postgresflexClient.CreateUser(context.Background(), projectId, instanceId).CreateUserPayload(createUserPayload).Execute()
47+
_, err = postgresflexClient.CreateUser(context.Background(), projectId, region, instanceId).CreateUserPayload(createUserPayload).Execute()
4848
if err != nil {
4949
fmt.Fprintf(os.Stderr, "Error when calling `CreateUser`: %v\n", err)
5050
os.Exit(1)
@@ -53,27 +53,27 @@ func main() {
5353
fmt.Printf("Created user \"%s\" associated to instance \"%s\".\n", username, *items[0].Name)
5454

5555
// Delete an instance
56-
err = postgresflexClient.DeleteInstance(context.Background(), projectId, instanceId).Execute()
56+
err = postgresflexClient.DeleteInstance(context.Background(), projectId, region, instanceId).Execute()
5757

5858
if err != nil {
5959
fmt.Fprintf(os.Stderr, "Error when delete PostgreSQL Flex instance: %v", err)
6060
}
6161

62-
_, err = wait.DeleteInstanceWaitHandler(context.Background(), postgresflexClient, projectId, instanceId).WaitWithContext(context.Background())
62+
_, err = wait.DeleteInstanceWaitHandler(context.Background(), postgresflexClient, projectId, region, instanceId).WaitWithContext(context.Background())
6363
if err != nil {
6464
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex instance deletion: %v", err)
6565
}
6666

6767
fmt.Printf("Deleted PostgreSQL Flex instance \"%s\".\n", instanceId)
6868

6969
// Force delete an instance
70-
err = postgresflexClient.ForceDeleteInstance(context.Background(), projectId, instanceId).Execute()
70+
err = postgresflexClient.ForceDeleteInstance(context.Background(), projectId, region, instanceId).Execute()
7171

7272
if err != nil {
7373
fmt.Fprintf(os.Stderr, "Error when force delete PostgreSQL Flex instance: %v", err)
7474
}
7575

76-
_, err = wait.ForceDeleteInstanceWaitHandler(context.Background(), postgresflexClient, projectId, instanceId).WaitWithContext(context.Background())
76+
_, err = wait.ForceDeleteInstanceWaitHandler(context.Background(), postgresflexClient, projectId, region, instanceId).WaitWithContext(context.Background())
7777
if err != nil {
7878
fmt.Fprintf(os.Stderr, "Error when waiting for PostgreSQL Flex instance force deletion: %v", err)
7979
}

examples/runtime/runtime.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77
"os"
88

9-
"github.com/stackitcloud/stackit-sdk-go/core/config"
109
"github.com/stackitcloud/stackit-sdk-go/core/runtime"
1110
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
1211
)
@@ -15,30 +14,31 @@ func main() {
1514
// Specify the project ID
1615
projectId := "PROJECT_ID"
1716

17+
// Specify the region
18+
region := "REGION"
19+
1820
// Create a new API client, that uses default authentication and configuration
19-
postgresflexClient, err := postgresflex.NewAPIClient(
20-
config.WithRegion("eu01"),
21-
)
21+
postgresflexClient, err := postgresflex.NewAPIClient()
2222
if err != nil {
2323
fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err)
2424
os.Exit(1)
2525
}
2626

27-
// Get the MongoDB Flex instances for your project and capture the HTTP response using the context
27+
// Get the PostgreSQL Flex instances for your project and capture the HTTP response using the context
2828
var httpResp *http.Response
2929
ctxWithHTTPResp := runtime.WithCaptureHTTPResponse(context.Background(), &httpResp)
30-
getInstancesResp, err := postgresflexClient.ListInstances(ctxWithHTTPResp, projectId).Execute()
30+
getInstancesResp, err := postgresflexClient.ListInstances(ctxWithHTTPResp, projectId, region).Execute()
3131
if err != nil {
3232
fmt.Fprintf(os.Stderr, "Error when calling `ListInstances`: %v\n", err)
3333
os.Exit(1)
3434
}
3535
fmt.Printf("Number of instances: %v\n\n", len(*getInstancesResp.Items))
3636
fmt.Printf("HTTP response: %+v\n\n", *httpResp)
3737

38-
// Get the MongoDB Flex instances for your project and capture the HTTP request using the context
38+
// Get the PostgreSQL Flex instances for your project and capture the HTTP request using the context
3939
var httpReq *http.Request
4040
ctxWithHTTPReq := runtime.WithCaptureHTTPRequest(context.Background(), &httpReq)
41-
getInstancesResp, err = postgresflexClient.ListInstances(ctxWithHTTPReq, projectId).Execute()
41+
getInstancesResp, err = postgresflexClient.ListInstances(ctxWithHTTPReq, projectId, region).Execute()
4242
if err != nil {
4343
fmt.Fprintf(os.Stderr, "Error when calling `ListInstances`: %v\n", err)
4444
os.Exit(1)

services/postgresflex/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v1.0.0 (2025-02-24)
2+
- **Breaking Change:** The region is no longer specified within the client configuration. Instead, the region must be passed as a parameter to any region-specific request.
3+
14
## v0.18.0 (2025-02-21)
25
- **New:** Minimal go version is now Go 1.21
36

0 commit comments

Comments
 (0)