Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@
- **Dependencies:** Bump STACKIT SDK core module to `v0.26.0`
- [v1.5.3](services/serviceenablement/CHANGELOG.md#v153)
- `v2api`: Removal of duplicated return statements in `DefaultAPIService` implementations
- [v1.6.0](services/serviceenablement/CHANGELOG.md#v160)
- **Improvement:** Use new WaiterHelper for serviceenablement waiters
- `sfs`:
- [v0.6.3](services/sfs/CHANGELOG.md#v063)
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1`
Expand Down
3 changes: 3 additions & 0 deletions services/serviceenablement/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v1.6.0
- **Improvement:** Use new WaiterHelper for serviceenablement waiters

## v1.5.3
- `v2api`: Removal of duplicated return statements in `DefaultAPIService` implementations

Expand Down
2 changes: 1 addition & 1 deletion services/serviceenablement/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.5.3
v1.6.0
77 changes: 34 additions & 43 deletions services/serviceenablement/v2api/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package wait

import (
"context"
"fmt"
"errors"
"time"

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

// EnableServiceWaitHandler will wait for service enablement
func EnableServiceWaitHandler(ctx context.Context, a serviceenablement.DefaultAPI, region, projectId, serviceId string) *wait.AsyncActionHandler[serviceenablement.ServiceStatus] {
handler := wait.New(func() (waitFinished bool, response *serviceenablement.ServiceStatus, err error) {
s, err := a.GetServiceStatusRegional(ctx, region, projectId, serviceId).Execute()
if err != nil {
return false, nil, err
}
if s == nil || s.State == nil {
return false, nil, nil
}
switch *s.State {
default:
return true, s, fmt.Errorf("service with id %s has unexpected state %s", serviceId, *s.State)
case SERVICESTATUSSTATE_ENABLED:
return true, s, nil
case SERVICESTATUSSTATE_ENABLING:
return false, nil, nil
case SERVICESTATUSSTATE_DISABLED:
return true, s, fmt.Errorf("enabling failed for service with id %s", serviceId)
case SERVICESTATUSSTATE_DISABLING:
return true, s, fmt.Errorf("service with id %s is in state %s", serviceId, *s.State)
}
})
waitConfig := wait.WaiterHelper[serviceenablement.ServiceStatus, string]{
FetchInstance: a.GetServiceStatusRegional(ctx, region, projectId, serviceId).Execute,
GetState: func(s *serviceenablement.ServiceStatus) (string, error) {
if s == nil {
return "", errors.New("empty response")
}
if s.State == nil {
return "", errors.New("state is missing")
}
return *s.State, nil
},
ActiveState: []string{SERVICESTATUSSTATE_ENABLED},
ErrorState: []string{SERVICESTATUSSTATE_DISABLED, SERVICESTATUSSTATE_DISABLING},
}

handler := wait.New(waitConfig.Wait())
handler.SetTimeout(45 * time.Minute).SetSleepBeforeWait(15 * time.Second)
return handler
}

// DisableServiceWaitHandler will wait for service disablement
func DisableServiceWaitHandler(ctx context.Context, a serviceenablement.DefaultAPI, region, projectId, serviceId string) *wait.AsyncActionHandler[serviceenablement.ServiceStatus] {
handler := wait.New(func() (waitFinished bool, response *serviceenablement.ServiceStatus, err error) {
s, err := a.GetServiceStatusRegional(ctx, region, projectId, serviceId).Execute()
if err != nil {
return false, nil, err
}
if s == nil || s.State == nil {
return false, nil, nil
}
switch *s.State {
default:
return true, s, fmt.Errorf("service with id %s has unexpected state %s", serviceId, *s.State)
case SERVICESTATUSSTATE_DISABLED:
return true, s, nil
case SERVICESTATUSSTATE_DISABLING:
return false, nil, nil
case SERVICESTATUSSTATE_ENABLED:
return true, s, fmt.Errorf("disabling failed for service with id %s", serviceId)
case SERVICESTATUSSTATE_ENABLING:
return true, s, fmt.Errorf("service with id %s is in state %s", serviceId, *s.State)
}
})
waitConfig := wait.WaiterHelper[serviceenablement.ServiceStatus, string]{
FetchInstance: a.GetServiceStatusRegional(ctx, region, projectId, serviceId).Execute,
GetState: func(s *serviceenablement.ServiceStatus) (string, error) {
if s == nil {
return "", errors.New("empty response")
}
if s.State == nil {
return "", errors.New("status is missing")
}
return *s.State, nil
},
ActiveState: []string{SERVICESTATUSSTATE_DISABLED},
ErrorState: []string{SERVICESTATUSSTATE_ENABLED, SERVICESTATUSSTATE_ENABLING},
}

handler := wait.New(waitConfig.Wait())
handler.SetTimeout(45 * time.Minute).SetSleepBeforeWait(15 * time.Second)
return handler
}
Loading