Skip to content

Commit 97216cc

Browse files
committed
waiters, changelogs
1 parent bca5f63 commit 97216cc

6 files changed

Lines changed: 821 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@
6666
- `v1betaapi`: New package which can be used for communication with the intake v1 beta API
6767
- **Deprecation:** The contents in the root of this SDK module including the `wait` package are marked as deprecated and will be removed after 2026-09-30. Switch to the new packages for the available API versions instead.
6868
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
69+
- `cdn`: [v1.11.0](services/cdn/CHANGELOG.md#v1110)
70+
- **Feature:** Introduction of multi API version support for the cdn SDK module. For more details please see the announcement on GitHub: https://github.com/stackitcloud/stackit-sdk-go/discussions/5062
71+
- `v1api`: New package which can be used for communication with the cdn v1 API
72+
- `v1betaapi`: New package which can be used for communication with the cdn v1 beta API
73+
- `v1beta2api`: New package which can be used for communication with the cdn v1 beta2 API
74+
- **Deprecation:** The contents in the root of this SDK module including the `wait` package are marked as deprecated and will be removed after 2026-09-30. Switch to the new packages for the available API versions instead.
75+
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
6976

7077
## Release (2026-02-20)
7178
- `core`: [v0.21.1](core/CHANGELOG.md#v0211)

services/cdn/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v1.11.0
2+
- **Feature:** Introduction of multi API version support for the cdn SDK module. For more details please see the announcement on GitHub: https://github.com/stackitcloud/stackit-sdk-go/discussions/5062
3+
- `v1api`: New package which can be used for communication with the cdn v1 API
4+
- `v1betaapi`: New package which can be used for communication with the cdn v1 beta API
5+
- `v1beta2api`: New package which can be used for communication with the cdn v1 beta2 API
6+
- **Deprecation:** The contents in the root of this SDK module including the `wait` package are marked as deprecated and will be removed after 2026-09-30. Switch to the new packages for the available API versions instead.
7+
- **Dependencies:** Bump STACKIT SDK core module from `v0.21.1` to `v0.22.0`
8+
19
## v1.10.0
210
- **Feature:** Add support for `RedirectConfig` in `Config`, `ConfigPatch` and `CreateDistributionPayload` models
311
- new related models `RedirectConfig`, `RedirectRule`, `Matcher` and `MatchCondition`

services/cdn/VERSION

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

services/cdn/v1api/wait/wait.go

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package wait
2+
3+
import (
4+
"context"
5+
"errors"
6+
"fmt"
7+
"net/http"
8+
"time"
9+
10+
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
11+
"github.com/stackitcloud/stackit-sdk-go/core/wait"
12+
cdn "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"
13+
)
14+
15+
const (
16+
DISTRIBUTIONSTATUS_CREATING = "CREATING"
17+
DISTRIBUTIONSTATUS_ACTIVE = "ACTIVE"
18+
DISTRIBUTIONSTATUS_UPDATING = "UPDATING"
19+
DISTRIBUTIONSTATUS_DELETING = "DELETING"
20+
DISTRIBUTIONSTATUS_ERROR = "ERROR"
21+
)
22+
23+
func CreateDistributionPoolWaitHandler(ctx context.Context, api cdn.DefaultAPI, projectId, distributionId string) *wait.AsyncActionHandler[cdn.GetDistributionResponse] {
24+
handler := wait.New(func() (waitFinished bool, distribution *cdn.GetDistributionResponse, err error) {
25+
distribution, err = api.GetDistribution(ctx, projectId, distributionId).Execute()
26+
if err != nil {
27+
return false, distribution, err
28+
}
29+
if distribution == nil {
30+
return false, distribution, fmt.Errorf("create failed for distribution with id %s, the response is nil", distributionId)
31+
}
32+
if distribution.Distribution.Id == distributionId {
33+
switch distribution.Distribution.Status {
34+
case DISTRIBUTIONSTATUS_ACTIVE:
35+
return true, distribution, nil
36+
case DISTRIBUTIONSTATUS_CREATING, DISTRIBUTIONSTATUS_UPDATING:
37+
return false, nil, nil
38+
case DISTRIBUTIONSTATUS_DELETING:
39+
return true, nil, fmt.Errorf("creating CDN distribution failed")
40+
case DISTRIBUTIONSTATUS_ERROR:
41+
return true, nil, fmt.Errorf("creating CDN distribution failed")
42+
default:
43+
return true, nil, fmt.Errorf("CDNDistributionWaitHandler: unexpected status %s", distribution.Distribution.Status)
44+
}
45+
}
46+
return false, nil, nil
47+
})
48+
handler.SetTimeout(10 * time.Minute)
49+
return handler
50+
}
51+
52+
func UpdateDistributionWaitHandler(ctx context.Context, api cdn.DefaultAPI, projectId, distributionId string) *wait.AsyncActionHandler[cdn.GetDistributionResponse] {
53+
handler := wait.New(func() (waitFinished bool, distribution *cdn.GetDistributionResponse, err error) {
54+
distribution, err = api.GetDistribution(ctx, projectId, distributionId).Execute()
55+
if err != nil {
56+
return false, distribution, err
57+
}
58+
if distribution == nil {
59+
return false, distribution, fmt.Errorf("update failed for distribution with id %s, the response is nil", distributionId)
60+
}
61+
if distribution.Distribution.Id == distributionId {
62+
switch distribution.Distribution.Status {
63+
case DISTRIBUTIONSTATUS_ACTIVE:
64+
return true, distribution, err
65+
case DISTRIBUTIONSTATUS_UPDATING:
66+
return false, nil, nil
67+
case DISTRIBUTIONSTATUS_DELETING:
68+
return true, nil, fmt.Errorf("updating CDN distribution failed")
69+
case DISTRIBUTIONSTATUS_ERROR:
70+
return true, nil, fmt.Errorf("updating CDN distribution failed")
71+
default:
72+
return true, nil, fmt.Errorf("UpdateDistributionWaitHandler: unexpected status %s", distribution.Distribution.Status)
73+
}
74+
}
75+
76+
return false, nil, nil
77+
})
78+
79+
handler.SetTimeout(10 * time.Minute)
80+
return handler
81+
}
82+
83+
func DeleteDistributionWaitHandler(ctx context.Context, api cdn.DefaultAPI, projectId, distributionId string) *wait.AsyncActionHandler[cdn.GetDistributionResponse] {
84+
handler := wait.New(func() (waitFinished bool, distribution *cdn.GetDistributionResponse, err error) {
85+
_, err = api.GetDistribution(ctx, projectId, distributionId).Execute()
86+
87+
// the distribution is still gettable, e.g. not deleted
88+
if err == nil {
89+
return false, nil, nil
90+
}
91+
var oapiError *oapierror.GenericOpenAPIError
92+
if errors.As(err, &oapiError) {
93+
if statusCode := oapiError.StatusCode; statusCode == http.StatusNotFound || statusCode == http.StatusGone {
94+
return true, nil, nil
95+
}
96+
}
97+
98+
return false, nil, err
99+
})
100+
handler.SetTimeout(10 * time.Minute)
101+
return handler
102+
}
103+
104+
func CreateCDNCustomDomainWaitHandler(ctx context.Context, a cdn.DefaultAPI, projectId, distributionId, domain string) *wait.AsyncActionHandler[cdn.CustomDomain] {
105+
handler := wait.New(func() (waitFinished bool, response *cdn.CustomDomain, err error) {
106+
resp, err := a.GetCustomDomain(ctx, projectId, distributionId, domain).Execute()
107+
if err != nil {
108+
return false, nil, err
109+
}
110+
if resp == nil {
111+
return false, nil, errors.New("CDNDistributionWaitHandler: response is nil")
112+
}
113+
114+
switch resp.CustomDomain.Status {
115+
case cdn.DOMAINSTATUS_ACTIVE:
116+
return true, &resp.CustomDomain, nil
117+
case cdn.DOMAINSTATUS_CREATING, cdn.DOMAINSTATUS_UPDATING:
118+
return false, nil, nil
119+
case cdn.DOMAINSTATUS_DELETING:
120+
return true, nil, fmt.Errorf("creating CDN custom domain failed")
121+
case cdn.DOMAINSTATUS_ERROR:
122+
return true, nil, fmt.Errorf("creating CDN custom domain failed")
123+
default:
124+
return true, nil, fmt.Errorf("CDNCustomDomainWaitHandler: unexpected status %s", resp.CustomDomain.Status)
125+
}
126+
})
127+
handler.SetTimeout(10 * time.Minute)
128+
return handler
129+
}
130+
131+
func DeleteCDNCustomDomainWaitHandler(ctx context.Context, a cdn.DefaultAPI, projectId, distributionId, domain string) *wait.AsyncActionHandler[cdn.CustomDomain] {
132+
handler := wait.New(func() (waitFinished bool, response *cdn.CustomDomain, err error) {
133+
_, err = a.GetCustomDomain(ctx, projectId, distributionId, domain).Execute()
134+
135+
// the custom domain is still gettable, e.g. not deleted
136+
if err == nil {
137+
return false, nil, nil
138+
}
139+
var oapiError *oapierror.GenericOpenAPIError
140+
if errors.As(err, &oapiError) {
141+
if statusCode := oapiError.StatusCode; statusCode == http.StatusNotFound || statusCode == http.StatusGone {
142+
return true, nil, nil
143+
}
144+
}
145+
return false, nil, err
146+
})
147+
handler.SetTimeout(10 * time.Minute)
148+
return handler
149+
}

0 commit comments

Comments
 (0)