Skip to content

Commit 1a6aca2

Browse files
committed
review changes
1 parent 90d3cf8 commit 1a6aca2

File tree

7 files changed

+199
-60
lines changed

7 files changed

+199
-60
lines changed

docs/stackit_routing-table_update.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ stackit routing-table update ROUTING_TABLE_ID [flags]
3333

3434
```
3535
--description string Description of the routing-table
36-
--dynamic-routes If set to false, prevents dynamic routes from propagating to the routing table. (default true)
36+
--dynamic-routes If set to false, prevents dynamic routes from propagating to the routing table.
3737
-h, --help Help for "stackit routing-table update"
3838
--labels stringToString Key=value labels (default [])
3939
--name string Name of the routing-table
4040
--network-area-id string Network-Area ID
4141
--organization-id string Organization ID
42-
--system-routes If set to false, disables routes for project-to-project communication. (default true)
42+
--system-routes If set to false, disables routes for project-to-project communication.
4343
```
4444

4545
### Options inherited from parent commands

internal/cmd/routingtable/delete/delete.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1212
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
14+
iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils"
1415
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1516
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1617
)
@@ -53,7 +54,16 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5354
return err
5455
}
5556

56-
prompt := fmt.Sprintf("Are you sure you want to delete the routing-table %q?", model.RoutingTableId)
57+
routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId)
58+
if err != nil {
59+
params.Printer.Debug(print.ErrorLevel, "get routing-table name: %v", err)
60+
routingTableLabel = model.RoutingTableId
61+
} else if routingTableLabel == "" {
62+
routingTableLabel = model.RoutingTableId
63+
}
64+
65+
prompt := fmt.Sprintf("Are you sure you want to delete the routing-table %q?", routingTableLabel)
66+
5767
err = params.Printer.PromptForConfirmation(prompt)
5868
if err != nil {
5969
return err

internal/cmd/routingtable/describe/describe.go

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,40 @@ func outputResult(p *print.Printer, outputFormat string, routingTable *iaas.Rout
107107
}
108108

109109
return p.OutputResult(outputFormat, routingTable, func() error {
110-
var labels []string
110+
table := tables.NewTable()
111+
112+
table.AddRow("ID", utils.PtrString(routingTable.Id))
113+
table.AddSeparator()
114+
115+
table.AddRow("NAME", utils.PtrString(routingTable.Name))
116+
table.AddSeparator()
117+
118+
table.AddRow("DESCRIPTION", utils.PtrString(routingTable.Description))
119+
table.AddSeparator()
120+
121+
table.AddRow("DEFAULT", utils.PtrString(routingTable.Default))
122+
table.AddSeparator()
123+
111124
if routingTable.Labels != nil && len(*routingTable.Labels) > 0 {
125+
var labels []string
112126
for key, value := range *routingTable.Labels {
113127
labels = append(labels, fmt.Sprintf("%s: %s", key, value))
114128
}
129+
table.AddRow("LABELS", strings.Join(labels, "\n"))
130+
table.AddSeparator()
115131
}
116132

117-
table := tables.NewTable()
118-
table.SetHeader("ID", "NAME", "DESCRIPTION", "DEFAULT", "LABELS", "SYSTEM ROUTES", "DYNAMIC ROUTES", "CREATED AT", "UPDATED AT")
119-
table.AddRow(
120-
utils.PtrString(routingTable.Id),
121-
utils.PtrString(routingTable.Name),
122-
utils.PtrString(routingTable.Description),
123-
utils.PtrString(routingTable.Default),
124-
strings.Join(labels, "\n"),
125-
utils.PtrString(routingTable.SystemRoutes),
126-
utils.PtrString(routingTable.DynamicRoutes),
127-
utils.ConvertTimePToDateTimeString(routingTable.CreatedAt),
128-
utils.ConvertTimePToDateTimeString(routingTable.UpdatedAt),
129-
)
133+
table.AddRow("SYSTEM ROUTES", utils.PtrString(routingTable.SystemRoutes))
134+
table.AddSeparator()
135+
136+
table.AddRow("DYNAMIC ROUTES", utils.PtrString(routingTable.DynamicRoutes))
137+
table.AddSeparator()
138+
139+
table.AddRow("CREATED AT", utils.ConvertTimePToDateTimeString(routingTable.CreatedAt))
140+
table.AddSeparator()
141+
142+
table.AddRow("UPDATED AT", utils.ConvertTimePToDateTimeString(routingTable.UpdatedAt))
143+
table.AddSeparator()
130144

131145
err := table.Display(p)
132146
if err != nil {

internal/cmd/routingtable/update/update.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1212
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
14+
iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils"
1415
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1516
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1617
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
@@ -31,8 +32,8 @@ type inputModel struct {
3132
*globalflags.GlobalFlagModel
3233
OrganizationId string
3334
NetworkAreaId string
34-
DynamicRoutes bool
35-
SystemRoutes bool
35+
DynamicRoutes *bool
36+
SystemRoutes *bool
3637
RoutingTableId string
3738
Description *string
3839
Labels *map[string]string
@@ -80,7 +81,15 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8081
return err
8182
}
8283

83-
prompt := fmt.Sprintf("Are you sure you want to update routing-table %q?", model.RoutingTableId)
84+
routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId)
85+
if err != nil {
86+
params.Printer.Debug(print.ErrorLevel, "get routing-table name: %v", err)
87+
routingTableLabel = model.RoutingTableId
88+
} else if routingTableLabel == "" {
89+
routingTableLabel = model.RoutingTableId
90+
}
91+
92+
prompt := fmt.Sprintf("Are you sure you want to update the routing-table %q?", routingTableLabel)
8493
err = params.Printer.PromptForConfirmation(prompt)
8594
if err != nil {
8695
return err
@@ -104,11 +113,11 @@ func configureFlags(cmd *cobra.Command) {
104113
cmd.Flags().String(nameFlag, "", "Name of the routing-table")
105114
cmd.Flags().StringToString(labelFlag, nil, "Key=value labels")
106115
cmd.Flags().Var(flags.UUIDFlag(), networkAreaIdFlag, "Network-Area ID")
107-
cmd.Flags().Bool(dynamicRoutesFlag, true, "If set to false, prevents dynamic routes from propagating to the routing table.")
108-
cmd.Flags().Bool(systemRoutesFlag, true, "If set to false, disables routes for project-to-project communication.")
116+
cmd.Flags().Bool(dynamicRoutesFlag, false, "If set to false, prevents dynamic routes from propagating to the routing table.")
117+
cmd.Flags().Bool(systemRoutesFlag, false, "If set to false, disables routes for project-to-project communication.")
109118
cmd.Flags().Var(flags.UUIDFlag(), organizationIdFlag, "Organization ID")
110119

111-
err := flags.MarkFlagsRequired(cmd, organizationIdFlag, networkAreaIdFlag)
120+
err := flags.MarkFlagsRequired(cmd, organizationIdFlag, networkAreaIdFlag, dynamicRoutesFlag, systemRoutesFlag, nameFlag)
112121
cobra.CheckErr(err)
113122
}
114123

@@ -123,8 +132,8 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
123132
Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag),
124133
Name: flags.FlagToStringPointer(p, cmd, nameFlag),
125134
NetworkAreaId: flags.FlagToStringValue(p, cmd, networkAreaIdFlag),
126-
SystemRoutes: flags.FlagToBoolValue(p, cmd, systemRoutesFlag),
127-
DynamicRoutes: flags.FlagToBoolValue(p, cmd, dynamicRoutesFlag),
135+
SystemRoutes: flags.FlagToBoolPointer(p, cmd, systemRoutesFlag),
136+
DynamicRoutes: flags.FlagToBoolPointer(p, cmd, dynamicRoutesFlag),
128137
OrganizationId: flags.FlagToStringValue(p, cmd, organizationIdFlag),
129138
RoutingTableId: routeTableId,
130139
}
@@ -161,8 +170,8 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
161170
Labels: utils.ConvertStringMapToInterfaceMap(model.Labels),
162171
Name: model.Name,
163172
Description: model.Description,
164-
DynamicRoutes: &model.DynamicRoutes,
165-
SystemRoutes: &model.SystemRoutes,
173+
DynamicRoutes: model.DynamicRoutes,
174+
SystemRoutes: model.SystemRoutes,
166175
}
167176

168177
return req.UpdateRoutingTableOfAreaPayload(payload)

internal/cmd/routingtable/update/update_test.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6767
NetworkAreaId: testNetworkAreaId,
6868
Name: utils.Ptr(testRoutingTableName),
6969
Description: utils.Ptr(testRoutingTableDescription),
70-
SystemRoutes: testSystemRoutesFlag,
71-
DynamicRoutes: testDynamicRoutesFlag,
72-
Labels: utils.Ptr(*testLabels),
70+
SystemRoutes: utils.Ptr(testSystemRoutesFlag),
71+
DynamicRoutes: utils.Ptr(testDynamicRoutesFlag),
72+
Labels: testLabels,
7373
}
7474
for _, mod := range mods {
7575
mod(model)
@@ -137,7 +137,7 @@ func TestParseInput(t *testing.T) {
137137
argValues: fixtureArgValues(),
138138
isValid: true,
139139
expectedModel: fixtureInputModel(func(model *inputModel) {
140-
model.DynamicRoutes = false
140+
model.DynamicRoutes = utils.Ptr(false)
141141
model.RoutingTableId = testRoutingTableId
142142
}),
143143
},
@@ -149,7 +149,7 @@ func TestParseInput(t *testing.T) {
149149
argValues: fixtureArgValues(),
150150
isValid: true,
151151
expectedModel: fixtureInputModel(func(model *inputModel) {
152-
model.SystemRoutes = false
152+
model.SystemRoutes = utils.Ptr(false)
153153
model.RoutingTableId = testRoutingTableId
154154
}),
155155
},
@@ -167,6 +167,22 @@ func TestParseInput(t *testing.T) {
167167
}),
168168
isValid: false,
169169
},
170+
{
171+
description: "dynamic-route-flag missing",
172+
argValues: []string{testRoutingTableId},
173+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
174+
delete(flagValues, dynamicRoutesFlag)
175+
}),
176+
isValid: false,
177+
},
178+
{
179+
description: "system-routes-flag missing",
180+
argValues: []string{testRoutingTableId},
181+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
182+
delete(flagValues, systemRoutesFlag)
183+
}),
184+
isValid: false,
185+
},
170186
{
171187
description: "org-id missing",
172188
argValues: fixtureArgValues(),
@@ -277,7 +293,7 @@ func TestBuildRequest(t *testing.T) {
277293
description: "dynamic routes disabled",
278294
model: fixtureInputModel(func(model *inputModel) {
279295
model.RoutingTableId = testRoutingTableId
280-
model.DynamicRoutes = false
296+
model.DynamicRoutes = utils.Ptr(false)
281297
}),
282298
expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateRoutingTableOfAreaRequest) {
283299
*request = (*request).UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{
@@ -293,7 +309,7 @@ func TestBuildRequest(t *testing.T) {
293309
description: "system routes disabled",
294310
model: fixtureInputModel(func(model *inputModel) {
295311
model.RoutingTableId = testRoutingTableId
296-
model.DynamicRoutes = false
312+
model.DynamicRoutes = utils.Ptr(false)
297313
}),
298314
expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateRoutingTableOfAreaRequest) {
299315
*request = (*request).UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{

internal/pkg/services/iaas/utils/utils.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type IaaSClient interface {
2121
GetServerExecute(ctx context.Context, projectId, region, serverId string) (*iaas.Server, error)
2222
GetVolumeExecute(ctx context.Context, projectId, region, volumeId string) (*iaas.Volume, error)
2323
GetNetworkExecute(ctx context.Context, projectId, region, networkId string) (*iaas.Network, error)
24+
GetRoutingTableOfAreaExecute(ctx context.Context, organizationId, areaId, region, routingTableId string) (*iaas.RoutingTable, error)
2425
GetNetworkAreaExecute(ctx context.Context, organizationId, areaId string) (*iaas.NetworkArea, error)
2526
ListNetworkAreaProjectsExecute(ctx context.Context, organizationId, areaId string) (*iaas.ProjectListResponse, error)
2627
GetNetworkAreaRangeExecute(ctx context.Context, organizationId, areaId, region, networkRangeId string) (*iaas.NetworkRange, error)
@@ -95,6 +96,18 @@ func GetNetworkName(ctx context.Context, apiClient IaaSClient, projectId, region
9596
return *resp.Name, nil
9697
}
9798

99+
func GetRoutingTableOfAreaName(ctx context.Context, apiClient IaaSClient, organizationId, areaId, region, routingTableId string) (string, error) {
100+
resp, err := apiClient.GetRoutingTableOfAreaExecute(ctx, organizationId, areaId, region, routingTableId)
101+
if err != nil {
102+
return "", fmt.Errorf("get routing-table: %w", err)
103+
} else if resp == nil {
104+
return "", ErrResponseNil
105+
} else if resp.Name == nil {
106+
return "", ErrNameNil
107+
}
108+
return *resp.Name, nil
109+
}
110+
98111
func GetNetworkAreaName(ctx context.Context, apiClient IaaSClient, organizationId, areaId string) (string, error) {
99112
resp, err := apiClient.GetNetworkAreaExecute(ctx, organizationId, areaId)
100113
if err != nil {

0 commit comments

Comments
 (0)