Skip to content

Commit b9dbaef

Browse files
committed
review changes
1 parent e6bee1e commit b9dbaef

File tree

15 files changed

+167
-170
lines changed

15 files changed

+167
-170
lines changed

docs/stackit_routing-table_create.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ stackit routing-table create [flags]
2020
stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --description "some description"
2121
2222
Create a routing-table with name `rt` with system routes disabled
23-
stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-system-routes
23+
stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --system-routes false
2424
2525
Create a routing-table with name `rt` with dynamic routes disabled
26-
stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-dynamic-routes
26+
stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --dynamic-routes false
2727
```
2828

2929
### Options
3030

3131
```
3232
--description string Description of the routing-table
33+
--dynamic-routes If false, preventing dynamic routes from propagating to the routing-table. (default true)
3334
-h, --help Help for "stackit routing-table create"
3435
--labels stringToString Key=value labels (default [])
3536
--name string Name of the routing-table
3637
--network-area-id string Network-Area ID
37-
--non-dynamic-routes If true, preventing dynamic routes from propagating to the routing-table.
38-
--non-system-routes If true, automatically disables routes for project-to-project communication.
3938
--organization-id string Organization ID
39+
--system-routes If false, automatically disables routes for project-to-project communication. (default true)
4040
```
4141

4242
### Options inherited from parent commands

docs/stackit_routing-table_delete.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Deletes a routing-table
77
Deletes a routing-table
88

99
```
10-
stackit routing-table delete ROUTING_TABLE [flags]
10+
stackit routing-table delete ROUTING_TABLE_ID [flags]
1111
```
1212

1313
### Examples

docs/stackit_routing-table_update.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ stackit routing-table update ROUTING_TABLE_ID [flags]
2323
$ stackit routing-table update xxx --description foo --organization-id yyy --network-area-id zzz
2424
2525
Disables the dynamic routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"
26-
$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --non-dynamic-routes
26+
$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --disable-dynamic-routes
2727
2828
Disables the system routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"
29-
$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --non-system-routes
29+
$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --disable-system-routes
3030
```
3131

3232
### Options
3333

3434
```
3535
--description string Description of the routing-table
36+
--dynamic-routes If false, automatically disables routes for project-to-project communication. (default true)
3637
-h, --help Help for "stackit routing-table update"
3738
--labels stringToString Key=value labels (default [])
3839
--name string Name of the routing-table
3940
--network-area-id string Network-Area ID
40-
--non-dynamic-routes If true, preventing dynamic routes from propagating to the routing-table.
41-
--non-system-routes If true, automatically disables routes for project-to-project communication.
4241
--organization-id string Organization ID
42+
--system-routes If false, preventing dynamic routes from propagating to the routing-table. (default true)
4343
```
4444

4545
### Options inherited from parent commands

internal/cmd/routingtable/create/create.go

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ import (
1919
)
2020

2121
const (
22-
descriptionFlag = "description"
23-
labelFlag = "labels"
24-
nameFlag = "name"
25-
networkAreaIdFlag = "network-area-id"
26-
nonDynamicRoutesFlag = "non-dynamic-routes"
27-
nonSystemRoutesFlag = "non-system-routes"
28-
organizationIdFlag = "organization-id"
22+
descriptionFlag = "description"
23+
labelFlag = "labels"
24+
nameFlag = "name"
25+
networkAreaIdFlag = "network-area-id"
26+
dynamicRoutesFlag = "dynamic-routes"
27+
systemRoutesFlag = "system-routes"
28+
organizationIdFlag = "organization-id"
2929
)
3030

3131
type inputModel struct {
3232
*globalflags.GlobalFlagModel
33-
Description *string
34-
Labels *map[string]string
35-
Name string
36-
NetworkAreaId string
37-
NonSystemRoutes bool
38-
NonDynamicRoutes bool
39-
OrganizationId string
33+
Description *string
34+
Labels *map[string]string
35+
Name string
36+
NetworkAreaId string
37+
SystemRoutes bool
38+
DynamicRoutes bool
39+
OrganizationId string
4040
}
4141

4242
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -56,11 +56,11 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5656
),
5757
examples.NewExample(
5858
"Create a routing-table with name `rt` with system routes disabled",
59-
`stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-system-routes`,
59+
`stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --system-routes false`,
6060
),
6161
examples.NewExample(
6262
"Create a routing-table with name `rt` with dynamic routes disabled",
63-
`stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-dynamic-routes`,
63+
`stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --dynamic-routes false`,
6464
),
6565
),
6666
RunE: func(cmd *cobra.Command, _ []string) error {
@@ -76,8 +76,9 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7676
}
7777

7878
if !model.AssumeYes {
79-
prompt := fmt.Sprintf("Are you sure you want to create a routing-table with the name %s?", model.Name)
80-
if err := params.Printer.PromptForConfirmation(prompt); err != nil {
79+
prompt := fmt.Sprintf("Are you sure you want to create the routing-table %q?", model.Name)
80+
err = params.Printer.PromptForConfirmation(prompt)
81+
if err != nil {
8182
return err
8283
}
8384
}
@@ -104,8 +105,8 @@ func configureFlags(cmd *cobra.Command) {
104105
cmd.Flags().StringToString(labelFlag, nil, "Key=value labels")
105106
cmd.Flags().String(nameFlag, "", "Name of the routing-table")
106107
cmd.Flags().Var(flags.UUIDFlag(), networkAreaIdFlag, "Network-Area ID")
107-
cmd.Flags().Bool(nonDynamicRoutesFlag, false, "If true, preventing dynamic routes from propagating to the routing-table.")
108-
cmd.Flags().Bool(nonSystemRoutesFlag, false, "If true, automatically disables routes for project-to-project communication.")
108+
cmd.Flags().Bool(dynamicRoutesFlag, true, "If false, preventing dynamic routes from propagating to the routing-table.")
109+
cmd.Flags().Bool(systemRoutesFlag, true, "If false, automatically disables routes for project-to-project communication.")
109110
cmd.Flags().Var(flags.UUIDFlag(), organizationIdFlag, "Organization ID")
110111

111112
err := flags.MarkFlagsRequired(cmd, organizationIdFlag, networkAreaIdFlag, nameFlag)
@@ -116,30 +117,27 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
116117
globalFlags := globalflags.Parse(p, cmd)
117118

118119
model := &inputModel{
119-
GlobalFlagModel: globalFlags,
120-
Description: flags.FlagToStringPointer(p, cmd, descriptionFlag),
121-
NonDynamicRoutes: flags.FlagToBoolValue(p, cmd, nonDynamicRoutesFlag),
122-
Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag),
123-
Name: flags.FlagToStringValue(p, cmd, nameFlag),
124-
NetworkAreaId: flags.FlagToStringValue(p, cmd, networkAreaIdFlag),
125-
OrganizationId: flags.FlagToStringValue(p, cmd, organizationIdFlag),
126-
NonSystemRoutes: flags.FlagToBoolValue(p, cmd, nonSystemRoutesFlag),
120+
GlobalFlagModel: globalFlags,
121+
Description: flags.FlagToStringPointer(p, cmd, descriptionFlag),
122+
DynamicRoutes: flags.FlagToBoolValue(p, cmd, dynamicRoutesFlag),
123+
Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag),
124+
Name: flags.FlagToStringValue(p, cmd, nameFlag),
125+
NetworkAreaId: flags.FlagToStringValue(p, cmd, networkAreaIdFlag),
126+
OrganizationId: flags.FlagToStringValue(p, cmd, organizationIdFlag),
127+
SystemRoutes: flags.FlagToBoolValue(p, cmd, systemRoutesFlag),
127128
}
128129

129130
p.DebugInputModel(model)
130131
return model, nil
131132
}
132133

133134
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) (iaas.ApiAddRoutingTableToAreaRequest, error) {
134-
systemRoutes := !model.NonSystemRoutes
135-
dynamicRoutes := !model.NonDynamicRoutes
136-
137135
payload := iaas.AddRoutingTableToAreaPayload{
138136
Description: model.Description,
139137
Name: utils.Ptr(model.Name),
140138
Labels: utils.ConvertStringMapToInterfaceMap(model.Labels),
141-
SystemRoutes: utils.Ptr(systemRoutes),
142-
DynamicRoutes: utils.Ptr(dynamicRoutes),
139+
SystemRoutes: utils.Ptr(model.SystemRoutes),
140+
DynamicRoutes: utils.Ptr(model.DynamicRoutes),
143141
}
144142

145143
return apiClient.AddRoutingTableToArea(

internal/cmd/routingtable/create/create_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ var testNetworkAreaId = uuid.NewString()
3030
const testRoutingTableName = "test"
3131
const testRoutingTableDescription = "test"
3232

33-
const testNonSystemRoutes = false
34-
const testNonDynamicRoutes = false
33+
const testSystemRoutesFlag = true
34+
const testDynamicRoutesFlag = true
3535

3636
const testLabelSelectorFlag = "key1=value1,key2=value2"
3737

@@ -47,8 +47,8 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
4747
networkAreaIdFlag: testNetworkAreaId,
4848
descriptionFlag: testRoutingTableDescription,
4949
nameFlag: testRoutingTableName,
50-
nonSystemRoutesFlag: strconv.FormatBool(testNonSystemRoutes),
51-
nonDynamicRoutesFlag: strconv.FormatBool(testNonDynamicRoutes),
50+
systemRoutesFlag: strconv.FormatBool(testSystemRoutesFlag),
51+
dynamicRoutesFlag: strconv.FormatBool(testDynamicRoutesFlag),
5252
labelFlag: testLabelSelectorFlag,
5353
}
5454
for _, mod := range mods {
@@ -63,13 +63,13 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6363
Verbosity: globalflags.VerbosityDefault,
6464
Region: testRegion,
6565
},
66-
OrganizationId: testOrgId,
67-
NetworkAreaId: testNetworkAreaId,
68-
Name: testRoutingTableName,
69-
Description: utils.Ptr(testRoutingTableDescription),
70-
NonSystemRoutes: testNonSystemRoutes,
71-
NonDynamicRoutes: testNonDynamicRoutes,
72-
Labels: utils.Ptr(*testLabels),
66+
OrganizationId: testOrgId,
67+
NetworkAreaId: testNetworkAreaId,
68+
Name: testRoutingTableName,
69+
Description: utils.Ptr(testRoutingTableDescription),
70+
SystemRoutes: testSystemRoutesFlag,
71+
DynamicRoutes: testDynamicRoutesFlag,
72+
Labels: utils.Ptr(*testLabels),
7373
}
7474
for _, mod := range mods {
7575
mod(model)
@@ -118,21 +118,21 @@ func TestParseInput(t *testing.T) {
118118
{
119119
description: "dynamic routes disabled",
120120
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
121-
flagValues[nonDynamicRoutesFlag] = "true"
121+
flagValues[dynamicRoutesFlag] = "false"
122122
}),
123123
isValid: true,
124124
expectedModel: fixtureInputModel(func(model *inputModel) {
125-
model.NonDynamicRoutes = true
125+
model.DynamicRoutes = false
126126
}),
127127
},
128128
{
129129
description: "system routes disabled",
130130
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
131-
flagValues[nonSystemRoutesFlag] = "true"
131+
flagValues[systemRoutesFlag] = "false"
132132
}),
133133
isValid: true,
134134
expectedModel: fixtureInputModel(func(model *inputModel) {
135-
model.NonSystemRoutes = true
135+
model.SystemRoutes = false
136136
}),
137137
},
138138
{
@@ -245,7 +245,7 @@ func TestBuildRequest(t *testing.T) {
245245
{
246246
description: "system routes disabled",
247247
model: fixtureInputModel(func(model *inputModel) {
248-
model.NonSystemRoutes = true
248+
model.SystemRoutes = false
249249
}),
250250
expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutingTableToAreaRequest) {
251251
*request = (*request).AddRoutingTableToAreaPayload(
@@ -258,7 +258,7 @@ func TestBuildRequest(t *testing.T) {
258258
{
259259
description: "dynamic routes disabled",
260260
model: fixtureInputModel(func(model *inputModel) {
261-
model.NonDynamicRoutes = true
261+
model.DynamicRoutes = false
262262
}),
263263
expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutingTableToAreaRequest) {
264264
*request = (*request).AddRoutingTableToAreaPayload(

internal/cmd/routingtable/delete/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
const (
1919
networkAreaIdFlag = "network-area-id"
2020
organizationIdFlag = "organization-id"
21-
routingTableIdArg = "ROUTING_TABLE"
21+
routingTableIdArg = "ROUTING_TABLE_ID"
2222
)
2323

2424
type inputModel struct {
@@ -54,7 +54,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5454
}
5555

5656
if !model.AssumeYes {
57-
prompt := fmt.Sprintf("Are you sure you want to delete the routing-table %q for network-area-id %q?", model.RoutingTableId, model.OrganizationId)
57+
prompt := fmt.Sprintf("Are you sure you want to delete the routing-table %q?", model.RoutingTableId)
5858
err = params.Printer.PromptForConfirmation(prompt)
5959
if err != nil {
6060
return err

internal/cmd/routingtable/list/list.go

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1515
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
16-
rmClient "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client"
17-
rmUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/utils"
1816
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
1917
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
2018
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
@@ -77,31 +75,14 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7775
return fmt.Errorf("list routing-tables: %w", err)
7876
}
7977

80-
if items := response.Items; items == nil {
81-
var orgLabel string
82-
rmApiClient, err := rmClient.ConfigureClient(params.Printer, params.CliVersion)
83-
if err == nil {
84-
orgLabel, err = rmUtils.GetOrganizationName(ctx, rmApiClient, model.OrganizationId)
85-
if err != nil {
86-
params.Printer.Debug(print.ErrorLevel, "get organization name: %v", err)
87-
orgLabel = model.OrganizationId
88-
} else if orgLabel == "" {
89-
orgLabel = model.OrganizationId
90-
}
91-
} else {
92-
params.Printer.Debug(print.ErrorLevel, "configure resource manager client: %v", err)
93-
}
94-
params.Printer.Outputf("No routing-tables found for organization %q\n", orgLabel)
95-
return nil
96-
}
78+
routingTables := utils.GetSliceFromPointer(response.Items)
9779

9880
// Truncate output
99-
items := response.GetItems()
100-
if model.Limit != nil && len(items) > int(*model.Limit) {
101-
items = items[:*model.Limit]
81+
if model.Limit != nil && len(routingTables) > int(*model.Limit) {
82+
routingTables = routingTables[:*model.Limit]
10283
}
10384

104-
return outputResult(params.Printer, model.OutputFormat, items)
85+
return outputResult(params.Printer, model.OutputFormat, routingTables, model.OrganizationId)
10586
},
10687
}
10788

@@ -150,12 +131,17 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
150131

151132
return request
152133
}
153-
func outputResult(p *print.Printer, outputFormat string, routingTables []iaas.RoutingTable) error {
134+
func outputResult(p *print.Printer, outputFormat string, routingTables []iaas.RoutingTable, orgId string) error {
154135
if routingTables == nil {
155136
return fmt.Errorf("list routing-table items are nil")
156137
}
157138

158139
return p.OutputResult(outputFormat, routingTables, func() error {
140+
if len(routingTables) == 0 {
141+
p.Outputf("No routing-tables found for organization %q\n", orgId)
142+
return nil
143+
}
144+
159145
table := tables.NewTable()
160146
table.SetHeader("ID", "NAME", "DESCRIPTION", "DEFAULT", "LABELS", "SYSTEM ROUTES", "DYNAMIC ROUTES", "CREATED AT", "UPDATED AT")
161147
for _, routingTable := range routingTables {

internal/cmd/routingtable/list/list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func TestOutputResult(t *testing.T) {
220220
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
221221
for _, tt := range tests {
222222
t.Run(tt.name, func(t *testing.T) {
223-
if err := outputResult(p, tt.outputFormat, tt.routingTable); (err != nil) != tt.wantErr {
223+
if err := outputResult(p, tt.outputFormat, tt.routingTable, "dummy-org-id"); (err != nil) != tt.wantErr {
224224
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
225225
}
226226
})

internal/cmd/routingtable/route/create/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8282

8383
if !model.AssumeYes {
8484
prompt := fmt.Sprintf("Are you sure you want to create a route for routing-table with id %q?", model.RoutingTableId)
85-
if err := params.Printer.PromptForConfirmation(prompt); err != nil {
85+
err = params.Printer.PromptForConfirmation(prompt)
86+
if err != nil {
8687
return err
8788
}
8889
}

0 commit comments

Comments
 (0)