Skip to content

Commit 1e64626

Browse files
ozanichkovskyOleksandr ZanichkovskyiFyuselGokceGK
authored
TelemetryRouter service waiters and examples (#6796)
* feat: telemetryrouter waiters and examples * chore: updated changelog and version * chore: update telemetryrouter examples version * chore: changes according to review comments * chore: using utils.Ptr * chore: updated telemetryrouter endpoints to be resolvable * chore: fixed failing update destination example * chore: Update CHANGELOG.md Co-authored-by: Alexander Dahmen <dahmena_hws@gmx.de> * chore: Update examples/telemetryrouter/telemetryrouter.go Co-authored-by: Gökce Gök Klingel <161626272+GokceGK@users.noreply.github.com> * chore: Update examples/telemetryrouter/go.mod Co-authored-by: Gökce Gök Klingel <161626272+GokceGK@users.noreply.github.com> * chore: more detailed logging --------- Co-authored-by: Oleksandr Zanichkovskyi <Oleksandr.Zanichkovskyi_ext@external.digits.schwarz> Co-authored-by: Alexander Dahmen <dahmena_hws@gmx.de> Co-authored-by: Gökce Gök Klingel <161626272+GokceGK@users.noreply.github.com>
1 parent 8301d3a commit 1e64626

10 files changed

Lines changed: 1227 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@
424424
- **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0`
425425
- [v0.2.0](services/telemetryrouter/CHANGELOG.md#v020)
426426
- **Feature:** Added `_UNKNOWN_DEFAULT_OPEN_API` fallback value to all enums to handle unknown API values gracefully.
427+
- [v0.2.1](services/telemetryrouter/CHANGELOG.md#v021)
428+
- **Improvement**: Use new `WaiterHandler` struct in the DNS WaitHandler
427429
- `vpn`:
428430
- [v0.4.2](services/vpn/CHANGELOG.md#v042)
429431
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1`

examples/telemetryrouter/go.mod

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module github.com/stackitcloud/stackit-sdk-go/examples/telemetryrouter
2+
3+
go 1.25
4+
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/telemetryrouter => ../../services/telemetryrouter
7+
8+
require (
9+
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
10+
github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter v0.2.1
11+
)
12+
13+
require (
14+
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
15+
github.com/google/uuid v1.6.0 // indirect
16+
)

examples/telemetryrouter/go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
2+
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
3+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
4+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
5+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
6+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7+
github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10cz4l0KM2L6hqYBH2QA=
8+
github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA=

examples/telemetryrouter/telemetryrouter.go

Lines changed: 390 additions & 0 deletions
Large diffs are not rendered by default.

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use (
3434
./examples/sfs
3535
./examples/ske
3636
./examples/sqlserverflex
37+
./examples/telemetryrouter
3738
./examples/waiter
3839
./services/alb
3940
./services/albwaf

services/telemetryrouter/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.2.1
2+
- **Improvement**: Use new `WaiterHandler` struct in the DNS WaitHandler
3+
14
## v0.2.0
25
- **Feature:** Added `_UNKNOWN_DEFAULT_OPEN_API` fallback value to all enums to handle unknown API values gracefully.
36

services/telemetryrouter/VERSION

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

services/telemetryrouter/go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ module github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter
22

33
go 1.25
44

5-
require github.com/stackitcloud/stackit-sdk-go/core v0.26.0
5+
require (
6+
github.com/google/go-cmp v0.7.0
7+
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
8+
)
69

710
require (
811
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
package wait
2+
3+
import (
4+
"context"
5+
"errors"
6+
"net/http"
7+
"time"
8+
9+
"github.com/stackitcloud/stackit-sdk-go/core/wait"
10+
telemetryrouter "github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter/v1betaapi"
11+
)
12+
13+
const (
14+
TELEMETRYROUTER_ACTIVE = "active"
15+
DESTINATION_ACTIVE = "active"
16+
ACCESSTOKEN_ACTIVE = "active"
17+
)
18+
19+
// CreateTelemetryRouterWaitHandler will wait for TelemetryRouter creation
20+
func CreateTelemetryRouterWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId string) *wait.AsyncActionHandler[telemetryrouter.TelemetryRouterResponse] {
21+
waitConfig := wait.WaiterHelper[telemetryrouter.TelemetryRouterResponse, string]{
22+
FetchInstance: a.GetTelemetryRouter(ctx, projectId, regionId, instanceId).Execute,
23+
GetState: func(d *telemetryrouter.TelemetryRouterResponse) (string, error) {
24+
if d == nil {
25+
return "", errors.New("empty response")
26+
}
27+
return d.Status, nil
28+
},
29+
ActiveState: []string{TELEMETRYROUTER_ACTIVE},
30+
}
31+
32+
handler := wait.New(waitConfig.Wait())
33+
handler.SetTimeout(10 * time.Minute)
34+
return handler
35+
}
36+
37+
// UpdateTelemetryRouterWaitHandler will wait for TelemetryRouter update
38+
func UpdateTelemetryRouterWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId string) *wait.AsyncActionHandler[telemetryrouter.TelemetryRouterResponse] {
39+
waitConfig := wait.WaiterHelper[telemetryrouter.TelemetryRouterResponse, string]{
40+
FetchInstance: a.GetTelemetryRouter(ctx, projectId, regionId, instanceId).Execute,
41+
GetState: func(d *telemetryrouter.TelemetryRouterResponse) (string, error) {
42+
if d == nil {
43+
return "", errors.New("empty response")
44+
}
45+
return d.Status, nil
46+
},
47+
ActiveState: []string{TELEMETRYROUTER_ACTIVE},
48+
}
49+
50+
handler := wait.New(waitConfig.Wait())
51+
handler.SetTimeout(10 * time.Minute)
52+
return handler
53+
}
54+
55+
// DeleteTelemetryRouterWaitHandler will wait for TelemetryRouter deletion
56+
func DeleteTelemetryRouterWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId string) *wait.AsyncActionHandler[telemetryrouter.TelemetryRouterResponse] {
57+
waitConfig := wait.WaiterHelper[telemetryrouter.TelemetryRouterResponse, string]{
58+
FetchInstance: a.GetTelemetryRouter(ctx, projectId, regionId, instanceId).Execute,
59+
GetState: func(d *telemetryrouter.TelemetryRouterResponse) (string, error) {
60+
if d == nil {
61+
return "", errors.New("empty response")
62+
}
63+
return d.Status, nil
64+
},
65+
DeleteHttpErrorStatusCodes: []int{http.StatusNotFound},
66+
}
67+
68+
handler := wait.New(waitConfig.Wait())
69+
handler.SetTimeout(10 * time.Minute)
70+
return handler
71+
}
72+
73+
// CreateDestinationWaitHandler will wait for Destination creation
74+
func CreateDestinationWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, destinationId string) *wait.AsyncActionHandler[telemetryrouter.DestinationResponse] {
75+
waitConfig := wait.WaiterHelper[telemetryrouter.DestinationResponse, string]{
76+
FetchInstance: a.GetDestination(ctx, projectId, regionId, instanceId, destinationId).Execute,
77+
GetState: func(d *telemetryrouter.DestinationResponse) (string, error) {
78+
if d == nil {
79+
return "", errors.New("empty response")
80+
}
81+
return d.Status, nil
82+
},
83+
ActiveState: []string{DESTINATION_ACTIVE},
84+
}
85+
86+
handler := wait.New(waitConfig.Wait())
87+
handler.SetTimeout(10 * time.Minute)
88+
return handler
89+
}
90+
91+
// UpdateDestinationWaitHandler will wait for Destination update
92+
func UpdateDestinationWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, destinationId string) *wait.AsyncActionHandler[telemetryrouter.DestinationResponse] {
93+
waitConfig := wait.WaiterHelper[telemetryrouter.DestinationResponse, string]{
94+
FetchInstance: a.GetDestination(ctx, projectId, regionId, instanceId, destinationId).Execute,
95+
GetState: func(d *telemetryrouter.DestinationResponse) (string, error) {
96+
if d == nil {
97+
return "", errors.New("empty response")
98+
}
99+
return d.Status, nil
100+
},
101+
ActiveState: []string{DESTINATION_ACTIVE},
102+
}
103+
104+
handler := wait.New(waitConfig.Wait())
105+
handler.SetTimeout(10 * time.Minute)
106+
return handler
107+
}
108+
109+
// DeleteDestinationWaitHandler will wait for Destination deletion
110+
func DeleteDestinationWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, destinationId string) *wait.AsyncActionHandler[telemetryrouter.DestinationResponse] {
111+
waitConfig := wait.WaiterHelper[telemetryrouter.DestinationResponse, string]{
112+
FetchInstance: a.GetDestination(ctx, projectId, regionId, instanceId, destinationId).Execute,
113+
GetState: func(d *telemetryrouter.DestinationResponse) (string, error) {
114+
if d == nil {
115+
return "", errors.New("empty response")
116+
}
117+
return d.Status, nil
118+
},
119+
DeleteHttpErrorStatusCodes: []int{http.StatusNotFound},
120+
}
121+
122+
handler := wait.New(waitConfig.Wait())
123+
handler.SetTimeout(10 * time.Minute)
124+
return handler
125+
}
126+
127+
// CreateAccessTokenWaitHandler will wait for AccessToken creation
128+
func CreateAccessTokenWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, accessTokenId string) *wait.AsyncActionHandler[telemetryrouter.GetAccessTokenResponse] {
129+
waitConfig := wait.WaiterHelper[telemetryrouter.GetAccessTokenResponse, string]{
130+
FetchInstance: a.GetAccessToken(ctx, projectId, regionId, instanceId, accessTokenId).Execute,
131+
GetState: func(d *telemetryrouter.GetAccessTokenResponse) (string, error) {
132+
if d == nil {
133+
return "", errors.New("empty response")
134+
}
135+
return d.Status, nil
136+
},
137+
ActiveState: []string{ACCESSTOKEN_ACTIVE},
138+
}
139+
140+
handler := wait.New(waitConfig.Wait())
141+
handler.SetTimeout(10 * time.Minute)
142+
return handler
143+
}
144+
145+
// UpdateAccessTokenWaitHandler will wait for AccessToken update
146+
func UpdateAccessTokenWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, accessTokenId string) *wait.AsyncActionHandler[telemetryrouter.GetAccessTokenResponse] {
147+
waitConfig := wait.WaiterHelper[telemetryrouter.GetAccessTokenResponse, string]{
148+
FetchInstance: a.GetAccessToken(ctx, projectId, regionId, instanceId, accessTokenId).Execute,
149+
GetState: func(d *telemetryrouter.GetAccessTokenResponse) (string, error) {
150+
if d == nil {
151+
return "", errors.New("empty response")
152+
}
153+
return d.Status, nil
154+
},
155+
ActiveState: []string{ACCESSTOKEN_ACTIVE},
156+
}
157+
158+
handler := wait.New(waitConfig.Wait())
159+
handler.SetTimeout(10 * time.Minute)
160+
return handler
161+
}
162+
163+
// DeleteAccessTokenWaitHandler will wait for AccessToken deletion
164+
func DeleteAccessTokenWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, accessTokenId string) *wait.AsyncActionHandler[telemetryrouter.GetAccessTokenResponse] {
165+
waitConfig := wait.WaiterHelper[telemetryrouter.GetAccessTokenResponse, string]{
166+
FetchInstance: a.GetAccessToken(ctx, projectId, regionId, instanceId, accessTokenId).Execute,
167+
GetState: func(d *telemetryrouter.GetAccessTokenResponse) (string, error) {
168+
if d == nil {
169+
return "", errors.New("empty response")
170+
}
171+
return d.Status, nil
172+
},
173+
DeleteHttpErrorStatusCodes: []int{http.StatusNotFound},
174+
}
175+
176+
handler := wait.New(waitConfig.Wait())
177+
handler.SetTimeout(10 * time.Minute)
178+
return handler
179+
}

0 commit comments

Comments
 (0)