Skip to content

Commit

Permalink
fix(network): show full API response in marshaled outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta committed Oct 17, 2023
1 parent 104f8bc commit 2f225cc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Breaking**: `storage list` and `storage show` JSON and YAML outputs to return full API response. This changes `servers` field to contain `server` field, which in turn contains the servers. `labels` field will not be outputted if empty.
- **Breaking**: `server list` and `server show` JSON and YAML outputs to return full API response. This changes field `host_id` to `host`. `nics` is replaced with `networking` subfield `interfaces`. `storage` is replaced with `storage_devices`. `labels` contain subfield `label` which in turn contains the labels.
- **Breaking**: `server firewall show` JSON and YAML outputs to return full API response. This removes fields `destination` and `source` fields in favor of `[destination|source]_address_start`, `[destination|source]_address_end`, `[destination|source]_port_start` and `[destination|source]_port_end`
- **Breaking**: In JSON and YAML output of `network list` and `network show`: display full API response. Servers list will only contain server UUID and name. `ip_networks` contains subfield `ip_network` which in turn contains the labels.
- In human readable output of `kubernetes show` command, show node-groups as table. Node-group details are available with `kubernetes nodegroup show` command.

## Removed
Expand Down
20 changes: 12 additions & 8 deletions internal/commands/network/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,18 @@ func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
n.Zone,
})
}
return output.Table{
Columns: []output.TableColumn{
{Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours},
{Key: "name", Header: "Name"},
{Key: "router", Header: "Router", Colour: ui.DefaultUUUIDColours},
{Key: "type", Header: "Type"},
{Key: "zone", Header: "Zone"},

return output.MarshaledWithHumanOutput{
Value: filtered,
Output: output.Table{
Columns: []output.TableColumn{
{Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours},
{Key: "name", Header: "Name"},
{Key: "router", Header: "Router", Colour: ui.DefaultUUUIDColours},
{Key: "type", Header: "Type"},
{Key: "zone", Header: "Zone"},
},
Rows: rows,
},
Rows: rows,
}, nil
}
25 changes: 14 additions & 11 deletions internal/commands/network/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,31 @@ func TestListCommand(t *testing.T) {
res, err := c.(commands.NoArgumentCommand).ExecuteWithoutArguments(commands.NewExecutor(cfg, &mService, flume.New("test")))

assert.Nil(t, err)
assert.Equal(t, createTable(test.expected), res)
assert.Equal(t, createOutput(test.expected), res)
})
}
}

func createTable(networks []upcloud.Network) output.Table {
func createOutput(networks []upcloud.Network) output.MarshaledWithHumanOutput {
rows := []output.TableRow{}
for _, network := range networks {
rows = append(rows,
output.TableRow{network.UUID, network.Name, network.Router, network.Type, network.Zone},
)
}

return output.Table{
HideHeader: false,
Columns: []output.TableColumn{
{Header: "UUID", Key: "uuid", Hidden: false, Colour: ui.DefaultUUUIDColours},
{Header: "Name", Key: "name", Hidden: false},
{Header: "Router", Key: "router", Hidden: false, Colour: ui.DefaultUUUIDColours},
{Header: "Type", Key: "type", Hidden: false},
{Header: "Zone", Key: "zone", Hidden: false},
return output.MarshaledWithHumanOutput{
Value: networks,
Output: output.Table{
HideHeader: false,
Columns: []output.TableColumn{
{Header: "UUID", Key: "uuid", Hidden: false, Colour: ui.DefaultUUUIDColours},
{Header: "Name", Key: "name", Hidden: false},
{Header: "Router", Key: "router", Hidden: false, Colour: ui.DefaultUUUIDColours},
{Header: "Type", Key: "type", Hidden: false},
{Header: "Zone", Key: "zone", Hidden: false},
},
Rows: rows,
},
Rows: rows,
}
}
5 changes: 4 additions & 1 deletion internal/commands/network/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
})
}

return combined, nil
return output.MarshaledWithHumanOutput{
Value: network,
Output: combined,
}, nil
}

func formatShowDHCPDNS(val interface{}) (text.Colors, string, error) {
Expand Down

0 comments on commit 2f225cc

Please sign in to comment.