Skip to content

Commit 208163f

Browse files
committed
review changes 3
1 parent 49d4669 commit 208163f

33 files changed

+979
-810
lines changed

docs/stackit_routing-table_create.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ stackit routing-table create [flags]
1919
Create a routing-table with name `rt` and description `some description`
2020
stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --description "some description"
2121
22-
Create a routing-table with name `rt` with system_routes disabled
22+
Create a routing-table with name `rt` with system routes disabled
2323
stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-system-routes
2424
25-
Create a routing-table with name `rt` with dynamic_routes disabled
25+
Create a routing-table with name `rt` with dynamic routes disabled
2626
stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-dynamic-routes
2727
```
2828

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_ARG [flags]
10+
stackit routing-table delete ROUTING_TABLE [flags]
1111
```
1212

1313
### Examples

docs/stackit_routing-table_describe.md

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

99
```
10-
stackit routing-table describe ROUTING_TABLE_ID_ARG [flags]
10+
stackit routing-table describe ROUTING_TABLE_ID [flags]
1111
```
1212

1313
### Examples

docs/stackit_routing-table_route_describe.md

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

99
```
10-
stackit routing-table route describe ROUTE_ID_ARG [flags]
10+
stackit routing-table route describe ROUTE_ID [flags]
1111
```
1212

1313
### Examples

docs/stackit_routing-table_route_update.md

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

99
```
10-
stackit routing-table route update ROUTE_ID_ARG [flags]
10+
stackit routing-table route update ROUTE_ID [flags]
1111
```
1212

1313
### Examples

docs/stackit_routing-table_update.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Updates a routing-table
77
Updates a routing-table.
88

99
```
10-
stackit routing-table update ROUTE_TABLE_ID_ARG [flags]
10+
stackit routing-table update ROUTE_TABLE_ID [flags]
1111
```
1212

1313
### Examples
@@ -22,7 +22,7 @@ stackit routing-table update ROUTE_TABLE_ID_ARG [flags]
2222
Updates the description of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"
2323
$ stackit routing-table update xxx --description foo --organization-id yyy --network-area-id zzz
2424
25-
Disables the dynamic_routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"
25+
Disables the dynamic routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"
2626
$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --non-dynamic-routes
2727
```
2828

internal/cmd/network/create/create.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
298298
}
299299

300300
payload := iaas.CreateNetworkPayload{
301-
Name: model.Name,
302-
Labels: utils.ConvertStringMapToInterfaceMap(model.Labels),
303-
Routed: utils.Ptr(!model.NonRouted),
304-
Ipv4: ipv4Network,
305-
Ipv6: ipv6Network,
301+
Name: model.Name,
302+
Labels: utils.ConvertStringMapToInterfaceMap(model.Labels),
303+
Routed: utils.Ptr(!model.NonRouted),
304+
Ipv4: ipv4Network,
305+
Ipv6: ipv6Network,
306306
RoutingTableId: model.RoutingTableID,
307307
}
308308

internal/cmd/network/describe/describe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func outputResult(p *print.Printer, outputFormat string, network *iaas.Network)
152152
table.AddSeparator()
153153

154154
if network.RoutingTableId != nil {
155-
table.AddRow("ROUTING-TABLE ID", utils.PtrString(network.RoutingTableId))
155+
table.AddRow("ROUTING TABLE ID", utils.PtrString(network.RoutingTableId))
156156
table.AddSeparator()
157157
}
158158

internal/cmd/routingtable/create/create.go

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ import (
44
"context"
55
"fmt"
66
"strings"
7-
"time"
87

98
"github.com/spf13/cobra"
10-
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
119
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1210
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
1311
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1412
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1513
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1614
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
1715
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1817
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1918
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
2019
)
@@ -40,7 +39,7 @@ type inputModel struct {
4039
OrganizationId string
4140
}
4241

43-
func NewCmd(params *params.CmdParams) *cobra.Command {
42+
func NewCmd(params *types.CmdParams) *cobra.Command {
4443
cmd := &cobra.Command{
4544
Use: "create",
4645
Short: "Creates a routing-table",
@@ -56,11 +55,11 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
5655
`stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --description "some description"`,
5756
),
5857
examples.NewExample(
59-
"Create a routing-table with name `rt` with system_routes disabled",
58+
"Create a routing-table with name `rt` with system routes disabled",
6059
`stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-system-routes`,
6160
),
6261
examples.NewExample(
63-
"Create a routing-table with name `rt` with dynamic_routes disabled",
62+
"Create a routing-table with name `rt` with dynamic routes disabled",
6463
`stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-dynamic-routes`,
6564
),
6665
),
@@ -132,15 +131,8 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
132131
}
133132

134133
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) (iaas.ApiAddRoutingTableToAreaRequest, error) {
135-
systemRoutes := true
136-
if model.NonSystemRoutes {
137-
systemRoutes = false
138-
}
139-
140-
dynamicRoutes := true
141-
if model.NonDynamicRoutes {
142-
dynamicRoutes = false
143-
}
134+
systemRoutes := !model.NonSystemRoutes
135+
dynamicRoutes := !model.NonDynamicRoutes
144136

145137
payload := iaas.AddRoutingTableToAreaPayload{
146138
Description: model.Description,
@@ -175,28 +167,18 @@ func outputResult(p *print.Printer, outputFormat string, routingTable *iaas.Rout
175167
}
176168
}
177169

178-
createdAt := ""
179-
if routingTable.CreatedAt != nil {
180-
createdAt = routingTable.CreatedAt.Format(time.RFC3339)
181-
}
182-
183-
updatedAt := ""
184-
if routingTable.UpdatedAt != nil {
185-
updatedAt = routingTable.UpdatedAt.Format(time.RFC3339)
186-
}
187-
188170
table := tables.NewTable()
189-
table.SetHeader("ID", "NAME", "DESCRIPTION", "CREATED_AT", "UPDATED_AT", "DEFAULT", "LABELS", "SYSTEM_ROUTES", "DYNAMIC_ROUTES")
171+
table.SetHeader("ID", "NAME", "DESCRIPTION", "DEFAULT", "LABELS", "SYSTEM ROUTES", "DYNAMIC ROUTES", "CREATED AT", "UPDATED AT")
190172
table.AddRow(
191173
utils.PtrString(routingTable.Id),
192174
utils.PtrString(routingTable.Name),
193175
utils.PtrString(routingTable.Description),
194-
createdAt,
195-
updatedAt,
196176
utils.PtrString(routingTable.Default),
197177
strings.Join(labels, "\n"),
198178
utils.PtrString(routingTable.SystemRoutes),
199179
utils.PtrString(routingTable.DynamicRoutes),
180+
utils.ConvertTimePToDateTimeString(routingTable.CreatedAt),
181+
utils.ConvertTimePToDateTimeString(routingTable.UpdatedAt),
200182
)
201183

202184
err := table.Display(p)

internal/cmd/routingtable/create/create_test.go

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"github.com/google/go-cmp/cmp"
1010
"github.com/google/go-cmp/cmp/cmpopts"
1111
"github.com/google/uuid"
12-
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
1312
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
14-
pprint "github.com/stackitcloud/stackit-cli/internal/pkg/print"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1514
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1616
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1717
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1818
)
@@ -29,8 +29,10 @@ var testNetworkAreaId = uuid.NewString()
2929

3030
const testRoutingTableName = "test"
3131
const testRoutingTableDescription = "test"
32-
const systemRoutesDisabled = true
33-
const dynamicRoutesDisabled = true
32+
33+
const testNonSystemRoutes = false
34+
const testNonDynamicRoutes = false
35+
3436
const testLabelSelectorFlag = "key1=value1,key2=value2"
3537

3638
var testLabels = &map[string]string{
@@ -45,8 +47,8 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
4547
networkAreaIdFlag: testNetworkAreaId,
4648
descriptionFlag: testRoutingTableDescription,
4749
nameFlag: testRoutingTableName,
48-
nonSystemRoutesFlag: strconv.FormatBool(systemRoutesDisabled),
49-
nonDynamicRoutesFlag: strconv.FormatBool(dynamicRoutesDisabled),
50+
nonSystemRoutesFlag: strconv.FormatBool(testNonSystemRoutes),
51+
nonDynamicRoutesFlag: strconv.FormatBool(testNonDynamicRoutes),
5052
labelFlag: testLabelSelectorFlag,
5153
}
5254
for _, mod := range mods {
@@ -65,8 +67,8 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6567
NetworkAreaId: testNetworkAreaId,
6668
Name: testRoutingTableName,
6769
Description: utils.Ptr(testRoutingTableDescription),
68-
NonSystemRoutes: systemRoutesDisabled,
69-
NonDynamicRoutes: dynamicRoutesDisabled,
70+
NonSystemRoutes: testNonSystemRoutes,
71+
NonDynamicRoutes: testNonDynamicRoutes,
7072
Labels: utils.Ptr(*testLabels),
7173
}
7274
for _, mod := range mods {
@@ -85,22 +87,12 @@ func fixtureRequest(mods ...func(request *iaas.ApiAddRoutingTableToAreaRequest))
8587
}
8688

8789
func fixturePayload(mods ...func(payload *iaas.AddRoutingTableToAreaPayload)) iaas.AddRoutingTableToAreaPayload {
88-
systemRoutes := true
89-
if dynamicRoutesDisabled {
90-
systemRoutes = false
91-
}
92-
93-
dynamicRoutes := true
94-
if systemRoutesDisabled {
95-
dynamicRoutes = false
96-
}
97-
9890
payload := iaas.AddRoutingTableToAreaPayload{
9991
Description: utils.Ptr(testRoutingTableDescription),
10092
Name: utils.Ptr(testRoutingTableName),
10193
Labels: utils.ConvertStringMapToInterfaceMap(testLabels),
102-
SystemRoutes: utils.Ptr(systemRoutes),
103-
DynamicRoutes: utils.Ptr(dynamicRoutes),
94+
SystemRoutes: utils.Ptr(true),
95+
DynamicRoutes: utils.Ptr(true),
10496
}
10597

10698
for _, mod := range mods {
@@ -124,7 +116,7 @@ func TestParseInput(t *testing.T) {
124116
expectedModel: fixtureInputModel(),
125117
},
126118
{
127-
description: "dynamic_routes disabled",
119+
description: "dynamic routes disabled",
128120
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
129121
flagValues[nonDynamicRoutesFlag] = "true"
130122
}),
@@ -134,7 +126,7 @@ func TestParseInput(t *testing.T) {
134126
}),
135127
},
136128
{
137-
description: "system_routes disabled",
129+
description: "system routes disabled",
138130
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
139131
flagValues[nonSystemRoutesFlag] = "true"
140132
}),
@@ -243,9 +235,11 @@ func TestBuildRequest(t *testing.T) {
243235
model.Labels = nil
244236
}),
245237
expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutingTableToAreaRequest) {
246-
*request = (*request).AddRoutingTableToAreaPayload(fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
247-
payload.Labels = nil
248-
}))
238+
*request = (*request).AddRoutingTableToAreaPayload(
239+
fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
240+
payload.Labels = nil
241+
}),
242+
)
249243
}),
250244
},
251245
{
@@ -254,9 +248,11 @@ func TestBuildRequest(t *testing.T) {
254248
model.NonSystemRoutes = true
255249
}),
256250
expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutingTableToAreaRequest) {
257-
*request = (*request).AddRoutingTableToAreaPayload(fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
258-
payload.SystemRoutes = utils.Ptr(false)
259-
}))
251+
*request = (*request).AddRoutingTableToAreaPayload(
252+
fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
253+
payload.SystemRoutes = utils.Ptr(false)
254+
}),
255+
)
260256
}),
261257
},
262258
{
@@ -265,9 +261,11 @@ func TestBuildRequest(t *testing.T) {
265261
model.NonDynamicRoutes = true
266262
}),
267263
expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutingTableToAreaRequest) {
268-
*request = (*request).AddRoutingTableToAreaPayload(fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
269-
payload.DynamicRoutes = utils.Ptr(false)
270-
}))
264+
*request = (*request).AddRoutingTableToAreaPayload(
265+
fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
266+
payload.DynamicRoutes = utils.Ptr(false)
267+
}),
268+
)
271269
}),
272270
},
273271
}
@@ -314,32 +312,32 @@ func TestOutputResult(t *testing.T) {
314312
},
315313
{
316314
name: "empty routing-table",
317-
outputFormat: "",
315+
outputFormat: print.PrettyOutputFormat,
318316
routingTable: &iaas.RoutingTable{},
319317
wantErr: true,
320318
},
321319
{
322-
name: "table output routing-table",
323-
outputFormat: "",
320+
name: "pretty output routing-table",
321+
outputFormat: print.PrettyOutputFormat,
324322
routingTable: &dummyRoutingTable,
325323
wantErr: false,
326324
},
327325
{
328326
name: "json output routing-table",
329-
outputFormat: pprint.JSONOutputFormat,
327+
outputFormat: print.JSONOutputFormat,
330328
routingTable: &dummyRoutingTable,
331329
wantErr: false,
332330
},
333331
{
334332
name: "yaml output routing-table",
335-
outputFormat: pprint.YAMLOutputFormat,
333+
outputFormat: print.YAMLOutputFormat,
336334
routingTable: &dummyRoutingTable,
337335
wantErr: false,
338336
},
339337
}
340338

341-
p := pprint.NewPrinter()
342-
p.Cmd = NewCmd(&params.CmdParams{Printer: p})
339+
p := print.NewPrinter()
340+
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
343341
for _, tt := range tests {
344342
t.Run(tt.name, func(t *testing.T) {
345343
if err := outputResult(p, tt.outputFormat, tt.routingTable); (err != nil) != tt.wantErr {

0 commit comments

Comments
 (0)