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: 1 addition & 1 deletion docs/stackit_beta_cdn_distribution_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ stackit beta cdn distribution create [flags]
--loki-username string Username for log sink
--monthly-limit-bytes int Monthly limit in bytes for the CDN distribution
--optimizer Enable optimizer for the CDN distribution (paid feature).
--regions strings Regions in which content should be cached, multiple of: ["EU" "US" "AF" "SA" "ASIA"] (default [])
--regions strings Regions in which content should be cached, multiple of: ["EU" "US" "AF" "SA" "ASIA" "unknown_default_open_api"] (default [])
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion docs/stackit_beta_cdn_distribution_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ stackit beta cdn distribution update [flags]
--loki-username string Username for log sink
--monthly-limit-bytes int Monthly limit in bytes for the CDN distribution
--optimizer Enable optimizer for the CDN distribution (paid feature).
--regions strings Regions in which content should be cached, multiple of: ["EU" "US" "AF" "SA" "ASIA"] (default [])
--regions strings Regions in which content should be cached, multiple of: ["EU" "US" "AF" "SA" "ASIA" "unknown_default_open_api"] (default [])
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.10.0
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.16.0
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6
github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3
github.com/stackitcloud/stackit-sdk-go/services/git v0.10.3
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,12 @@ github.com/ssgreg/nlreturn/v2 v2.2.1 h1:X4XDI7jstt3ySqGU86YGAURbxw3oTDPK9sPEi6YE
github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRkkxBiELzh2I=
github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10cz4l0KM2L6hqYBH2QA=
github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA=
github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0 h1:V9+885qkSv621rZZatg1YE5ENM1ElALxQDJsh+hDIUg=
github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0/go.mod h1:V6+MolxM/M2FWyWZA+FRFKEzzUe10MU9eEVfMvxHGi8=
github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2 h1:hGzfOJjlCRoFpri5eYIiwhE27qu02pKZLprKvbsTC/w=
github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2/go.mod h1:eK6oRB5Tmpt6KbXQ4UYBGg2LgW5bPtVoncL9E8JSRww=
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0 h1:HxPgBu04j5tj6nfZ2r0l6v4VXC0/tYOGe4sA5Addra8=
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0/go.mod h1:uYI9pHAA2g84jJN25ejFUxa0/JtfpPZqMDkctQ1BzJk=
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.10.0 h1:YALzjYAApyQMKyt4C2LKhPRZHa6brmbFeKuuwl+KOTs=
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.10.0/go.mod h1:915b/lJgDikYFEoRQ8wc8aCtPvUCceYk7gGm9nViJe0=
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.16.0 h1:Wqxx0PDTL2F5gqI5jjznuJY0TdqECltjA0aa/rHY63U=
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.16.0/go.mod h1:MHB1N3EQ9GuAduAQoNS+gb1MjrWJieszbpOso9TQv5s=
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6 h1:GBRb49x5Nax/oQQaaf2F3kKwv8DQQOL0TQOC0C/v/Ew=
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6/go.mod h1:IX9iL3MigDZUmzwswTJMfYvyi118KAHrFMfjJUy5NYk=
github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3 h1:TxChb2qbO82JiQEBYClSSD5HZxqKeKJ6dIvkEUCJmbs=
Expand Down
46 changes: 22 additions & 24 deletions internal/cmd/beta/cdn/distribution/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/spf13/cobra"
sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
cdn "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"

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

func buildRequest(ctx context.Context, model *inputModel, apiClient *cdn.APIClient) cdn.ApiCreateDistributionRequest {
req := apiClient.CreateDistribution(ctx, model.ProjectId)
var backend cdn.CreateDistributionPayloadGetBackendArgType
req := apiClient.DefaultAPI.CreateDistribution(ctx, model.ProjectId)
var backend cdn.CreateDistributionPayloadBackend
if model.HTTP != nil {
backend = cdn.CreateDistributionPayloadGetBackendArgType{
backend = cdn.CreateDistributionPayloadBackend{
HttpBackendCreate: &cdn.HttpBackendCreate{
Geofencing: model.HTTP.Geofencing,
OriginRequestHeaders: model.HTTP.OriginRequestHeaders,
OriginUrl: &model.HTTP.OriginURL,
Type: utils.Ptr("http"),
OriginUrl: model.HTTP.OriginURL,
Type: "http",
},
}
} else {
backend = cdn.CreateDistributionPayloadGetBackendArgType{
backend = cdn.CreateDistributionPayloadBackend{
BucketBackendCreate: &cdn.BucketBackendCreate{
BucketUrl: &model.Bucket.URL,
Credentials: cdn.NewBucketCredentials(
BucketUrl: model.Bucket.URL,
Credentials: *cdn.NewBucketCredentials(
model.Bucket.AccessKeyID,
model.Bucket.Password,
),
Region: &model.Bucket.Region,
Type: utils.Ptr("bucket"),
Region: model.Bucket.Region,
Type: "bucket",
},
}
}
Expand All @@ -294,30 +294,28 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *cdn.APIClie
model.Regions,
)
if len(model.BlockedCountries) > 0 {
payload.BlockedCountries = &model.BlockedCountries
payload.BlockedCountries = model.BlockedCountries
}
if len(model.BlockedIPs) > 0 {
payload.BlockedIps = &model.BlockedIPs
payload.BlockedIps = model.BlockedIPs
}
if model.DefaultCacheDuration != "" {
payload.DefaultCacheDuration = utils.Ptr(model.DefaultCacheDuration)
}
if model.Loki != nil {
payload.LogSink = &cdn.CreateDistributionPayloadGetLogSinkArgType{
LokiLogSinkCreate: &cdn.LokiLogSinkCreate{
Credentials: &cdn.LokiLogSinkCredentials{
Password: &model.Loki.Password,
Username: &model.Loki.Username,
},
PushUrl: &model.Loki.PushURL,
Type: utils.Ptr("loki"),
payload.LogSink = &cdn.LokiLogSinkCreate{
Credentials: cdn.LokiLogSinkCredentials{
Password: model.Loki.Password,
Username: model.Loki.Username,
},
PushUrl: model.Loki.PushURL,
Type: "loki",
}
}
payload.MonthlyLimitBytes = model.MonthlyLimitBytes
if model.Optimizer {
payload.Optimizer = &cdn.CreateDistributionPayloadGetOptimizerArgType{
Enabled: utils.Ptr(true),
payload.Optimizer = &cdn.Optimizer{
Enabled: true,
}
}
return req.CreateDistributionPayload(*payload)
Expand All @@ -328,7 +326,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, resp *cdn
return fmt.Errorf("create distribution response is nil")
}
return p.OutputResult(outputFormat, resp, func() error {
p.Outputf("Created CDN distribution for %q. ID: %s\n", projectLabel, utils.PtrString(resp.Distribution.Id))
p.Outputf("Created CDN distribution for %q. ID: %s\n", projectLabel, resp.Distribution.Id)
return nil
})
}
48 changes: 23 additions & 25 deletions internal/cmd/beta/cdn/distribution/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
cdn "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"
"k8s.io/utils/ptr"

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

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

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

func fixturePayload(mods ...func(payload *cdn.CreateDistributionPayload)) cdn.CreateDistributionPayload {
payload := *cdn.NewCreateDistributionPayload(
cdn.CreateDistributionPayloadGetBackendArgType{
cdn.CreateDistributionPayloadBackend{
HttpBackendCreate: &cdn.HttpBackendCreate{
Type: utils.Ptr("http"),
OriginUrl: utils.Ptr("https://http-backend.example.com"),
Type: "http",
OriginUrl: "https://http-backend.example.com",
},
},
[]cdn.Region{testRegions},
Expand All @@ -145,18 +145,18 @@ func fixturePayload(mods ...func(payload *cdn.CreateDistributionPayload)) cdn.Cr

func payloadRegions(regions ...cdn.Region) func(payload *cdn.CreateDistributionPayload) {
return func(payload *cdn.CreateDistributionPayload) {
payload.Regions = &regions
payload.Regions = regions
}
}

func payloadBucketBackend() func(payload *cdn.CreateDistributionPayload) {
return func(payload *cdn.CreateDistributionPayload) {
payload.Backend = &cdn.CreateDistributionPayloadGetBackendArgType{
payload.Backend = cdn.CreateDistributionPayloadBackend{
BucketBackendCreate: &cdn.BucketBackendCreate{
Type: utils.Ptr("bucket"),
BucketUrl: utils.Ptr("https://bucket-backend.example.com"),
Region: utils.Ptr("eu"),
Credentials: cdn.NewBucketCredentials(
Type: "bucket",
BucketUrl: "https://bucket-backend.example.com",
Region: "eu",
Credentials: *cdn.NewBucketCredentials(
"access-key-id",
"",
),
Expand All @@ -167,18 +167,16 @@ func payloadBucketBackend() func(payload *cdn.CreateDistributionPayload) {

func payloadLoki() func(payload *cdn.CreateDistributionPayload) {
return func(payload *cdn.CreateDistributionPayload) {
payload.LogSink = &cdn.CreateDistributionPayloadGetLogSinkArgType{
LokiLogSinkCreate: &cdn.LokiLogSinkCreate{
Type: utils.Ptr("loki"),
PushUrl: utils.Ptr("https://loki.example.com"),
Credentials: cdn.NewLokiLogSinkCredentials("", "loki-user"),
},
payload.LogSink = &cdn.LokiLogSinkCreate{
Type: "loki",
PushUrl: "https://loki.example.com",
Credentials: *cdn.NewLokiLogSinkCredentials("", "loki-user"),
}
}
}

func fixtureRequest(mods ...func(payload *cdn.CreateDistributionPayload)) cdn.ApiCreateDistributionRequest {
req := testClient.CreateDistribution(testCtx, testProjectId)
req := testClient.DefaultAPI.CreateDistribution(testCtx, testProjectId)
req = req.CreateDistributionPayload(fixturePayload(mods...))
return req
}
Expand Down Expand Up @@ -466,11 +464,11 @@ func TestBuildRequest(t *testing.T) {
expected: fixtureRequest(
func(payload *cdn.CreateDistributionPayload) {
payload.MonthlyLimitBytes = utils.Ptr[int64](5368709120)
payload.Optimizer = &cdn.CreateDistributionPayloadGetOptimizerArgType{
Enabled: utils.Ptr(true),
payload.Optimizer = &cdn.Optimizer{
Enabled: true,
}
payload.BlockedCountries = &[]string{"DE", "AT"}
payload.BlockedIps = &[]string{"127.0.0.1"}
payload.BlockedCountries = []string{"DE", "AT"}
payload.BlockedIps = []string{"127.0.0.1"}
payload.DefaultCacheDuration = utils.Ptr("PT2H")
},
),
Expand All @@ -488,7 +486,7 @@ func TestBuildRequest(t *testing.T) {
request := buildRequest(testCtx, tt.model, testClient)

diff := cmp.Diff(request, tt.expected,
cmp.AllowUnexported(tt.expected),
cmp.AllowUnexported(tt.expected, cdn.DefaultAPIService{}),
cmpopts.EquateComparable(testCtx),
)
if diff != "" {
Expand Down Expand Up @@ -516,8 +514,8 @@ func TestOutputResult(t *testing.T) {
description: "table output",
outputFormat: "table",
response: &cdn.CreateDistributionResponse{
Distribution: &cdn.Distribution{
Id: ptr.To("dist-1234"),
Distribution: cdn.Distribution{
Id: "dist-1234",
},
},
expected: fmt.Sprintf("Created CDN distribution for %q. ID: dist-1234\n", testProjectId),
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/beta/cdn/distribution/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
cdn "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"

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

func buildRequest(ctx context.Context, model *inputModel, apiClient *cdn.APIClient) cdn.ApiDeleteDistributionRequest {
return apiClient.DeleteDistribution(ctx, model.ProjectId, model.DistributionID)
return apiClient.DefaultAPI.DeleteDistribution(ctx, model.ProjectId, model.DistributionID)
}
8 changes: 4 additions & 4 deletions internal/cmd/beta/cdn/distribution/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
cdn "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
Expand All @@ -18,7 +18,7 @@ type testCtxKey struct{}
var (
testCtx = context.WithValue(context.Background(), testCtxKey{}, "test")
testProjectId = uuid.NewString()
testClient = &cdn.APIClient{}
testClient = &cdn.APIClient{DefaultAPI: &cdn.DefaultAPIService{}}
testDistributionID = uuid.NewString()
)

Expand Down Expand Up @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *cdn.ApiDeleteDistributionRequest)) cdn.ApiDeleteDistributionRequest {
request := testClient.DeleteDistribution(testCtx, testProjectId, testDistributionID)
request := testClient.DefaultAPI.DeleteDistribution(testCtx, testProjectId, testDistributionID)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestBuildRequest(t *testing.T) {
request := buildRequest(testCtx, tt.model, testClient)

diff := cmp.Diff(request, tt.expectedResult,
cmp.AllowUnexported(tt.expectedResult),
cmp.AllowUnexported(tt.expectedResult, cdn.DefaultAPIService{}),
cmpopts.EquateComparable(testCtx),
)
if diff != "" {
Expand Down
Loading
Loading