Skip to content
Open
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 @@ -149,6 +149,8 @@
- **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0`
- [v0.9.0](services/intake/CHANGELOG.md#v090)
- **Feature:** Added `_UNKNOWN_DEFAULT_OPEN_API` fallback value to all enums to handle unknown API values gracefully.
- [v0.10.0](services/intake/CHANGELOG.md#v0100)
- `v1betaapi`: **Improvement**: Use new `WaiterHandler` struct in the Git WaitHandler
- `kms`:
- [v1.6.2](services/kms/CHANGELOG.md#v162)
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1`
Expand Down
3 changes: 3 additions & 0 deletions services/intake/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.10.0
- `v1betaapi`: **Improvement**: Use new `WaiterHandler` struct in the Intake WaitHandler

## v0.9.0
- **Feature:** Added `_UNKNOWN_DEFAULT_OPEN_API` fallback value to all enums to handle unknown API values gracefully.

Expand Down
2 changes: 1 addition & 1 deletion services/intake/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.9.0
v0.10.0
218 changes: 115 additions & 103 deletions services/intake/v1betaapi/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package wait
import (
"context"
"errors"
"fmt"
"net/http"
"time"

"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/core/wait"
intake "github.com/stackitcloud/stackit-sdk-go/services/intake/v1betaapi"
)
Expand All @@ -27,133 +25,147 @@ const (
INTAKEUSERRESPONSESTATE_DELETING = "deleting"
)

func CreateOrUpdateIntakeRunnerWaitHandler(ctx context.Context, a intake.DefaultAPI, projectId, region, intakeRunnerId string) *wait.AsyncActionHandler[intake.IntakeRunnerResponse] {
handler := wait.New(func() (waitFinished bool, response *intake.IntakeRunnerResponse, err error) {
runner, err := a.GetIntakeRunner(ctx, projectId, region, intakeRunnerId).Execute()
if err != nil {
return false, nil, err
}

if runner == nil {
return false, nil, fmt.Errorf("API returned a nil response for Intake Runner %s", intakeRunnerId)
}

if runner.Id == intakeRunnerId && runner.State == INTAKERUNNERRESPONSESTATE_ACTIVE {
return true, runner, nil
}

// Deprecated: Will be removed after 2026-11-13. Use the CreateIntakeRunnerWaitHandler or UpdateIntakeRunnerWaitHandler instead
func CreateOrUpdateIntakeRunnerWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeRunnerId string) *wait.AsyncActionHandler[intake.IntakeRunnerResponse] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here :)

// TODO: mark function as private after deprecation period
waitConfig := wait.WaiterHelper[intake.IntakeRunnerResponse, string]{
FetchInstance: client.GetIntakeRunner(ctx, projectId, region, intakeRunnerId).Execute,
GetState: func(response *intake.IntakeRunnerResponse) (string, error) {
if response == nil {
return "", errors.New("empty response")
}
return response.State, nil
},
ActiveState: []string{INTAKERUNNERRESPONSESTATE_ACTIVE},
ErrorState: []string{},
// The API does not have a dedicated failure state for this resource,
// so we rely on the timeout for cases where it never becomes active.
return false, nil, nil
})
}

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

func DeleteIntakeRunnerWaitHandler(ctx context.Context, a intake.DefaultAPI, projectId, region, intakeRunnerId string) *wait.AsyncActionHandler[intake.IntakeRunnerResponse] {
handler := wait.New(func() (waitFinished bool, response *intake.IntakeRunnerResponse, err error) {
_, err = a.GetIntakeRunner(ctx, projectId, region, intakeRunnerId).Execute()
if err == nil {
// Resource still exists
return false, nil, nil
}

var oapiError *oapierror.GenericOpenAPIError
if errors.As(err, &oapiError) {
if oapiError.StatusCode == http.StatusNotFound {
// Success: Resource is gone
return true, nil, nil
func CreateIntakeRunnerWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeRunnerId string) *wait.AsyncActionHandler[intake.IntakeRunnerResponse] {
return CreateOrUpdateIntakeRunnerWaitHandler(ctx, client, projectId, region, intakeRunnerId)
}

func UpdateIntakeRunnerWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeRunnerId string) *wait.AsyncActionHandler[intake.IntakeRunnerResponse] {
return CreateOrUpdateIntakeRunnerWaitHandler(ctx, client, projectId, region, intakeRunnerId)
}

func DeleteIntakeRunnerWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeRunnerId string) *wait.AsyncActionHandler[intake.IntakeRunnerResponse] {
waitConfig := wait.WaiterHelper[intake.IntakeRunnerResponse, string]{
FetchInstance: client.GetIntakeRunner(ctx, projectId, region, intakeRunnerId).Execute,
GetState: func(response *intake.IntakeRunnerResponse) (string, error) {
if response == nil {
return "", errors.New("empty response")
}
}
// An unexpected error occurred
return false, nil, err
})
return response.State, nil
},
ActiveState: []string{},
ErrorState: []string{},
DeleteHttpErrorStatusCodes: []int{http.StatusNotFound},
}

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

func CreateOrUpdateIntakeWaitHandler(ctx context.Context, a intake.DefaultAPI, projectId, region, intakeId string) *wait.AsyncActionHandler[intake.IntakeResponse] {
handler := wait.New(func() (waitFinished bool, response *intake.IntakeResponse, err error) {
ik, err := a.GetIntake(ctx, projectId, region, intakeId).Execute()
if err != nil {
return false, nil, err
}

if ik == nil {
return false, nil, fmt.Errorf("API returned a nil response for Intake %s", intakeId)
}

if ik.Id == intakeId && ik.State == INTAKERESPONSESTATE_ACTIVE {
return true, ik, nil
}

if ik.Id == intakeId && ik.State == INTAKERESPONSESTATE_FAILED {
return true, ik, fmt.Errorf("create/update failed for Intake %s", intakeId)
}
// Deprecated: Will be removed after 2026-11-13. Use the CreateIntakeWaitHandler or UpdateIntakeWaitHandler instead
func CreateOrUpdateIntakeWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeId string) *wait.AsyncActionHandler[intake.IntakeResponse] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here :)

// TODO: mark function as private after deprecation period
waitConfig := wait.WaiterHelper[intake.IntakeResponse, string]{
FetchInstance: client.GetIntake(ctx, projectId, region, intakeId).Execute,
GetState: func(response *intake.IntakeResponse) (string, error) {
if response == nil {
return "", errors.New("empty response")
}
return response.State, nil
},
ActiveState: []string{INTAKERUNNERRESPONSESTATE_ACTIVE},
ErrorState: []string{INTAKERESPONSESTATE_FAILED},
}

return false, nil, nil
})
handler := wait.New(waitConfig.Wait())
handler.SetTimeout(10 * time.Minute)
return handler
}

func DeleteIntakeWaitHandler(ctx context.Context, a intake.DefaultAPI, projectId, region, intakeId string) *wait.AsyncActionHandler[intake.IntakeResponse] {
handler := wait.New(func() (waitFinished bool, response *intake.IntakeResponse, err error) {
_, err = a.GetIntake(ctx, projectId, region, intakeId).Execute()
if err == nil {
return false, nil, nil
}

var oapiError *oapierror.GenericOpenAPIError
if errors.As(err, &oapiError) {
if oapiError.StatusCode == http.StatusNotFound {
return true, nil, nil
func CreateIntakeWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeId string) *wait.AsyncActionHandler[intake.IntakeResponse] {
return CreateOrUpdateIntakeWaitHandler(ctx, client, projectId, region, intakeId)
}

func UpdateIntakeWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeId string) *wait.AsyncActionHandler[intake.IntakeResponse] {
return CreateOrUpdateIntakeWaitHandler(ctx, client, projectId, region, intakeId)
}

func DeleteIntakeWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeId string) *wait.AsyncActionHandler[intake.IntakeResponse] {
waitConfig := wait.WaiterHelper[intake.IntakeResponse, string]{
FetchInstance: client.GetIntake(ctx, projectId, region, intakeId).Execute,
GetState: func(response *intake.IntakeResponse) (string, error) {
if response == nil {
return "", errors.New("empty response")
}
}
return false, nil, err
})
return response.State, nil
},
ActiveState: []string{},
ErrorState: []string{},
DeleteHttpErrorStatusCodes: []int{http.StatusNotFound},
}

handler := wait.New(waitConfig.Wait())
handler.SetTimeout(10 * time.Minute)
return handler
}

func CreateOrUpdateIntakeUserWaitHandler(ctx context.Context, a intake.DefaultAPI, projectId, region, intakeId, intakeUserId string) *wait.AsyncActionHandler[intake.IntakeUserResponse] {
handler := wait.New(func() (waitFinished bool, response *intake.IntakeUserResponse, err error) {
user, err := a.GetIntakeUser(ctx, projectId, region, intakeId, intakeUserId).Execute()
if err != nil {
return false, nil, err
}

if user == nil {
return false, nil, fmt.Errorf("API returned a nil response for Intake User %s", intakeUserId)
}

if user.Id == intakeUserId && user.State == INTAKEUSERRESPONSESTATE_ACTIVE {
return true, user, nil
}

// The API does not have a dedicated failure state for this resource, we rely on the timeout for cases where
// it never becomes active.
return false, nil, nil
})
// Deprecated: Will be removed after 2026-11-13. Use the CreateIntakeUserWaitHandler or UpdateIntakeUserWaitHandler instead
func CreateOrUpdateIntakeUserWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeId, intakeUserId string) *wait.AsyncActionHandler[intake.IntakeUserResponse] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can directly apply the thing I mentioned in the daily here

// Deprecated: Will be removed after YYYY-MM-DD. Use the CreateIntakeUserWaitHandler or UpdateIntakeUserWaitHandler instead
func CreateOrUpdateIntakeUserWaitHandler(...) ... {
    // TODO: mark function as private after deprecation period

   // keep the existing logic
}

func CreateIntakeUserWaitHandler(...) ... {
  return CreateOrUpdateIntakeUserWaitHandler(...)
}

func UpdateIntakeUserWaitHandler(...) ... {
  return CreateOrUpdateIntakeUserWaitHandler(...)
}

Deprecation period: now + 6 months

// TODO: mark function as private after deprecation period
waitConfig := wait.WaiterHelper[intake.IntakeUserResponse, string]{
FetchInstance: client.GetIntakeUser(ctx, projectId, region, intakeId, intakeUserId).Execute,
GetState: func(response *intake.IntakeUserResponse) (string, error) {
if response == nil {
return "", errors.New("empty response")
}
return response.State, nil
},
ActiveState: []string{INTAKEUSERRESPONSESTATE_ACTIVE},
ErrorState: []string{},
// The API does not have a dedicated failure state for this resource,
// so we rely on the timeout for cases where it never becomes active.
}

handler := wait.New(waitConfig.Wait())
handler.SetTimeout(5 * time.Minute)
return handler
}

func DeleteIntakeUserWaitHandler(ctx context.Context, a intake.DefaultAPI, projectId, region, intakeId, intakeUserId string) *wait.AsyncActionHandler[intake.IntakeUserResponse] {
handler := wait.New(func() (waitFinished bool, response *intake.IntakeUserResponse, err error) {
_, err = a.GetIntakeUser(ctx, projectId, region, intakeId, intakeUserId).Execute()
if err == nil {
return false, nil, nil
}

var oapiError *oapierror.GenericOpenAPIError
if errors.As(err, &oapiError) {
if oapiError.StatusCode == http.StatusNotFound {
return true, nil, nil
func CreateIntakeUserWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeId, intakeUserId string) *wait.AsyncActionHandler[intake.IntakeUserResponse] {
return CreateOrUpdateIntakeUserWaitHandler(ctx, client, projectId, region, intakeId, intakeUserId)
}

func UpdateIntakeUserWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeId, intakeUserId string) *wait.AsyncActionHandler[intake.IntakeUserResponse] {
return CreateOrUpdateIntakeUserWaitHandler(ctx, client, projectId, region, intakeId, intakeUserId)
}

func DeleteIntakeUserWaitHandler(ctx context.Context, client intake.DefaultAPI, projectId, region, intakeId, intakeUserId string) *wait.AsyncActionHandler[intake.IntakeUserResponse] {
waitConfig := wait.WaiterHelper[intake.IntakeUserResponse, string]{
FetchInstance: client.GetIntakeUser(ctx, projectId, region, intakeId, intakeUserId).Execute,
GetState: func(response *intake.IntakeUserResponse) (string, error) {
if response == nil {
return "", errors.New("empty response")
}
}
return false, nil, err
})
return response.State, nil
},
ActiveState: []string{},
ErrorState: []string{},
DeleteHttpErrorStatusCodes: []int{http.StatusNotFound},
}

handler := wait.New(waitConfig.Wait())
handler.SetTimeout(5 * time.Minute)
return handler
}
Loading
Loading