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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@
- `v1api`:
- **Feature:** Added optional `CreateCredentialsPayload` to `ApiCreateCredentialsRequest`.
- **Deprecation:** `FluentdTls`, `FluentdTlsCiphers`, `FluentdTlsMaxVersion`, `FluentdTlsMinVersion`, `FluentdTlsVersion`, `OpensearchTlsCiphers`, `OpensearchTlsProtocols` from `InstanceParameters` model are deprecated and will be removed 2026-12-12.
- [v1.0.1](services/logme/CHANGELOG.md#v101)
- `v2api`:
- **Bugfix**: Add missing waiter
- `logs`:
- [v0.7.3](services/logs/CHANGELOG.md#v073)
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1`
Expand Down
4 changes: 4 additions & 0 deletions services/logme/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.0.1
- `v2api`:
- **Bugfix**: Add missing waiter

## v1.0.0
- `v2api`:
- New package which can be used for communication with the logme v2 API
Expand Down
2 changes: 1 addition & 1 deletion services/logme/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.0
v1.0.1
152 changes: 152 additions & 0 deletions services/logme/v2api/wait/wait.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package wait

import (
"context"
"errors"
"fmt"
"net/http"
"strings"
"time"

"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/core/wait"
logme "github.com/stackitcloud/stackit-sdk-go/services/logme/v2api"
)

const (
// Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing

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.

Introducing deprecated code in a new file????

//go:fix inline
INSTANCESTATUS_ACTIVE = logme.INSTANCESTATUS_ACTIVE
// Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing
//go:fix inline
INSTANCESTATUS_FAILED = logme.INSTANCESTATUS_FAILED
// Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing
//go:fix inline
INSTANCESTATUS_STOPPED = logme.INSTANCESTATUS_STOPPED
// Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing
//go:fix inline
INSTANCESTATUS_CREATING = logme.INSTANCESTATUS_CREATING
// Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing
//go:fix inline
INSTANCESTATUS_DELETING = logme.INSTANCESTATUS_DELETING
// Deprecated: symbol is not used anymore, use the packages enum instead, will be removed 2026-12, use `go fix` for automatic fixing
//go:fix inline
INSTANCESTATUS_UPDATING = logme.INSTANCESTATUS_UPDATING
)

// CreateInstanceWaitHandler will wait for instance creation
func CreateInstanceWaitHandler(ctx context.Context, client logme.DefaultAPI, projectId, region, instanceId string) *wait.AsyncActionHandler[logme.Instance] {
waitConfig := wait.WaiterHelper[logme.Instance, logme.InstanceStatus]{
FetchInstance: client.GetInstance(ctx, projectId, region, instanceId).Execute,
GetState: func(response *logme.Instance) (logme.InstanceStatus, error) {
if response == nil {
return "", errors.New("empty response")
}
if response.Status == nil {
return "", errors.New("status is missing in response")
}
return *response.Status, nil
},
ActiveState: []logme.InstanceStatus{logme.INSTANCESTATUS_ACTIVE},
ErrorState: []logme.InstanceStatus{logme.INSTANCESTATUS_FAILED},
}

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

// PartialUpdateInstanceWaitHandler will wait for instance update
func PartialUpdateInstanceWaitHandler(ctx context.Context, client logme.DefaultAPI, projectId, region, instanceId string) *wait.AsyncActionHandler[logme.Instance] {
waitConfig := wait.WaiterHelper[logme.Instance, logme.InstanceStatus]{
FetchInstance: client.GetInstance(ctx, projectId, region, instanceId).Execute,
GetState: func(response *logme.Instance) (logme.InstanceStatus, error) {
if response == nil {
return "", errors.New("empty response")
}
if response.Status == nil {
return "", errors.New("status is missing in response")
}
return *response.Status, nil
},
ActiveState: []logme.InstanceStatus{logme.INSTANCESTATUS_ACTIVE},
ErrorState: []logme.InstanceStatus{logme.INSTANCESTATUS_FAILED},
}

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

// DeleteInstanceWaitHandler will wait for instance deletion
func DeleteInstanceWaitHandler(ctx context.Context, a logme.DefaultAPI, projectId, region, instanceId string) *wait.AsyncActionHandler[struct{}] {
handler := wait.New(func() (waitFinished bool, response *struct{}, err error) {
s, err := a.GetInstance(ctx, projectId, region, instanceId).Execute()
if err == nil {
if s.Status == nil {
return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The status is missing", instanceId)
}
if *s.Status == logme.INSTANCESTATUS_ACTIVE {
if strings.Contains(s.LastOperation.Description, "DeleteFailed") || strings.Contains(s.LastOperation.Description, "failed") {
return true, nil, fmt.Errorf("instance was deleted successfully but has errors: %s", s.LastOperation.Description)
}
return true, nil, nil
}
return false, nil, nil
}
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
if !ok {
return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError")
}
if oapiErr.StatusCode != http.StatusGone {
return false, nil, err
}
return true, nil, nil
})
handler.SetTimeout(15 * time.Minute)
return handler
}

// CreateCredentialsWaitHandler will wait for credentials creation
func CreateCredentialsWaitHandler(ctx context.Context, a logme.DefaultAPI, projectId, region, instanceId, credentialsId string) *wait.AsyncActionHandler[logme.CredentialsResponse] {
handler := wait.New(func() (waitFinished bool, response *logme.CredentialsResponse, err error) {
s, err := a.GetCredentials(ctx, projectId, region, instanceId, credentialsId).Execute()
if err != nil {
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
if !ok {
return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError")
}
// If the request returns 404, the credentials have not been created yet
if oapiErr.StatusCode == http.StatusNotFound {
return false, nil, nil
}
return false, nil, err
}
if s.Id == credentialsId {
return true, s, nil
}
return false, nil, nil
})
handler.SetTimeout(1 * time.Minute)
return handler
}

// DeleteCredentialsWaitHandler will wait for credentials deletion
func DeleteCredentialsWaitHandler(ctx context.Context, a logme.DefaultAPI, projectId, region, instanceId, credentialsId string) *wait.AsyncActionHandler[struct{}] {
handler := wait.New(func() (waitFinished bool, response *struct{}, err error) {
_, err = a.GetCredentials(ctx, projectId, region, instanceId, credentialsId).Execute()
if err == nil {
return false, nil, nil
}
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
if !ok {
return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError")
}
if oapiErr.StatusCode != http.StatusNotFound && oapiErr.StatusCode != http.StatusGone {
return false, nil, err
}
return true, nil, nil
})
handler.SetTimeout(1 * time.Minute)
return handler
}
Loading
Loading