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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Release (2025-XX-YY)
- `cdn`: [v0.3.0](services/cdn/CHANGELOG.md#v030-2025-04-04)
- **New:** Add waiter for creation of `CustomDomain`

## Release (2025-XX-YY)
- `cdn`: [v0.2.0](services/cdn/CHANGELOG.md#v020-2025-04-01)
- **API enhancement:** Provide waiter infrastructure
Expand Down
23 changes: 23 additions & 0 deletions patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2c8562e1..649d463b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## Release (2025-XX-YY)
+ - `cdn`: [v0.3.0](services/cdn/CHANGELOG.md#v030-2025-04-04)
+ - **New:** Add waiter for creation of `CustomDomain`
+
## Release (2025-XX-YY)
- `cdn`: [v0.2.0](services/cdn/CHANGELOG.md#v020-2025-04-01)
- **API enhancement:** Provide waiter infrastructure
diff --git a/services/cdn/CHANGELOG.md b/services/cdn/CHANGELOG.md
index dd315f01..b8e57e59 100644
--- a/services/cdn/CHANGELOG.md
+++ b/services/cdn/CHANGELOG.md
@@ -1,3 +1,6 @@
+## v0.3.0 (2025-04-04)
+- **New:** Add waiter for creation of `CustomDomain`
+
## v0.2.0 (2025-04-01)
- **API enhancement:** Provide waiter infrastructure

3 changes: 3 additions & 0 deletions services/cdn/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.3.0 (2025-04-04)
- **New:** Add waiter for creation of `CustomDomain`

## v0.2.0 (2025-04-01)
- **API enhancement:** Provide waiter infrastructure

Expand Down
1 change: 1 addition & 0 deletions services/cdn/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/stackitcloud/stackit-sdk-go/services/cdn
go 1.21

require (
github.com/google/go-cmp v0.7.0
github.com/google/uuid v1.6.0
github.com/stackitcloud/stackit-sdk-go/core v0.16.2
)
Expand Down
105 changes: 83 additions & 22 deletions services/cdn/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import (
)

const (
DistributionStateCreating = "CREATING"
DistributionStateActive = "ACTIVE"
DistributionStateUpdating = "UPDATING"
DistributionStateDeleting = "DELETING"
DistributionStateError = "ERROR"
DistributionStatusCreating = "CREATING"
DistributionStatusActive = "ACTIVE"
DistributionStatusUpdating = "UPDATING"
DistributionStatusDeleting = "DELETING"
DistributionStatusError = "ERROR"
)

// Interfaces needed for tests
type APIClientInterface interface {
GetDistributionExecute(ctx context.Context, projectId string, distributionId string) (*cdn.GetDistributionResponse, error)
GetCustomDomainExecute(ctx context.Context, projectId string, distributionId string, domain string) (*cdn.GetCustomDomainResponse, error)
}

func CreateDistributionPoolWaitHandler(ctx context.Context, api APIClientInterface, projectId, distributionId string) *wait.AsyncActionHandler[cdn.GetDistributionResponse] {
Expand All @@ -39,17 +40,21 @@ func CreateDistributionPoolWaitHandler(ctx context.Context, api APIClientInterfa
}
if *distribution.Distribution.Id == distributionId {
switch *distribution.Distribution.Status {
case DistributionStateActive:
return true, distribution, err
case DistributionStatusActive:
return true, distribution, nil
case DistributionStatusCreating, DistributionStatusUpdating:
return false, nil, nil
case DistributionStatusDeleting:
return true, nil, fmt.Errorf("creating CDN distribution failed")
case DistributionStatusError:
return true, nil, fmt.Errorf("creating CDN distribution failed")
default:
return false, distribution, err
return true, nil, fmt.Errorf("CDNDistributionWaitHandler: unexpected status %s", *distribution.Distribution.Status)
}
}

return false, nil, nil
})

handler.SetTimeout(10 * time.Minute)
handler.SetTimeout(1 * time.Minute)
return handler
}

Expand All @@ -67,10 +72,16 @@ func UpdateDistributionWaitHandler(ctx context.Context, api APIClientInterface,
}
if *distribution.Distribution.Id == distributionId {
switch *distribution.Distribution.Status {
case DistributionStateActive:
case DistributionStatusActive:
return true, distribution, err
case DistributionStatusUpdating:
return false, nil, nil
case DistributionStatusDeleting:
return true, nil, fmt.Errorf("updating CDN distribution failed")
case DistributionStatusError:
return true, nil, fmt.Errorf("updating CDN distribution failed")
default:
return false, distribution, err
return true, nil, fmt.Errorf("UpdateDistributionWaitHandler: unexpected status %s", *distribution.Distribution.Status)
}
}

Expand All @@ -83,18 +94,68 @@ func UpdateDistributionWaitHandler(ctx context.Context, api APIClientInterface,

func DeleteDistributionWaitHandler(ctx context.Context, api APIClientInterface, projectId, distributionId string) *wait.AsyncActionHandler[cdn.GetDistributionResponse] {
handler := wait.New(func() (waitFinished bool, distribution *cdn.GetDistributionResponse, err error) {
distribution, err = api.GetDistributionExecute(ctx, projectId, distributionId)
if err != nil {
var oapiError *oapierror.GenericOpenAPIError
if errors.As(err, &oapiError) {
if statusCode := oapiError.StatusCode; statusCode == http.StatusNotFound || statusCode == http.StatusGone {
return true, distribution, nil
}
_, err = api.GetDistributionExecute(ctx, projectId, distributionId)

// the distribution is still gettable, e.g. not deleted
if err == nil {
return false, nil, nil
}
var oapiError *oapierror.GenericOpenAPIError
if errors.As(err, &oapiError) {
if statusCode := oapiError.StatusCode; statusCode == http.StatusNotFound || statusCode == http.StatusGone {
return true, nil, nil
}
}
return false, nil, nil

return false, nil, err
})
handler.SetTimeout(30 * time.Second)
return handler
}

handler.SetTimeout(10 * time.Minute)
func CreateCDNCustomDomainWaitHandler(ctx context.Context, a APIClientInterface, projectId, distributionId, domain string) *wait.AsyncActionHandler[cdn.CustomDomain] {
handler := wait.New(func() (waitFinished bool, response *cdn.CustomDomain, err error) {
resp, err := a.GetCustomDomainExecute(ctx, projectId, distributionId, domain)
if err != nil {
return false, nil, err
}
if resp == nil || resp.CustomDomain == nil || resp.CustomDomain.Status == nil {
return false, nil, errors.New("CDNDistributionWaitHandler: status or custom domain missing in response")
}

switch *resp.CustomDomain.Status {
case cdn.DOMAINSTATUS_ACTIVE:
return true, resp.CustomDomain, nil
case cdn.DOMAINSTATUS_CREATING, cdn.DOMAINSTATUS_UPDATING:
return false, nil, nil
case cdn.DOMAINSTATUS_DELETING:
return true, nil, fmt.Errorf("creating CDN custom domain failed")
case cdn.DOMAINSTATUS_ERROR:
return true, nil, fmt.Errorf("creating CDN custom domain failed")
default:
return true, nil, fmt.Errorf("CDNCustomDomainWaitHandler: unexpected status %s", *resp.CustomDomain.Status)
}
})
handler.SetTimeout(1 * time.Minute)
return handler
}

func DeleteCDNCustomDomainWaitHandler(ctx context.Context, a APIClientInterface, projectId, distributionId, domain string) *wait.AsyncActionHandler[cdn.CustomDomain] {
handler := wait.New(func() (waitFinished bool, response *cdn.CustomDomain, err error) {
_, err = a.GetCustomDomainExecute(ctx, projectId, distributionId, domain)

// the custom domain is still gettable, e.g. not deleted
if err == nil {
return false, nil, nil
}
var oapiError *oapierror.GenericOpenAPIError
if errors.As(err, &oapiError) {
if statusCode := oapiError.StatusCode; statusCode == http.StatusNotFound || statusCode == http.StatusGone {
return true, nil, nil
}
}
return false, nil, err
})
handler.SetTimeout(30 * time.Second)
return handler
}
Loading
Loading