Skip to content

Commit c8e094f

Browse files
authored
chore(alb): migrate to new SDK structure (#1415)
* chore(alb): migrate to new SDK structure relates to STACKITCLI-355 * chore(alb): fix alb creation template relates to STACKITCLI-355 * chore(alb): styling update relates to STACKITCLI-355 * chore(alb): fix example relates to STACKITCLI-355
1 parent 5f4346a commit c8e094f

32 files changed

Lines changed: 125 additions & 122 deletions

docs/stackit_beta_alb_pool_update.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ stackit beta alb pool update [flags]
1414

1515
```
1616
Update an application target pool from a configuration file (the name of the pool is read from the file)
17-
$ stackit beta alb update --configuration my-target-pool.json --name my-load-balancer
17+
$ stackit beta alb pool update --configuration my-target-pool.json --name my-load-balancer
1818
```
1919

2020
### Options
2121

2222
```
2323
-c, --configuration string Filename of the input configuration file
2424
-h, --help Help for "stackit beta alb pool update"
25-
-n, --name string Name of the target pool name to update
25+
-n, --name string Name of the application load balancer
2626
```
2727

2828
### Options inherited from parent commands

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/spf13/pflag v1.0.10
1717
github.com/spf13/viper v1.21.0
1818
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
19-
github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0
19+
github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2
2020
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0
2121
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.10.0
2222
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10
598598
github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA=
599599
github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0 h1:V9+885qkSv621rZZatg1YE5ENM1ElALxQDJsh+hDIUg=
600600
github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0/go.mod h1:V6+MolxM/M2FWyWZA+FRFKEzzUe10MU9eEVfMvxHGi8=
601+
github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2 h1:hGzfOJjlCRoFpri5eYIiwhE27qu02pKZLprKvbsTC/w=
602+
github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2/go.mod h1:eK6oRB5Tmpt6KbXQ4UYBGg2LgW5bPtVoncL9E8JSRww=
601603
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0 h1:HxPgBu04j5tj6nfZ2r0l6v4VXC0/tYOGe4sA5Addra8=
602604
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0/go.mod h1:uYI9pHAA2g84jJN25ejFUxa0/JtfpPZqMDkctQ1BzJk=
603605
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.10.0 h1:YALzjYAApyQMKyt4C2LKhPRZHa6brmbFeKuuwl+KOTs=

internal/cmd/beta/alb/create/create.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
2525

2626
"github.com/spf13/cobra"
27-
"github.com/stackitcloud/stackit-sdk-go/services/alb"
28-
"github.com/stackitcloud/stackit-sdk-go/services/alb/wait"
27+
alb "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api"
28+
"github.com/stackitcloud/stackit-sdk-go/services/alb/v2api/wait"
2929
)
3030

3131
const (
@@ -86,7 +86,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8686
// Wait for async operation, if async mode not enabled
8787
if !model.Async {
8888
err := spinner.Run(params.Printer, "Creating loadbalancer", func() error {
89-
_, err := wait.CreateOrUpdateLoadbalancerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, *resp.Name).WaitWithContext(ctx)
89+
_, err := wait.CreateOrUpdateLoadbalancerWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, *resp.Name).WaitWithContext(ctx)
9090
return err
9191
})
9292
if err != nil {
@@ -123,7 +123,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
123123
}
124124

125125
func buildRequest(ctx context.Context, model *inputModel, apiClient *alb.APIClient) (req alb.ApiCreateLoadBalancerRequest, err error) {
126-
req = apiClient.CreateLoadBalancer(ctx, model.ProjectId, model.Region)
126+
req = apiClient.DefaultAPI.CreateLoadBalancer(ctx, model.ProjectId, model.Region)
127127
payload, err := readPayload(ctx, model)
128128
if err != nil {
129129
return req, err

internal/cmd/beta/alb/create/create_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/google/go-cmp/cmp"
1111
"github.com/google/go-cmp/cmp/cmpopts"
1212
"github.com/google/uuid"
13-
"github.com/stackitcloud/stackit-sdk-go/services/alb"
13+
alb "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api"
1414

1515
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
1616

@@ -27,7 +27,7 @@ var projectIdFlag = globalflags.ProjectIdFlag
2727
type testCtxKey struct{}
2828

2929
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
30-
var testClient = &alb.APIClient{}
30+
var testClient = &alb.APIClient{DefaultAPI: &alb.DefaultAPIService{}}
3131
var testProjectId = uuid.NewString()
3232
var testRegion = "eu01"
3333
var testConfig = "testdata/testconfig.json"
@@ -69,7 +69,7 @@ func fixturePayload(mods ...func(payload *alb.CreateLoadBalancerPayload)) (paylo
6969
}
7070

7171
func fixtureRequest(mods ...func(request *alb.ApiCreateLoadBalancerRequest)) alb.ApiCreateLoadBalancerRequest {
72-
request := testClient.CreateLoadBalancer(testCtx, testProjectId, testRegion)
72+
request := testClient.DefaultAPI.CreateLoadBalancer(testCtx, testProjectId, testRegion)
7373

7474
request = request.CreateLoadBalancerPayload(fixturePayload())
7575
for _, mod := range mods {
@@ -163,7 +163,7 @@ func TestBuildRequest(t *testing.T) {
163163
},
164164
Configuration: &testConfig,
165165
},
166-
expectedRequest: testClient.
166+
expectedRequest: testClient.DefaultAPI.
167167
CreateLoadBalancer(testCtx, testProjectId, testRegion).
168168
CreateLoadBalancerPayload(fixturePayload()),
169169
},
@@ -177,7 +177,7 @@ func TestBuildRequest(t *testing.T) {
177177
}
178178

179179
diff := cmp.Diff(request, tt.expectedRequest,
180-
cmp.AllowUnexported(tt.expectedRequest),
180+
cmp.AllowUnexported(tt.expectedRequest, alb.DefaultAPIService{}),
181181
cmpopts.EquateComparable(testCtx),
182182
)
183183
if diff != "" {

internal/cmd/beta/alb/delete/delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/services/alb/client"
1515

1616
"github.com/spf13/cobra"
17-
"github.com/stackitcloud/stackit-sdk-go/services/alb"
17+
alb "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api"
1818
)
1919

2020
const (
@@ -70,7 +70,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7070
return fmt.Errorf("delete loadbalancer: %w", err)
7171
}
7272

73-
params.Printer.Outputf("Load balancer %q deleted.", model.Name)
73+
params.Printer.Outputf("Load balancer %q deleted.\n", model.Name)
7474
return nil
7575
},
7676
}
@@ -91,5 +91,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
9191
}
9292

9393
func buildRequest(ctx context.Context, model *inputModel, apiClient *alb.APIClient) alb.ApiDeleteLoadBalancerRequest {
94-
return apiClient.DeleteLoadBalancer(ctx, model.ProjectId, model.Region, model.Name)
94+
return apiClient.DefaultAPI.DeleteLoadBalancer(ctx, model.ProjectId, model.Region, model.Name)
9595
}

internal/cmd/beta/alb/delete/delete_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/google/go-cmp/cmp"
1111
"github.com/google/go-cmp/cmp/cmpopts"
1212
"github.com/google/uuid"
13-
"github.com/stackitcloud/stackit-sdk-go/services/alb"
13+
alb "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api"
1414
)
1515

1616
type testCtxKey struct{}
@@ -19,7 +19,7 @@ var (
1919
testCtx = context.WithValue(context.Background(), testCtxKey{}, "test")
2020
testProjectId = uuid.NewString()
2121
testRegion = "eu01"
22-
testClient = &alb.APIClient{}
22+
testClient = &alb.APIClient{DefaultAPI: &alb.DefaultAPIService{}}
2323
testLoadBalancerName = "my-test-loadbalancer"
2424
)
2525

@@ -60,7 +60,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6060
}
6161

6262
func fixtureRequest(mods ...func(request *alb.ApiDeleteLoadBalancerRequest)) alb.ApiDeleteLoadBalancerRequest {
63-
request := testClient.DeleteLoadBalancer(testCtx, testProjectId, testRegion, testLoadBalancerName)
63+
request := testClient.DefaultAPI.DeleteLoadBalancer(testCtx, testProjectId, testRegion, testLoadBalancerName)
6464
for _, mod := range mods {
6565
mod(&request)
6666
}
@@ -134,7 +134,7 @@ func TestBuildRequest(t *testing.T) {
134134
request := buildRequest(testCtx, tt.model, testClient)
135135

136136
diff := cmp.Diff(request, tt.expectedResult,
137-
cmp.AllowUnexported(tt.expectedResult),
137+
cmp.AllowUnexported(tt.expectedResult, alb.DefaultAPIService{}),
138138
cmpopts.EquateComparable(testCtx),
139139
)
140140
if diff != "" {

internal/cmd/beta/alb/describe/describe.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
1818

1919
"github.com/spf13/cobra"
20-
"github.com/stackitcloud/stackit-sdk-go/services/alb"
20+
alb "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api"
2121
)
2222

2323
const (
@@ -85,7 +85,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
8585
}
8686

8787
func buildRequest(ctx context.Context, model *inputModel, apiClient *alb.APIClient) alb.ApiGetLoadBalancerRequest {
88-
return apiClient.GetLoadBalancer(ctx, model.ProjectId, model.Region, model.Name)
88+
return apiClient.DefaultAPI.GetLoadBalancer(ctx, model.ProjectId, model.Region, model.Name)
8989
}
9090

9191
func outputResult(p *print.Printer, outputFormat string, loadbalancer *alb.LoadBalancer) error {
@@ -95,11 +95,11 @@ func outputResult(p *print.Printer, outputFormat string, loadbalancer *alb.LoadB
9595
content = append(content, buildLoadBalancerTable(loadbalancer))
9696

9797
if loadbalancer.Listeners != nil {
98-
content = append(content, buildListenersTable(*loadbalancer.Listeners))
98+
content = append(content, buildListenersTable(loadbalancer.Listeners))
9999
}
100100

101101
if loadbalancer.TargetPools != nil {
102-
content = append(content, buildTargetPoolsTable(*loadbalancer.TargetPools))
102+
content = append(content, buildTargetPoolsTable(loadbalancer.TargetPools))
103103
}
104104

105105
err := tables.DisplayTables(p, content)
@@ -116,7 +116,7 @@ func buildLoadBalancerTable(loadbalancer *alb.LoadBalancer) tables.Table {
116116
privateAccessOnly := false
117117
if loadbalancer.Options != nil {
118118
if loadbalancer.Options.AccessControl != nil && loadbalancer.Options.AccessControl.AllowedSourceRanges != nil {
119-
acl = *loadbalancer.Options.AccessControl.AllowedSourceRanges
119+
acl = loadbalancer.Options.AccessControl.AllowedSourceRanges
120120
}
121121

122122
if loadbalancer.Options.PrivateNetworkOnly != nil {
@@ -125,16 +125,16 @@ func buildLoadBalancerTable(loadbalancer *alb.LoadBalancer) tables.Table {
125125
}
126126

127127
networkId := "-"
128-
if loadbalancer.Networks != nil && len(*loadbalancer.Networks) > 0 {
129-
networks := *loadbalancer.Networks
128+
if len(loadbalancer.Networks) > 0 {
129+
networks := loadbalancer.Networks
130130
networkId = *networks[0].NetworkId
131131
}
132132

133133
externalAddress := utils.PtrStringDefault(loadbalancer.ExternalAddress, "-")
134134

135135
errorDescriptions := []string{}
136-
if loadbalancer.Errors != nil && len((*loadbalancer.Errors)) > 0 {
137-
for _, err := range *loadbalancer.Errors {
136+
if len(loadbalancer.Errors) > 0 {
137+
for _, err := range loadbalancer.Errors {
138138
errorDescriptions = append(errorDescriptions, *err.Description)
139139
}
140140
}
@@ -179,7 +179,7 @@ func buildTargetPoolsTable(targetPools []alb.TargetPool) tables.Table {
179179
table.SetTitle("Target Pools")
180180
table.SetHeader("NAME", "PORT", "TARGETS")
181181
for _, targetPool := range targetPools {
182-
table.AddRow(utils.PtrString(targetPool.Name), utils.PtrString(targetPool.TargetPort), len(*targetPool.Targets))
182+
table.AddRow(utils.PtrString(targetPool.Name), utils.PtrString(targetPool.TargetPort), len(targetPool.Targets))
183183
}
184184
return table
185185
}

internal/cmd/beta/alb/describe/describe_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/google/go-cmp/cmp"
1212
"github.com/google/go-cmp/cmp/cmpopts"
1313
"github.com/google/uuid"
14-
"github.com/stackitcloud/stackit-sdk-go/services/alb"
14+
alb "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api"
1515
)
1616

1717
type testCtxKey struct{}
@@ -20,7 +20,7 @@ var (
2020
testCtx = context.WithValue(context.Background(), testCtxKey{}, "test")
2121
testProjectId = uuid.NewString()
2222
testRegion = "eu01"
23-
testClient = &alb.APIClient{}
23+
testClient = &alb.APIClient{DefaultAPI: &alb.DefaultAPIService{}}
2424
testLoadBalancerName = "my-test-loadbalancer"
2525
)
2626

@@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6161
}
6262

6363
func fixtureRequest(mods ...func(request *alb.ApiGetLoadBalancerRequest)) alb.ApiGetLoadBalancerRequest {
64-
request := testClient.GetLoadBalancer(testCtx, testProjectId, testRegion, testLoadBalancerName)
64+
request := testClient.DefaultAPI.GetLoadBalancer(testCtx, testProjectId, testRegion, testLoadBalancerName)
6565
for _, mod := range mods {
6666
mod(&request)
6767
}
@@ -135,7 +135,7 @@ func TestBuildRequest(t *testing.T) {
135135
request := buildRequest(testCtx, tt.model, testClient)
136136

137137
diff := cmp.Diff(request, tt.expectedResult,
138-
cmp.AllowUnexported(tt.expectedResult),
138+
cmp.AllowUnexported(tt.expectedResult, alb.DefaultAPIService{}),
139139
cmpopts.EquateComparable(testCtx),
140140
)
141141
if diff != "" {

internal/cmd/beta/alb/list/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
88

99
"github.com/spf13/cobra"
10-
"github.com/stackitcloud/stackit-sdk-go/services/alb"
10+
alb "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -117,7 +117,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
117117
}
118118

119119
func buildRequest(ctx context.Context, model *inputModel, apiClient *alb.APIClient) alb.ApiListLoadBalancersRequest {
120-
request := apiClient.ListLoadBalancers(ctx, model.ProjectId, model.Region)
120+
request := apiClient.DefaultAPI.ListLoadBalancers(ctx, model.ProjectId, model.Region)
121121

122122
return request
123123
}
@@ -135,7 +135,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, items []a
135135

136136
var errNo int
137137
if item.Errors != nil {
138-
errNo = len(*item.Errors)
138+
errNo = len(item.Errors)
139139
}
140140
table.AddRow(utils.PtrString(item.Name),
141141
utils.PtrString(item.ExternalAddress),

0 commit comments

Comments
 (0)