Skip to content

Commit cc5fb11

Browse files
committed
adjust nic commands
1 parent 38805b0 commit cc5fb11

File tree

10 files changed

+73
-36
lines changed

10 files changed

+73
-36
lines changed

internal/cmd/network-interface/create/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const (
3838

3939
type inputModel struct {
4040
*globalflags.GlobalFlagModel
41-
NetworkId *string
41+
NetworkId string
4242
AllowedAddresses *[]iaas.AllowedAddressesInner
4343
Ipv4 *string
4444
Ipv6 *string
@@ -177,7 +177,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
177177

178178
model := inputModel{
179179
GlobalFlagModel: globalFlags,
180-
NetworkId: flags.FlagToStringPointer(p, cmd, networkIdFlag),
180+
NetworkId: flags.FlagToStringValue(p, cmd, networkIdFlag),
181181
Ipv4: flags.FlagToStringPointer(p, cmd, ipv4Flag),
182182
Ipv6: flags.FlagToStringPointer(p, cmd, ipv6Flag),
183183
Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag),
@@ -195,7 +195,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
195195
}
196196

197197
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateNicRequest {
198-
req := apiClient.CreateNic(ctx, model.ProjectId, *model.NetworkId)
198+
req := apiClient.CreateNic(ctx, model.ProjectId, model.Region, model.NetworkId)
199199

200200
payload := iaas.CreateNicPayload{
201201
AllowedAddresses: model.AllowedAddresses,

internal/cmd/network-interface/create/create_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,27 @@ import (
1515
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1616
)
1717

18+
const (
19+
projectIdFlag = globalflags.ProjectIdFlag
20+
regionFlag = globalflags.RegionFlag
21+
22+
testRegion = "eu01"
23+
)
24+
1825
type testCtxKey struct{}
1926

2027
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2128
var testClient = &iaas.APIClient{}
2229

23-
var projectIdFlag = globalflags.ProjectIdFlag
2430
var testProjectId = uuid.NewString()
2531
var testNetworkId = uuid.NewString()
2632
var testSecurityGroup = uuid.NewString()
2733

2834
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2935
flagValues := map[string]string{
30-
projectIdFlag: testProjectId,
36+
projectIdFlag: testProjectId,
37+
regionFlag: testRegion,
38+
3139
networkIdFlag: testNetworkId,
3240
allowedAddressesFlag: "1.1.1.1,8.8.8.8,9.9.9.9",
3341
ipv4Flag: "1.2.3.4",
@@ -52,9 +60,10 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5260
model := &inputModel{
5361
GlobalFlagModel: &globalflags.GlobalFlagModel{
5462
ProjectId: testProjectId,
63+
Region: testRegion,
5564
Verbosity: globalflags.VerbosityDefault,
5665
},
57-
NetworkId: utils.Ptr(testNetworkId),
66+
NetworkId: testNetworkId,
5867
AllowedAddresses: utils.Ptr(allowedAddresses),
5968
Ipv4: utils.Ptr("1.2.3.4"),
6069
Ipv6: utils.Ptr("2001:0db8:85a3:08d3::0370:7344"),
@@ -72,7 +81,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
7281
}
7382

7483
func fixtureRequest(mods ...func(request *iaas.ApiCreateNicRequest)) iaas.ApiCreateNicRequest {
75-
request := testClient.CreateNic(testCtx, testProjectId, testNetworkId)
84+
request := testClient.CreateNic(testCtx, testProjectId, testRegion, testNetworkId)
7685
request = request.CreateNicPayload(fixturePayload())
7786
for _, mod := range mods {
7887
mod(&request)

internal/cmd/network-interface/delete/delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424

2525
type inputModel struct {
2626
*globalflags.GlobalFlagModel
27-
NetworkId *string
27+
NetworkId string
2828
NicId string
2929
}
3030

@@ -90,7 +90,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
9090

9191
model := inputModel{
9292
GlobalFlagModel: globalFlags,
93-
NetworkId: flags.FlagToStringPointer(p, cmd, networkIdFlag),
93+
NetworkId: flags.FlagToStringValue(p, cmd, networkIdFlag),
9494
NicId: nicId,
9595
}
9696

@@ -99,6 +99,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
9999
}
100100

101101
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteNicRequest {
102-
req := apiClient.DeleteNic(ctx, model.ProjectId, *model.NetworkId, model.NicId)
102+
req := apiClient.DeleteNic(ctx, model.ProjectId, model.Region, model.NetworkId, model.NicId)
103103
return req
104104
}

internal/cmd/network-interface/delete/delete_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@ import (
1010
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1212
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
13-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1413
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1514
)
1615

16+
const (
17+
projectIdFlag = globalflags.ProjectIdFlag
18+
regionFlag = globalflags.RegionFlag
19+
20+
testRegion = "eu01"
21+
)
22+
1723
type testCtxKey struct{}
1824

1925
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2026
var testClient = &iaas.APIClient{}
2127

22-
var projectIdFlag = globalflags.ProjectIdFlag
2328
var testProjectId = uuid.NewString()
2429
var testNetworkId = uuid.NewString()
2530
var testNicId = uuid.NewString()
@@ -37,6 +42,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3742
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3843
flagValues := map[string]string{
3944
projectIdFlag: testProjectId,
45+
regionFlag: testRegion,
4046
networkIdFlag: testNetworkId,
4147
}
4248
for _, mod := range mods {
@@ -50,8 +56,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5056
GlobalFlagModel: &globalflags.GlobalFlagModel{
5157
ProjectId: testProjectId,
5258
Verbosity: globalflags.VerbosityDefault,
59+
Region: testRegion,
5360
},
54-
NetworkId: utils.Ptr(testNetworkId),
61+
NetworkId: testNetworkId,
5562
NicId: testNicId,
5663
}
5764
for _, mod := range mods {
@@ -61,7 +68,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6168
}
6269

6370
func fixtureRequest(mods ...func(request *iaas.ApiDeleteNicRequest)) iaas.ApiDeleteNicRequest {
64-
request := testClient.DeleteNic(testCtx, testProjectId, testNetworkId, testNicId)
71+
request := testClient.DeleteNic(testCtx, testProjectId, testRegion, testNetworkId, testNicId)
6572
for _, mod := range mods {
6673
mod(&request)
6774
}

internal/cmd/network-interface/describe/describe.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727

2828
type inputModel struct {
2929
*globalflags.GlobalFlagModel
30-
NetworkId *string
30+
NetworkId string
3131
NicId string
3232
}
3333

@@ -94,7 +94,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
9494

9595
model := inputModel{
9696
GlobalFlagModel: globalFlags,
97-
NetworkId: flags.FlagToStringPointer(p, cmd, networkIdFlag),
97+
NetworkId: flags.FlagToStringValue(p, cmd, networkIdFlag),
9898
NicId: nicId,
9999
}
100100

@@ -103,7 +103,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
103103
}
104104

105105
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetNicRequest {
106-
req := apiClient.GetNic(ctx, model.ProjectId, *model.NetworkId, model.NicId)
106+
req := apiClient.GetNic(ctx, model.ProjectId, model.Region, model.NetworkId, model.NicId)
107107
return req
108108
}
109109

internal/cmd/network-interface/describe/describe_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@ import (
1010
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1212
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
13-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1413
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1514
)
1615

16+
const (
17+
projectIdFlag = globalflags.ProjectIdFlag
18+
regionFlag = globalflags.RegionFlag
19+
20+
testRegion = "eu01"
21+
)
22+
1723
type testCtxKey struct{}
1824

1925
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2026
var testClient = &iaas.APIClient{}
2127

22-
var projectIdFlag = globalflags.ProjectIdFlag
2328
var testProjectId = uuid.NewString()
2429
var testNetworkId = uuid.NewString()
2530
var testNicId = uuid.NewString()
@@ -37,6 +42,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3742
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3843
flagValues := map[string]string{
3944
projectIdFlag: testProjectId,
45+
regionFlag: testRegion,
4046
networkIdFlag: testNetworkId,
4147
}
4248
for _, mod := range mods {
@@ -50,8 +56,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5056
GlobalFlagModel: &globalflags.GlobalFlagModel{
5157
ProjectId: testProjectId,
5258
Verbosity: globalflags.VerbosityDefault,
59+
Region: testRegion,
5360
},
54-
NetworkId: utils.Ptr(testNetworkId),
61+
NetworkId: testNetworkId,
5562
NicId: testNicId,
5663
}
5764
for _, mod := range mods {
@@ -61,7 +68,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6168
}
6269

6370
func fixtureRequest(mods ...func(request *iaas.ApiGetNicRequest)) iaas.ApiGetNicRequest {
64-
request := testClient.GetNic(testCtx, testProjectId, testNetworkId, testNicId)
71+
request := testClient.GetNic(testCtx, testProjectId, testRegion, testNetworkId, testNicId)
6572
for _, mod := range mods {
6673
mod(&request)
6774
}

internal/cmd/network-interface/list/list.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type inputModel struct {
2929
*globalflags.GlobalFlagModel
3030
Limit *int64
3131
LabelSelector *string
32-
NetworkId *string
32+
NetworkId string
3333
}
3434

3535
func NewCmd(params *params.CmdParams) *cobra.Command {
@@ -77,12 +77,12 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
7777
}
7878

7979
if resp.Items == nil || len(*resp.Items) == 0 {
80-
networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, *model.NetworkId)
80+
networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, model.NetworkId)
8181
if err != nil {
8282
params.Printer.Debug(print.ErrorLevel, "get network name: %v", err)
83-
networkLabel = *model.NetworkId
83+
networkLabel = model.NetworkId
8484
} else if networkLabel == "" {
85-
networkLabel = *model.NetworkId
85+
networkLabel = model.NetworkId
8686
}
8787
params.Printer.Info("No network interfaces found for network %q\n", networkLabel)
8888
return nil
@@ -128,15 +128,15 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
128128
GlobalFlagModel: globalFlags,
129129
Limit: limit,
130130
LabelSelector: flags.FlagToStringPointer(p, cmd, labelSelectorFlag),
131-
NetworkId: flags.FlagToStringPointer(p, cmd, networkIdFlag),
131+
NetworkId: flags.FlagToStringValue(p, cmd, networkIdFlag),
132132
}
133133

134134
p.DebugInputModel(model)
135135
return &model, nil
136136
}
137137

138138
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListNicsRequest {
139-
req := apiClient.ListNics(ctx, model.ProjectId, *model.NetworkId)
139+
req := apiClient.ListNics(ctx, model.ProjectId, model.Region, model.NetworkId)
140140
if model.LabelSelector != nil {
141141
req = req.LabelSelector(*model.LabelSelector)
142142
}

internal/cmd/network-interface/list/list_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import (
1616
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1717
)
1818

19-
var projectIdFlag = globalflags.ProjectIdFlag
19+
const (
20+
projectIdFlag = globalflags.ProjectIdFlag
21+
regionFlag = globalflags.RegionFlag
22+
23+
testRegion = "eu01"
24+
)
2025

2126
type testCtxKey struct{}
2227

@@ -29,6 +34,7 @@ var testLabelSelector = "label"
2934
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3035
flagValues := map[string]string{
3136
projectIdFlag: testProjectId,
37+
regionFlag: testRegion,
3238
networkIdFlag: testNetworkId,
3339
limitFlag: "10",
3440
labelSelectorFlag: testLabelSelector,
@@ -44,10 +50,11 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4450
GlobalFlagModel: &globalflags.GlobalFlagModel{
4551
Verbosity: globalflags.VerbosityDefault,
4652
ProjectId: testProjectId,
53+
Region: testRegion,
4754
},
4855
Limit: utils.Ptr(int64(10)),
4956
LabelSelector: utils.Ptr(testLabelSelector),
50-
NetworkId: utils.Ptr(testNetworkId),
57+
NetworkId: testNetworkId,
5158
}
5259
for _, mod := range mods {
5360
mod(model)
@@ -56,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5663
}
5764

5865
func fixtureRequest(mods ...func(request *iaas.ApiListNicsRequest)) iaas.ApiListNicsRequest {
59-
request := testClient.ListNics(testCtx, testProjectId, testNetworkId)
66+
request := testClient.ListNics(testCtx, testProjectId, testRegion, testNetworkId)
6067
request = request.LabelSelector(testLabelSelector)
6168
for _, mod := range mods {
6269
mod(&request)

internal/cmd/network-interface/update/update.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const (
3838
type inputModel struct {
3939
*globalflags.GlobalFlagModel
4040
NicId string
41-
NetworkId *string
41+
NetworkId string
4242
AllowedAddresses *[]iaas.AllowedAddressesInner
4343
Labels *map[string]string
4444
Name *string // <= 63 characters + regex ^[A-Za-z0-9]+((-|_|\s|\.)[A-Za-z0-9]+)*$
@@ -171,7 +171,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
171171
model := inputModel{
172172
GlobalFlagModel: globalFlags,
173173
NicId: nicId,
174-
NetworkId: flags.FlagToStringPointer(p, cmd, networkIdFlag),
174+
NetworkId: flags.FlagToStringValue(p, cmd, networkIdFlag),
175175
Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag),
176176
Name: name,
177177
NicSecurity: flags.FlagToBoolPointer(p, cmd, nicSecurityFlag),
@@ -187,7 +187,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
187187
}
188188

189189
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateNicRequest {
190-
req := apiClient.UpdateNic(ctx, model.ProjectId, *model.NetworkId, model.NicId)
190+
req := apiClient.UpdateNic(ctx, model.ProjectId, model.Region, model.NetworkId, model.NicId)
191191

192192
payload := iaas.UpdateNicPayload{
193193
AllowedAddresses: model.AllowedAddresses,

internal/cmd/network-interface/update/update_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import (
1515
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1616
)
1717

18-
var projectIdFlag = globalflags.ProjectIdFlag
18+
const (
19+
projectIdFlag = globalflags.ProjectIdFlag
20+
regionFlag = globalflags.RegionFlag
21+
22+
testRegion = "eu01"
23+
)
1924

2025
type testCtxKey struct{}
2126

@@ -39,6 +44,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3944
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
4045
flagValues := map[string]string{
4146
projectIdFlag: testProjectId,
47+
regionFlag: testRegion,
4248
networkIdFlag: testNetworkId,
4349
allowedAddressesFlag: "1.1.1.1,8.8.8.8,9.9.9.9",
4450
labelFlag: "key=value",
@@ -62,8 +68,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6268
GlobalFlagModel: &globalflags.GlobalFlagModel{
6369
ProjectId: testProjectId,
6470
Verbosity: globalflags.VerbosityDefault,
71+
Region: testRegion,
6572
},
66-
NetworkId: utils.Ptr(testNetworkId),
73+
NetworkId: testNetworkId,
6774
AllowedAddresses: utils.Ptr(allowedAddresses),
6875
Labels: utils.Ptr(map[string]string{
6976
"key": "value",
@@ -80,7 +87,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
8087
}
8188

8289
func fixtureRequest(mods ...func(request *iaas.ApiUpdateNicRequest)) iaas.ApiUpdateNicRequest {
83-
request := testClient.UpdateNic(testCtx, testProjectId, testNetworkId, testNicId)
90+
request := testClient.UpdateNic(testCtx, testProjectId, testRegion, testNetworkId, testNicId)
8491
request = request.UpdateNicPayload(fixturePayload())
8592
for _, mod := range mods {
8693
mod(&request)

0 commit comments

Comments
 (0)