Skip to content

Commit f3d2f83

Browse files
authored
Merge branch 'main' into generator-bot-26237997285/vpn
2 parents 26bb9c5 + 3e749fc commit f3d2f83

4 files changed

Lines changed: 40 additions & 44 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@
407407
- **Dependencies:** Bump STACKIT SDK core module to `v0.26.0`
408408
- [v1.5.3](services/serviceenablement/CHANGELOG.md#v153)
409409
- `v2api`: Removal of duplicated return statements in `DefaultAPIService` implementations
410+
- [v1.6.0](services/serviceenablement/CHANGELOG.md#v160)
411+
- **Improvement:** Use new WaiterHelper for serviceenablement waiters
410412
- `sfs`:
411413
- [v0.6.3](services/sfs/CHANGELOG.md#v063)
412414
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1`

services/serviceenablement/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v1.6.0
2+
- **Improvement:** Use new WaiterHelper for serviceenablement waiters
3+
14
## v1.5.3
25
- `v2api`: Removal of duplicated return statements in `DefaultAPIService` implementations
36

services/serviceenablement/VERSION

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

services/serviceenablement/v2api/wait/wait.go

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package wait
22

33
import (
44
"context"
5-
"fmt"
5+
"errors"
66
"time"
77

88
"github.com/stackitcloud/stackit-sdk-go/core/wait"
@@ -16,55 +16,46 @@ const (
1616
SERVICESTATUSSTATE_DISABLING = "DISABLING"
1717
)
1818

19+
// EnableServiceWaitHandler will wait for service enablement
1920
func EnableServiceWaitHandler(ctx context.Context, a serviceenablement.DefaultAPI, region, projectId, serviceId string) *wait.AsyncActionHandler[serviceenablement.ServiceStatus] {
20-
handler := wait.New(func() (waitFinished bool, response *serviceenablement.ServiceStatus, err error) {
21-
s, err := a.GetServiceStatusRegional(ctx, region, projectId, serviceId).Execute()
22-
if err != nil {
23-
return false, nil, err
24-
}
25-
if s == nil || s.State == nil {
26-
return false, nil, nil
27-
}
28-
switch *s.State {
29-
default:
30-
return true, s, fmt.Errorf("service with id %s has unexpected state %s", serviceId, *s.State)
31-
case SERVICESTATUSSTATE_ENABLED:
32-
return true, s, nil
33-
case SERVICESTATUSSTATE_ENABLING:
34-
return false, nil, nil
35-
case SERVICESTATUSSTATE_DISABLED:
36-
return true, s, fmt.Errorf("enabling failed for service with id %s", serviceId)
37-
case SERVICESTATUSSTATE_DISABLING:
38-
return true, s, fmt.Errorf("service with id %s is in state %s", serviceId, *s.State)
39-
}
40-
})
21+
waitConfig := wait.WaiterHelper[serviceenablement.ServiceStatus, string]{
22+
FetchInstance: a.GetServiceStatusRegional(ctx, region, projectId, serviceId).Execute,
23+
GetState: func(s *serviceenablement.ServiceStatus) (string, error) {
24+
if s == nil {
25+
return "", errors.New("empty response")
26+
}
27+
if s.State == nil {
28+
return "", errors.New("state is missing")
29+
}
30+
return *s.State, nil
31+
},
32+
ActiveState: []string{SERVICESTATUSSTATE_ENABLED},
33+
ErrorState: []string{SERVICESTATUSSTATE_DISABLED, SERVICESTATUSSTATE_DISABLING},
34+
}
4135

36+
handler := wait.New(waitConfig.Wait())
4237
handler.SetTimeout(45 * time.Minute).SetSleepBeforeWait(15 * time.Second)
4338
return handler
4439
}
4540

41+
// DisableServiceWaitHandler will wait for service disablement
4642
func DisableServiceWaitHandler(ctx context.Context, a serviceenablement.DefaultAPI, region, projectId, serviceId string) *wait.AsyncActionHandler[serviceenablement.ServiceStatus] {
47-
handler := wait.New(func() (waitFinished bool, response *serviceenablement.ServiceStatus, err error) {
48-
s, err := a.GetServiceStatusRegional(ctx, region, projectId, serviceId).Execute()
49-
if err != nil {
50-
return false, nil, err
51-
}
52-
if s == nil || s.State == nil {
53-
return false, nil, nil
54-
}
55-
switch *s.State {
56-
default:
57-
return true, s, fmt.Errorf("service with id %s has unexpected state %s", serviceId, *s.State)
58-
case SERVICESTATUSSTATE_DISABLED:
59-
return true, s, nil
60-
case SERVICESTATUSSTATE_DISABLING:
61-
return false, nil, nil
62-
case SERVICESTATUSSTATE_ENABLED:
63-
return true, s, fmt.Errorf("disabling failed for service with id %s", serviceId)
64-
case SERVICESTATUSSTATE_ENABLING:
65-
return true, s, fmt.Errorf("service with id %s is in state %s", serviceId, *s.State)
66-
}
67-
})
43+
waitConfig := wait.WaiterHelper[serviceenablement.ServiceStatus, string]{
44+
FetchInstance: a.GetServiceStatusRegional(ctx, region, projectId, serviceId).Execute,
45+
GetState: func(s *serviceenablement.ServiceStatus) (string, error) {
46+
if s == nil {
47+
return "", errors.New("empty response")
48+
}
49+
if s.State == nil {
50+
return "", errors.New("status is missing")
51+
}
52+
return *s.State, nil
53+
},
54+
ActiveState: []string{SERVICESTATUSSTATE_DISABLED},
55+
ErrorState: []string{SERVICESTATUSSTATE_ENABLED, SERVICESTATUSSTATE_ENABLING},
56+
}
57+
58+
handler := wait.New(waitConfig.Wait())
6859
handler.SetTimeout(45 * time.Minute).SetSleepBeforeWait(15 * time.Second)
6960
return handler
7061
}

0 commit comments

Comments
 (0)