Skip to content

Commit 620d67a

Browse files
committed
adjust public-ip commands
1 parent cc5fb11 commit 620d67a

File tree

14 files changed

+82
-29
lines changed

14 files changed

+82
-29
lines changed

internal/cmd/public-ip/associate/associate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
5656
return err
5757
}
5858

59-
publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.PublicIpId)
59+
publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.Region, model.PublicIpId)
6060
if err != nil {
6161
params.Printer.Debug(print.ErrorLevel, "get public IP: %v", err)
6262
publicIpLabel = model.PublicIpId
@@ -113,7 +113,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
113113
}
114114

115115
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdatePublicIPRequest {
116-
req := apiClient.UpdatePublicIP(ctx, model.ProjectId, model.PublicIpId)
116+
req := apiClient.UpdatePublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId)
117117

118118
payload := iaas.UpdatePublicIPPayload{
119119
NetworkInterface: iaas.NewNullableString(model.AssociatedResourceId),

internal/cmd/public-ip/associate/associate_test.go

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

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

1924
type testCtxKey struct{}
2025

@@ -37,7 +42,9 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3742

3843
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3944
flagValues := map[string]string{
40-
projectIdFlag: testProjectId,
45+
projectIdFlag: testProjectId,
46+
regionFlag: testRegion,
47+
4148
associatedResourceIdFlag: testAssociatedResourceId,
4249
}
4350
for _, mod := range mods {
@@ -51,6 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5158
GlobalFlagModel: &globalflags.GlobalFlagModel{
5259
ProjectId: testProjectId,
5360
Verbosity: globalflags.VerbosityDefault,
61+
Region: testRegion,
5462
},
5563
PublicIpId: testPublicIpId,
5664
AssociatedResourceId: utils.Ptr(testAssociatedResourceId),
@@ -62,7 +70,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6270
}
6371

6472
func fixtureRequest(mods ...func(request *iaas.ApiUpdatePublicIPRequest)) iaas.ApiUpdatePublicIPRequest {
65-
request := testClient.UpdatePublicIP(testCtx, testProjectId, testPublicIpId)
73+
request := testClient.UpdatePublicIP(testCtx, testProjectId, testRegion, testPublicIpId)
6674
request = request.UpdatePublicIPPayload(fixturePayload())
6775
for _, mod := range mods {
6876
mod(&request)

internal/cmd/public-ip/create/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
114114
}
115115

116116
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreatePublicIPRequest {
117-
req := apiClient.CreatePublicIP(ctx, model.ProjectId)
117+
req := apiClient.CreatePublicIP(ctx, model.ProjectId, model.Region)
118118

119119
payload := iaas.CreatePublicIPPayload{
120120
NetworkInterface: iaas.NewNullableString(model.AssociatedResourceId),

internal/cmd/public-ip/create/create_test.go

Lines changed: 11 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

@@ -28,7 +33,9 @@ var testAssociatedResourceId = uuid.NewString()
2833

2934
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3035
flagValues := map[string]string{
31-
projectIdFlag: testProjectId,
36+
projectIdFlag: testProjectId,
37+
regionFlag: testRegion,
38+
3239
associatedResourceIdFlag: testAssociatedResourceId,
3340
labelFlag: "key=value",
3441
}
@@ -43,6 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4350
GlobalFlagModel: &globalflags.GlobalFlagModel{
4451
ProjectId: testProjectId,
4552
Verbosity: globalflags.VerbosityDefault,
53+
Region: testRegion,
4654
},
4755
AssociatedResourceId: utils.Ptr(testAssociatedResourceId),
4856
Labels: utils.Ptr(map[string]string{
@@ -56,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5664
}
5765

5866
func fixtureRequest(mods ...func(request *iaas.ApiCreatePublicIPRequest)) iaas.ApiCreatePublicIPRequest {
59-
request := testClient.CreatePublicIP(testCtx, testProjectId)
67+
request := testClient.CreatePublicIP(testCtx, testProjectId, testRegion)
6068
request = request.CreatePublicIPPayload(fixturePayload())
6169
for _, mod := range mods {
6270
mod(&request)

internal/cmd/public-ip/delete/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
5454
return err
5555
}
5656

57-
publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.PublicIpId)
57+
publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.Region, model.PublicIpId)
5858
if err != nil {
5959
params.Printer.Debug(print.ErrorLevel, "get public IP: %v", err)
6060
publicIpLabel = model.PublicIpId
@@ -102,5 +102,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
102102
}
103103

104104
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeletePublicIPRequest {
105-
return apiClient.DeletePublicIP(ctx, model.ProjectId, model.PublicIpId)
105+
return apiClient.DeletePublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId)
106106
}

internal/cmd/public-ip/delete/delete_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import (
1313
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1414
)
1515

16-
var projectIdFlag = globalflags.ProjectIdFlag
16+
const (
17+
projectIdFlag = globalflags.ProjectIdFlag
18+
regionFlag = globalflags.RegionFlag
19+
20+
testRegion = "eu01"
21+
)
1722

1823
type testCtxKey struct{}
1924

@@ -35,6 +40,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3540
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3641
flagValues := map[string]string{
3742
projectIdFlag: testProjectId,
43+
regionFlag: testRegion,
3844
}
3945
for _, mod := range mods {
4046
mod(flagValues)
@@ -47,6 +53,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4753
GlobalFlagModel: &globalflags.GlobalFlagModel{
4854
Verbosity: globalflags.VerbosityDefault,
4955
ProjectId: testProjectId,
56+
Region: testRegion,
5057
},
5158
PublicIpId: testPublicIpId,
5259
}
@@ -57,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5764
}
5865

5966
func fixtureRequest(mods ...func(request *iaas.ApiDeletePublicIPRequest)) iaas.ApiDeletePublicIPRequest {
60-
request := testClient.DeletePublicIP(testCtx, testProjectId, testPublicIpId)
67+
request := testClient.DeletePublicIP(testCtx, testProjectId, testRegion, testPublicIpId)
6168
for _, mod := range mods {
6269
mod(&request)
6370
}

internal/cmd/public-ip/describe/describe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
8888
}
8989

9090
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetPublicIPRequest {
91-
return apiClient.GetPublicIP(ctx, model.ProjectId, model.PublicIpId)
91+
return apiClient.GetPublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId)
9292
}
9393

9494
func outputResult(p *print.Printer, outputFormat string, publicIp iaas.PublicIp) error {

internal/cmd/public-ip/describe/describe_test.go

Lines changed: 9 additions & 2 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

@@ -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
}
4147
for _, mod := range mods {
4248
mod(flagValues)
@@ -49,6 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4955
GlobalFlagModel: &globalflags.GlobalFlagModel{
5056
ProjectId: testProjectId,
5157
Verbosity: globalflags.VerbosityDefault,
58+
Region: testRegion,
5259
},
5360
PublicIpId: testPublicIpId,
5461
}
@@ -59,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5966
}
6067

6168
func fixtureRequest(mods ...func(request *iaas.ApiGetPublicIPRequest)) iaas.ApiGetPublicIPRequest {
62-
request := testClient.GetPublicIP(testCtx, testProjectId, testPublicIpId)
69+
request := testClient.GetPublicIP(testCtx, testProjectId, testRegion, testPublicIpId)
6370
for _, mod := range mods {
6471
mod(&request)
6572
}

internal/cmd/public-ip/disassociate/disassociate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
5252
return err
5353
}
5454

55-
publicIpLabel, associatedResourceId, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.PublicIpId)
55+
publicIpLabel, associatedResourceId, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.Region, model.PublicIpId)
5656
if err != nil {
5757
params.Printer.Debug(print.ErrorLevel, "get public IP: %v", err)
5858
publicIpLabel = model.PublicIpId
@@ -100,7 +100,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
100100
}
101101

102102
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdatePublicIPRequest {
103-
req := apiClient.UpdatePublicIP(ctx, model.ProjectId, model.PublicIpId)
103+
req := apiClient.UpdatePublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId)
104104

105105
payload := iaas.UpdatePublicIPPayload{
106106
NetworkInterface: iaas.NewNullableString(nil),

internal/cmd/public-ip/disassociate/disassociate_test.go

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

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

1924
type testCtxKey struct{}
2025

@@ -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
}
4147
for _, mod := range mods {
4248
mod(flagValues)
@@ -49,6 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4955
GlobalFlagModel: &globalflags.GlobalFlagModel{
5056
ProjectId: testProjectId,
5157
Verbosity: globalflags.VerbosityDefault,
58+
Region: testRegion,
5259
},
5360
PublicIpId: testPublicIpId,
5461
}
@@ -59,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5966
}
6067

6168
func fixtureRequest(mods ...func(request *iaas.ApiUpdatePublicIPRequest)) iaas.ApiUpdatePublicIPRequest {
62-
request := testClient.UpdatePublicIP(testCtx, testProjectId, testPublicIpId)
69+
request := testClient.UpdatePublicIP(testCtx, testProjectId, testRegion, testPublicIpId)
6370
request = request.UpdatePublicIPPayload(fixturePayload())
6471
for _, mod := range mods {
6572
mod(&request)

0 commit comments

Comments
 (0)