Skip to content

Commit e35277a

Browse files
committed
changelogs, examples, waiters
1 parent 9321202 commit e35277a

File tree

9 files changed

+276
-27
lines changed

9 files changed

+276
-27
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
- **Deprecation:** The contents in the root of this SDK module including the `wait` package are marked as deprecated and will be removed after 2026-09-30. Switch to the new `v0api` package instead.
1515
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
1616
- **Breaking Change:** Removal of deprecated constants `ActiveState` and `CreatingState` in `wait` package
17+
- `logs`: [v0.6.0](services/logs/CHANGELOG.md#v060)
18+
- **Feature:** Introduction of multi API version support for the logs SDK module. For more details please see the announcement on GitHub: https://github.com/stackitcloud/stackit-sdk-go/discussions/5062
19+
- `v1alphaapi`: New package which can be used for communication with the logs v1 alpha API
20+
- `v1betaapi`: New package which can be used for communication with the logs v1 beta API
21+
- `v1api`: New package which can be used for communication with the logs v1 API
22+
- **Deprecation:** The contents in the root of this SDK module including the `wait` package are marked as deprecated and will be removed after 2026-09-30. Switch to the new packages for the available API versions instead.
23+
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
1724

1825
## Release (2026-02-20)
1926
- `core`: [v0.21.1](core/CHANGELOG.md#v0211)

examples/logs/go.mod

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

33
go 1.21
44

5+
// 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.
6+
replace github.com/stackitcloud/stackit-sdk-go/services/logs => ../../services/logs
7+
58
require (
6-
github.com/stackitcloud/stackit-sdk-go/core v0.21.1
9+
github.com/stackitcloud/stackit-sdk-go/core v0.22.0
710
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2
811
)
912

examples/logs/go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
44
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
55
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
66
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7-
github.com/stackitcloud/stackit-sdk-go/core v0.21.1 h1:Y/PcAgM7DPYMNqum0MLv4n1mF9ieuevzcCIZYQfm3Ts=
8-
github.com/stackitcloud/stackit-sdk-go/core v0.21.1/go.mod h1:osMglDby4csGZ5sIfhNyYq1bS1TxIdPY88+skE/kkmI=
9-
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2 h1:vr4atxFRT+EL+DqONMT5R44f7AzEMbePa9U7PEE0THU=
10-
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2/go.mod h1:CAPsiTX7osAImfrG5RnIjaJ/Iz3QpoBKuH2fS346wuQ=
7+
github.com/stackitcloud/stackit-sdk-go/core v0.22.0 h1:6rViz7GnNwXSh51Lur5xuDzO8EWSZfN9J0HvEkBKq6c=
8+
github.com/stackitcloud/stackit-sdk-go/core v0.22.0/go.mod h1:osMglDby4csGZ5sIfhNyYq1bS1TxIdPY88+skE/kkmI=

examples/logs/logs.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"log"
66

77
"github.com/stackitcloud/stackit-sdk-go/core/utils"
8-
"github.com/stackitcloud/stackit-sdk-go/services/logs"
8+
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
99
)
1010

1111
func main() {
@@ -22,60 +22,59 @@ func main() {
2222
// Create a Logs Instance
2323
var createdInstance string
2424
createInstancePayload := logs.CreateLogsInstancePayload{
25-
DisplayName: utils.Ptr("my-logs-instance"),
26-
RetentionDays: utils.Ptr(int64(1)),
25+
DisplayName: "my-logs-instance",
26+
RetentionDays: int32(1),
2727
}
28-
createResp, err := client.CreateLogsInstance(ctx, projectId, regionId).
28+
createResp, err := client.DefaultAPI.CreateLogsInstance(ctx, projectId, regionId).
2929
CreateLogsInstancePayload(createInstancePayload).
3030
Execute()
3131
if err != nil {
3232
log.Fatalf("[Logs API] Error when calling `CreateLogsInstance`: %v\n", err)
3333
}
34-
createdInstance = *createResp.Id
35-
log.Printf("[Logs API] Created Logs Instance with ID \"%s\".\n", createdInstance)
34+
log.Printf("[Logs API] Created Logs Instance with ID \"%s\".\n", createResp.Id)
3635

3736
// List Logs Instances
38-
listResp, err := client.ListLogsInstances(ctx, projectId, regionId).Execute()
37+
listResp, err := client.DefaultAPI.ListLogsInstances(ctx, projectId, regionId).Execute()
3938
if err != nil {
4039
log.Fatalf("[Logs API] Error when calling `ListLogsInstances`: %v\n", err)
4140
}
42-
log.Printf("[Logs API] Retrieved %d Logs Instances.\n", len(*listResp.Instances))
41+
log.Printf("[Logs API] Retrieved %d Logs Instances.\n", len(listResp.Instances))
4342

4443
// Get the created Logs Instance
45-
getResp, err := client.GetLogsInstance(ctx, projectId, regionId, createdInstance).Execute()
44+
getResp, err := client.DefaultAPI.GetLogsInstance(ctx, projectId, regionId, createdInstance).Execute()
4645
if err != nil {
4746
log.Fatalf("[Logs API] Error when calling `GetLogsInstance`: %v\n", err)
4847
}
49-
log.Printf("[Logs API] Retrieved Logs Instance with ID \"%s\" and Display Name \"%s\".\n", *getResp.Id, *getResp.DisplayName)
48+
log.Printf("[Logs API] Retrieved Logs Instance with ID \"%s\" and Display Name \"%s\".\n", getResp.Id, getResp.DisplayName)
5049

5150
// Update the created Logs Instance
5251
updatePayload := logs.UpdateLogsInstancePayload{
5352
DisplayName: utils.Ptr("my-updated-logs-instance"),
54-
RetentionDays: utils.Ptr(int64(7)),
53+
RetentionDays: utils.Ptr(int32(7)),
5554
}
56-
updateResp, err := client.UpdateLogsInstance(ctx, projectId, regionId, createdInstance).
55+
updateResp, err := client.DefaultAPI.UpdateLogsInstance(ctx, projectId, regionId, createdInstance).
5756
UpdateLogsInstancePayload(updatePayload).
5857
Execute()
5958
if err != nil {
6059
log.Fatalf("[Logs API] Error when calling `UpdateLogsInstance`: %v\n", err)
6160
}
62-
log.Printf("[Logs API] Updated Logs Instance with ID \"%s\" to Display Name \"%s\".\n", *updateResp.Id, *updateResp.DisplayName)
61+
log.Printf("[Logs API] Updated Logs Instance with ID \"%s\" to Display Name \"%s\".\n", updateResp.Id, updateResp.DisplayName)
6362

6463
// Create an Access Token
6564
createTokenPayload := logs.CreateAccessTokenPayload{
66-
DisplayName: utils.Ptr("my-access-token"),
67-
Permissions: &[]string{"read"},
65+
DisplayName: "my-access-token",
66+
Permissions: []string{"read"},
6867
}
69-
createTokenResp, err := client.CreateAccessToken(ctx, projectId, regionId, createdInstance).
68+
createTokenResp, err := client.DefaultAPI.CreateAccessToken(ctx, projectId, regionId, createdInstance).
7069
CreateAccessTokenPayload(createTokenPayload).
7170
Execute()
7271
if err != nil {
7372
log.Fatalf("[Logs API] Error when calling `CreateAccessToken`: %v\n", err)
7473
}
75-
log.Printf("[Logs API] Created Access Token with ID \"%s\".\n", *createTokenResp.Id)
74+
log.Printf("[Logs API] Created Access Token with ID \"%s\".\n", createTokenResp.Id)
7675

7776
// Add Access Token to Logs Instance
78-
err = client.UpdateAccessToken(ctx, projectId, regionId, createdInstance, *createTokenResp.Id).
77+
err = client.DefaultAPI.UpdateAccessToken(ctx, projectId, regionId, createdInstance, createTokenResp.Id).
7978
// needs at least an empty payload
8079
UpdateAccessTokenPayload(logs.UpdateAccessTokenPayload{}).
8180
Execute()
@@ -84,14 +83,14 @@ func main() {
8483
}
8584

8685
// Delete all Access Tokens from Logs Instance
87-
tokenList, err := client.DeleteAllAccessTokens(ctx, projectId, regionId, createdInstance).Execute()
86+
tokenList, err := client.DefaultAPI.DeleteAllAccessTokens(ctx, projectId, regionId, createdInstance).Execute()
8887
if err != nil {
8988
log.Fatalf("[Logs API] Error when calling `DeleteAllAccessTokens`: %v\n", err)
9089
}
91-
log.Printf("[Logs API] Deleted %d Access Tokens from Logs Instance with ID \"%s\".\n", len(*tokenList.Tokens), createdInstance)
90+
log.Printf("[Logs API] Deleted %d Access Tokens from Logs Instance with ID \"%s\".\n", len(tokenList.Tokens), createdInstance)
9291

9392
// Delete the created Logs Instance
94-
err = client.DeleteLogsInstance(ctx, projectId, regionId, createdInstance).Execute()
93+
err = client.DefaultAPI.DeleteLogsInstance(ctx, projectId, regionId, createdInstance).Execute()
9594
if err != nil {
9695
log.Fatalf("[Logs API] Error when calling `DeleteLogsInstance`: %v\n", err)
9796
}

services/logs/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v0.6.0
2+
- **Feature:** Introduction of multi API version support for the logs SDK module. For more details please see the announcement on GitHub: https://github.com/stackitcloud/stackit-sdk-go/discussions/5062
3+
- `v1alphaapi`: New package which can be used for communication with the logs v1 alpha API
4+
- `v1betaapi`: New package which can be used for communication with the logs v1 beta API
5+
- `v1api`: New package which can be used for communication with the logs v1 API
6+
- **Deprecation:** The contents in the root of this SDK module including the `wait` package are marked as deprecated and will be removed after 2026-09-30. Switch to the new packages for the available API versions instead.
7+
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
8+
19
## v0.5.2
210
- Bump STACKIT SDK core module from `v0.21.0` to `v0.21.1`
311

services/logs/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.5.2
1+
v0.6.0

services/logs/v1api/wait/wait.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package wait
2+
3+
import (
4+
"context"
5+
"errors"
6+
"fmt"
7+
"net/http"
8+
"time"
9+
10+
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
11+
"github.com/stackitcloud/stackit-sdk-go/core/wait"
12+
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
13+
)
14+
15+
const (
16+
instanceStatusActive = "active"
17+
instanceStatusDeleting = "deleting"
18+
)
19+
20+
func CreateLogsInstanceWaitHandler(ctx context.Context, client logs.DefaultAPI, projectID, region, instanceID string) *wait.AsyncActionHandler[logs.LogsInstance] {
21+
handler := wait.New(func() (waitFinished bool, response *logs.LogsInstance, err error) {
22+
instance, err := client.GetLogsInstance(ctx, projectID, region, instanceID).Execute()
23+
if err != nil {
24+
return false, nil, err
25+
}
26+
if instance.Id == instanceID && instance.Status == instanceStatusActive {
27+
return true, instance, nil
28+
}
29+
if instance.Status == instanceStatusDeleting {
30+
return true, nil, fmt.Errorf("creating log instance failed, instance is being deleted")
31+
}
32+
return false, nil, nil
33+
})
34+
handler.SetTimeout(10 * time.Minute)
35+
return handler
36+
}
37+
38+
func DeleteLogsInstanceWaitHandler(ctx context.Context, client logs.DefaultAPI, projectID, region, instanceID string) *wait.AsyncActionHandler[logs.LogsInstance] {
39+
handler := wait.New(func() (waitFinished bool, response *logs.LogsInstance, err error) {
40+
_, err = client.GetLogsInstance(ctx, projectID, region, instanceID).Execute()
41+
// the instances is still gettable, e.g. not deleted, when the errors is null
42+
if err == nil {
43+
return false, nil, nil
44+
}
45+
var oapiError *oapierror.GenericOpenAPIError
46+
if errors.As(err, &oapiError) {
47+
if statusCode := oapiError.StatusCode; statusCode == http.StatusNotFound {
48+
return true, nil, nil
49+
}
50+
}
51+
return false, nil, err
52+
})
53+
handler.SetTimeout(10 * time.Minute)
54+
return handler
55+
}
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
package wait
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"testing"
7+
"time"
8+
9+
"github.com/google/go-cmp/cmp"
10+
"github.com/google/uuid"
11+
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
12+
"github.com/stackitcloud/stackit-sdk-go/core/utils"
13+
logs "github.com/stackitcloud/stackit-sdk-go/services/logs/v1api"
14+
)
15+
16+
type mockSettings struct {
17+
getFails bool
18+
returnInstance bool
19+
statusCode int
20+
getLogsResponse *logs.LogsInstance
21+
}
22+
23+
func newAPIMock(settings mockSettings) logs.DefaultAPI {
24+
return &logs.DefaultAPIServiceMock{
25+
GetLogsInstanceExecuteMock: utils.Ptr(func(_ logs.ApiGetLogsInstanceRequest) (*logs.LogsInstance, error) {
26+
if settings.getFails {
27+
return nil, &oapierror.GenericOpenAPIError{
28+
StatusCode: settings.statusCode,
29+
}
30+
}
31+
if !settings.returnInstance {
32+
return nil, nil
33+
}
34+
return settings.getLogsResponse, nil
35+
}),
36+
}
37+
}
38+
39+
var projectId = uuid.NewString()
40+
var instanceId = uuid.NewString()
41+
42+
const region = "eu01"
43+
44+
func TestCreateLogsInstanceWaitHandler(t *testing.T) {
45+
tests := []struct {
46+
description string
47+
getFails bool
48+
wantErr bool
49+
wantResp bool
50+
returnInstance bool
51+
getLogsResponse *logs.LogsInstance
52+
}{
53+
{
54+
description: "create succeeded",
55+
getFails: false,
56+
wantErr: false,
57+
wantResp: true,
58+
returnInstance: true,
59+
getLogsResponse: &logs.LogsInstance{
60+
Id: instanceId,
61+
Status: instanceStatusActive,
62+
},
63+
},
64+
{
65+
description: "create failed with error",
66+
getFails: true,
67+
wantErr: true,
68+
wantResp: false,
69+
returnInstance: true,
70+
getLogsResponse: &logs.LogsInstance{
71+
Id: instanceId,
72+
Status: instanceStatusActive,
73+
},
74+
},
75+
{
76+
description: "create without id",
77+
getFails: false,
78+
wantErr: true,
79+
wantResp: false,
80+
returnInstance: true,
81+
getLogsResponse: &logs.LogsInstance{
82+
Status: instanceStatusActive,
83+
},
84+
},
85+
{
86+
description: "create without status",
87+
getFails: false,
88+
wantErr: true,
89+
wantResp: false,
90+
returnInstance: true,
91+
getLogsResponse: &logs.LogsInstance{
92+
Id: instanceId,
93+
},
94+
},
95+
{
96+
description: "instance deleting",
97+
getFails: false,
98+
wantErr: true,
99+
wantResp: false,
100+
returnInstance: true,
101+
getLogsResponse: &logs.LogsInstance{
102+
Id: instanceId,
103+
Status: instanceStatusDeleting,
104+
},
105+
},
106+
}
107+
for _, tt := range tests {
108+
t.Run(tt.description, func(t *testing.T) {
109+
client := newAPIMock(mockSettings{
110+
getFails: tt.getFails,
111+
getLogsResponse: tt.getLogsResponse,
112+
returnInstance: tt.returnInstance,
113+
})
114+
115+
var instanceWanted *logs.LogsInstance
116+
if tt.wantResp {
117+
instanceWanted = tt.getLogsResponse
118+
}
119+
120+
handler := CreateLogsInstanceWaitHandler(context.Background(), client, projectId, region, instanceId)
121+
122+
response, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background())
123+
124+
if (err != nil) != tt.wantErr {
125+
t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr)
126+
}
127+
if !cmp.Equal(response, instanceWanted) {
128+
t.Fatalf("handler gotRes = %v, want %v", response, instanceWanted)
129+
}
130+
})
131+
}
132+
}
133+
134+
func TestDeleteLogsInstanceWaitHandler(t *testing.T) {
135+
tests := []struct {
136+
description string
137+
getFails bool
138+
wantErr bool
139+
statusCode int
140+
}{
141+
{
142+
description: "delete succeeded",
143+
getFails: true,
144+
statusCode: http.StatusNotFound,
145+
},
146+
{
147+
description: "delete failed with error",
148+
getFails: true,
149+
wantErr: true,
150+
statusCode: http.StatusInternalServerError,
151+
},
152+
{
153+
description: "delete still in progress",
154+
getFails: false,
155+
wantErr: true,
156+
statusCode: http.StatusOK,
157+
},
158+
}
159+
for _, tt := range tests {
160+
t.Run(tt.description, func(t *testing.T) {
161+
client := newAPIMock(mockSettings{
162+
getFails: tt.getFails,
163+
returnInstance: false,
164+
statusCode: tt.statusCode,
165+
getLogsResponse: nil,
166+
})
167+
168+
handler := DeleteLogsInstanceWaitHandler(context.Background(), client, projectId, region, instanceId)
169+
_, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background())
170+
if (err != nil) != tt.wantErr {
171+
t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr)
172+
}
173+
})
174+
}
175+
}

0 commit comments

Comments
 (0)