Skip to content

Commit

Permalink
fix(server): show full API response in marshaled outputs (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
villevsv-upcloud authored Oct 16, 2023
1 parent 1b09bb4 commit 104f8bc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- **Breaking**: In JSON and YAML output of `loadbalancer list`: display full API response. This changes `state` field to `operational_state`.
- **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.
- In human readable output of `kubernetes show` command, show node-groups as table. Node-group datails are available with `kubernetes nodegroup show` command.
- **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`
- In human readable output of `kubernetes show` command, show node-groups as table. Node-group details are available with `kubernetes nodegroup show` command.

## Removed
- **Breaking**: Remove `database connection list` and `database connection cancel` commands in favor of `database session` counterparts
Expand Down
42 changes: 23 additions & 19 deletions internal/commands/server/firewall/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,32 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
},
})
}
return output.Combined{
output.CombinedSection{
Key: "rules",
Title: "Firewall rules",
Contents: output.Table{
Columns: []output.TableColumn{
{Key: "index", Header: "#"},
{Key: "action", Header: "Action", Format: actionFormat},
{Key: "source", Header: "Source", Format: addressFormat},
{Key: "destination", Header: "Destination", Format: addressFormat},
{Key: "direction", Header: "Dir"},
{Key: "protocol", Header: "Proto", Format: protoFormat},

return output.MarshaledWithHumanOutput{
Value: rules,
Output: output.Combined{
output.CombinedSection{
Key: "rules",
Title: "Firewall rules",
Contents: output.Table{
Columns: []output.TableColumn{
{Key: "index", Header: "#"},
{Key: "action", Header: "Action", Format: actionFormat},
{Key: "source", Header: "Source", Format: addressFormat},
{Key: "destination", Header: "Destination", Format: addressFormat},
{Key: "direction", Header: "Dir"},
{Key: "protocol", Header: "Proto", Format: protoFormat},
},
Rows: fwRows,
},
Rows: fwRows,
},
},
output.CombinedSection{
Contents: output.Details{Sections: []output.DetailSection{
{Rows: []output.DetailRow{
{Key: "enabled", Title: "Enabled", Value: server.Firewall == "on", Format: format.Boolean},
output.CombinedSection{
Contents: output.Details{Sections: []output.DetailSection{
{Rows: []output.DetailRow{
{Key: "enabled", Title: "Enabled", Value: server.Firewall == "on", Format: format.Boolean},
}},
}},
}},
},
},
}, nil
}
Expand Down
9 changes: 6 additions & 3 deletions internal/commands/server/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ func (ls *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.O
}
}

return output.Table{
Columns: columns,
Rows: rows,
return output.MarshaledWithHumanOutput{
Value: servers,
Output: output.Table{
Columns: columns,
Rows: rows,
},
}, nil
}

Expand Down
5 changes: 4 additions & 1 deletion internal/commands/server/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ func (s *showCommand) Execute(exec commands.Executor, uuid string) (output.Outpu
})
}

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

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

0 comments on commit 104f8bc

Please sign in to comment.