Skip to content

Commit 9711742

Browse files
committed
refac(cdn): Migrate to new SDK structure
STACKITCLI-356 Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
1 parent 4cafb60 commit 9711742

13 files changed

Lines changed: 235 additions & 219 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
1919
github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2
2020
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0
21-
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.10.0
21+
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.16.0
2222
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6
2323
github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3
2424
github.com/stackitcloud/stackit-sdk-go/services/git v0.10.3

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,12 @@ github.com/ssgreg/nlreturn/v2 v2.2.1 h1:X4XDI7jstt3ySqGU86YGAURbxw3oTDPK9sPEi6YE
596596
github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRkkxBiELzh2I=
597597
github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10cz4l0KM2L6hqYBH2QA=
598598
github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA=
599-
github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0 h1:V9+885qkSv621rZZatg1YE5ENM1ElALxQDJsh+hDIUg=
600-
github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0/go.mod h1:V6+MolxM/M2FWyWZA+FRFKEzzUe10MU9eEVfMvxHGi8=
601599
github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2 h1:hGzfOJjlCRoFpri5eYIiwhE27qu02pKZLprKvbsTC/w=
602600
github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2/go.mod h1:eK6oRB5Tmpt6KbXQ4UYBGg2LgW5bPtVoncL9E8JSRww=
603601
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0 h1:HxPgBu04j5tj6nfZ2r0l6v4VXC0/tYOGe4sA5Addra8=
604602
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0/go.mod h1:uYI9pHAA2g84jJN25ejFUxa0/JtfpPZqMDkctQ1BzJk=
605-
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.10.0 h1:YALzjYAApyQMKyt4C2LKhPRZHa6brmbFeKuuwl+KOTs=
606-
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.10.0/go.mod h1:915b/lJgDikYFEoRQ8wc8aCtPvUCceYk7gGm9nViJe0=
603+
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.16.0 h1:Wqxx0PDTL2F5gqI5jjznuJY0TdqECltjA0aa/rHY63U=
604+
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.16.0/go.mod h1:MHB1N3EQ9GuAduAQoNS+gb1MjrWJieszbpOso9TQv5s=
607605
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6 h1:GBRb49x5Nax/oQQaaf2F3kKwv8DQQOL0TQOC0C/v/Ew=
608606
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6/go.mod h1:IX9iL3MigDZUmzwswTJMfYvyi118KAHrFMfjJUy5NYk=
609607
github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3 h1:TxChb2qbO82JiQEBYClSSD5HZxqKeKJ6dIvkEUCJmbs=

internal/cmd/beta/cdn/distribution/create/create.go

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/spf13/cobra"
88
sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
9-
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
9+
cdn "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"
1010

1111
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1212
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -264,27 +264,27 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
264264
}
265265

266266
func buildRequest(ctx context.Context, model *inputModel, apiClient *cdn.APIClient) cdn.ApiCreateDistributionRequest {
267-
req := apiClient.CreateDistribution(ctx, model.ProjectId)
268-
var backend cdn.CreateDistributionPayloadGetBackendArgType
267+
req := apiClient.DefaultAPI.CreateDistribution(ctx, model.ProjectId)
268+
var backend cdn.CreateDistributionPayloadBackend
269269
if model.HTTP != nil {
270-
backend = cdn.CreateDistributionPayloadGetBackendArgType{
270+
backend = cdn.CreateDistributionPayloadBackend{
271271
HttpBackendCreate: &cdn.HttpBackendCreate{
272272
Geofencing: model.HTTP.Geofencing,
273273
OriginRequestHeaders: model.HTTP.OriginRequestHeaders,
274-
OriginUrl: &model.HTTP.OriginURL,
275-
Type: utils.Ptr("http"),
274+
OriginUrl: model.HTTP.OriginURL,
275+
Type: "http",
276276
},
277277
}
278278
} else {
279-
backend = cdn.CreateDistributionPayloadGetBackendArgType{
279+
backend = cdn.CreateDistributionPayloadBackend{
280280
BucketBackendCreate: &cdn.BucketBackendCreate{
281-
BucketUrl: &model.Bucket.URL,
282-
Credentials: cdn.NewBucketCredentials(
281+
BucketUrl: model.Bucket.URL,
282+
Credentials: *cdn.NewBucketCredentials(
283283
model.Bucket.AccessKeyID,
284284
model.Bucket.Password,
285285
),
286-
Region: &model.Bucket.Region,
287-
Type: utils.Ptr("bucket"),
286+
Region: model.Bucket.Region,
287+
Type: "bucket",
288288
},
289289
}
290290
}
@@ -294,30 +294,28 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *cdn.APIClie
294294
model.Regions,
295295
)
296296
if len(model.BlockedCountries) > 0 {
297-
payload.BlockedCountries = &model.BlockedCountries
297+
payload.BlockedCountries = model.BlockedCountries
298298
}
299299
if len(model.BlockedIPs) > 0 {
300-
payload.BlockedIps = &model.BlockedIPs
300+
payload.BlockedIps = model.BlockedIPs
301301
}
302302
if model.DefaultCacheDuration != "" {
303303
payload.DefaultCacheDuration = utils.Ptr(model.DefaultCacheDuration)
304304
}
305305
if model.Loki != nil {
306-
payload.LogSink = &cdn.CreateDistributionPayloadGetLogSinkArgType{
307-
LokiLogSinkCreate: &cdn.LokiLogSinkCreate{
308-
Credentials: &cdn.LokiLogSinkCredentials{
309-
Password: &model.Loki.Password,
310-
Username: &model.Loki.Username,
311-
},
312-
PushUrl: &model.Loki.PushURL,
313-
Type: utils.Ptr("loki"),
306+
payload.LogSink = &cdn.LokiLogSinkCreate{
307+
Credentials: cdn.LokiLogSinkCredentials{
308+
Password: model.Loki.Password,
309+
Username: model.Loki.Username,
314310
},
311+
PushUrl: model.Loki.PushURL,
312+
Type: "loki",
315313
}
316314
}
317315
payload.MonthlyLimitBytes = model.MonthlyLimitBytes
318316
if model.Optimizer {
319-
payload.Optimizer = &cdn.CreateDistributionPayloadGetOptimizerArgType{
320-
Enabled: utils.Ptr(true),
317+
payload.Optimizer = &cdn.Optimizer{
318+
Enabled: true,
321319
}
322320
}
323321
return req.CreateDistributionPayload(*payload)
@@ -328,7 +326,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, resp *cdn
328326
return fmt.Errorf("create distribution response is nil")
329327
}
330328
return p.OutputResult(outputFormat, resp, func() error {
331-
p.Outputf("Created CDN distribution for %q. ID: %s\n", projectLabel, utils.PtrString(resp.Distribution.Id))
329+
p.Outputf("Created CDN distribution for %q. ID: %s\n", projectLabel, resp.Distribution.Id)
332330
return nil
333331
})
334332
}

internal/cmd/beta/cdn/distribution/create/create_test.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/google/go-cmp/cmp/cmpopts"
1111
"github.com/google/uuid"
1212
sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
13-
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
13+
cdn "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"
1414
"k8s.io/utils/ptr"
1515

1616
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
@@ -23,7 +23,7 @@ import (
2323
type testCtxKey struct{}
2424

2525
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
26-
var testClient = &cdn.APIClient{}
26+
var testClient = &cdn.APIClient{DefaultAPI: &cdn.DefaultAPIService{}}
2727
var testProjectId = uuid.NewString()
2828

2929
const testRegions = cdn.REGION_EU
@@ -129,10 +129,10 @@ func modelLoki() func(model *inputModel) {
129129

130130
func fixturePayload(mods ...func(payload *cdn.CreateDistributionPayload)) cdn.CreateDistributionPayload {
131131
payload := *cdn.NewCreateDistributionPayload(
132-
cdn.CreateDistributionPayloadGetBackendArgType{
132+
cdn.CreateDistributionPayloadBackend{
133133
HttpBackendCreate: &cdn.HttpBackendCreate{
134-
Type: utils.Ptr("http"),
135-
OriginUrl: utils.Ptr("https://http-backend.example.com"),
134+
Type: "http",
135+
OriginUrl: "https://http-backend.example.com",
136136
},
137137
},
138138
[]cdn.Region{testRegions},
@@ -145,18 +145,18 @@ func fixturePayload(mods ...func(payload *cdn.CreateDistributionPayload)) cdn.Cr
145145

146146
func payloadRegions(regions ...cdn.Region) func(payload *cdn.CreateDistributionPayload) {
147147
return func(payload *cdn.CreateDistributionPayload) {
148-
payload.Regions = &regions
148+
payload.Regions = regions
149149
}
150150
}
151151

152152
func payloadBucketBackend() func(payload *cdn.CreateDistributionPayload) {
153153
return func(payload *cdn.CreateDistributionPayload) {
154-
payload.Backend = &cdn.CreateDistributionPayloadGetBackendArgType{
154+
payload.Backend = cdn.CreateDistributionPayloadBackend{
155155
BucketBackendCreate: &cdn.BucketBackendCreate{
156-
Type: utils.Ptr("bucket"),
157-
BucketUrl: utils.Ptr("https://bucket-backend.example.com"),
158-
Region: utils.Ptr("eu"),
159-
Credentials: cdn.NewBucketCredentials(
156+
Type: "bucket",
157+
BucketUrl: "https://bucket-backend.example.com",
158+
Region: "eu",
159+
Credentials: *cdn.NewBucketCredentials(
160160
"access-key-id",
161161
"",
162162
),
@@ -167,18 +167,16 @@ func payloadBucketBackend() func(payload *cdn.CreateDistributionPayload) {
167167

168168
func payloadLoki() func(payload *cdn.CreateDistributionPayload) {
169169
return func(payload *cdn.CreateDistributionPayload) {
170-
payload.LogSink = &cdn.CreateDistributionPayloadGetLogSinkArgType{
171-
LokiLogSinkCreate: &cdn.LokiLogSinkCreate{
172-
Type: utils.Ptr("loki"),
173-
PushUrl: utils.Ptr("https://loki.example.com"),
174-
Credentials: cdn.NewLokiLogSinkCredentials("", "loki-user"),
175-
},
170+
payload.LogSink = &cdn.LokiLogSinkCreate{
171+
Type: "loki",
172+
PushUrl: "https://loki.example.com",
173+
Credentials: *cdn.NewLokiLogSinkCredentials("", "loki-user"),
176174
}
177175
}
178176
}
179177

180178
func fixtureRequest(mods ...func(payload *cdn.CreateDistributionPayload)) cdn.ApiCreateDistributionRequest {
181-
req := testClient.CreateDistribution(testCtx, testProjectId)
179+
req := testClient.DefaultAPI.CreateDistribution(testCtx, testProjectId)
182180
req = req.CreateDistributionPayload(fixturePayload(mods...))
183181
return req
184182
}
@@ -466,11 +464,11 @@ func TestBuildRequest(t *testing.T) {
466464
expected: fixtureRequest(
467465
func(payload *cdn.CreateDistributionPayload) {
468466
payload.MonthlyLimitBytes = utils.Ptr[int64](5368709120)
469-
payload.Optimizer = &cdn.CreateDistributionPayloadGetOptimizerArgType{
470-
Enabled: utils.Ptr(true),
467+
payload.Optimizer = &cdn.Optimizer{
468+
Enabled: true,
471469
}
472-
payload.BlockedCountries = &[]string{"DE", "AT"}
473-
payload.BlockedIps = &[]string{"127.0.0.1"}
470+
payload.BlockedCountries = []string{"DE", "AT"}
471+
payload.BlockedIps = []string{"127.0.0.1"}
474472
payload.DefaultCacheDuration = utils.Ptr("PT2H")
475473
},
476474
),
@@ -488,7 +486,7 @@ func TestBuildRequest(t *testing.T) {
488486
request := buildRequest(testCtx, tt.model, testClient)
489487

490488
diff := cmp.Diff(request, tt.expected,
491-
cmp.AllowUnexported(tt.expected),
489+
cmp.AllowUnexported(tt.expected, cdn.DefaultAPIService{}),
492490
cmpopts.EquateComparable(testCtx),
493491
)
494492
if diff != "" {
@@ -516,8 +514,8 @@ func TestOutputResult(t *testing.T) {
516514
description: "table output",
517515
outputFormat: "table",
518516
response: &cdn.CreateDistributionResponse{
519-
Distribution: &cdn.Distribution{
520-
Id: ptr.To("dist-1234"),
517+
Distribution: cdn.Distribution{
518+
Id: "dist-1234",
521519
},
522520
},
523521
expected: fmt.Sprintf("Created CDN distribution for %q. ID: dist-1234\n", testProjectId),

internal/cmd/beta/cdn/distribution/delete/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66

77
"github.com/spf13/cobra"
8-
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
8+
cdn "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"
99

1010
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
@@ -89,5 +89,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
8989
}
9090

9191
func buildRequest(ctx context.Context, model *inputModel, apiClient *cdn.APIClient) cdn.ApiDeleteDistributionRequest {
92-
return apiClient.DeleteDistribution(ctx, model.ProjectId, model.DistributionID)
92+
return apiClient.DefaultAPI.DeleteDistribution(ctx, model.ProjectId, model.DistributionID)
9393
}

internal/cmd/beta/cdn/distribution/delete/delete_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/google/go-cmp/cmp"
88
"github.com/google/go-cmp/cmp/cmpopts"
99
"github.com/google/uuid"
10-
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
10+
cdn "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
@@ -18,7 +18,7 @@ type testCtxKey struct{}
1818
var (
1919
testCtx = context.WithValue(context.Background(), testCtxKey{}, "test")
2020
testProjectId = uuid.NewString()
21-
testClient = &cdn.APIClient{}
21+
testClient = &cdn.APIClient{DefaultAPI: &cdn.DefaultAPIService{}}
2222
testDistributionID = uuid.NewString()
2323
)
2424

@@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5757
}
5858

5959
func fixtureRequest(mods ...func(request *cdn.ApiDeleteDistributionRequest)) cdn.ApiDeleteDistributionRequest {
60-
request := testClient.DeleteDistribution(testCtx, testProjectId, testDistributionID)
60+
request := testClient.DefaultAPI.DeleteDistribution(testCtx, testProjectId, testDistributionID)
6161
for _, mod := range mods {
6262
mod(&request)
6363
}
@@ -120,7 +120,7 @@ func TestBuildRequest(t *testing.T) {
120120
request := buildRequest(testCtx, tt.model, testClient)
121121

122122
diff := cmp.Diff(request, tt.expectedResult,
123-
cmp.AllowUnexported(tt.expectedResult),
123+
cmp.AllowUnexported(tt.expectedResult, cdn.DefaultAPIService{}),
124124
cmpopts.EquateComparable(testCtx),
125125
)
126126
if diff != "" {

0 commit comments

Comments
 (0)