Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions internal/cmd/server/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ var DescribeCmd = base.DescribeCmd[*hcloud.Server]{
fmt.Fprintf(out, " No Floating IPs\n")
}

fmt.Fprintln(out)
fmt.Fprintf(out, " Firewalls:\n")
if len(server.PublicNet.Firewalls) > 0 {
for _, f := range server.PublicNet.Firewalls {
var err error
fw, _, err := s.Client().Firewall().GetByID(s, f.Firewall.ID)
if err != nil {
return err
}
if fw == nil {
continue
}
fmt.Fprintf(out, " - ID:\t%d\n", fw.ID)
fmt.Fprintf(out, " Name:\t%s\n", fw.Name)
fmt.Fprintf(out, " Status:\t%s\n", f.Status)
}
} else {
fmt.Fprintf(out, " No Firewalls\n")
}

fmt.Fprintln(out)
fmt.Fprintf(out, "Private Net:\n")
if len(server.PrivateNet) > 0 {
Expand Down
19 changes: 18 additions & 1 deletion internal/cmd/server/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,25 @@ func TestDescribe(t *testing.T) {
},
IncludedTraffic: 20 * util.Tebibyte,
Protection: hcloud.ServerProtection{Delete: true, Rebuild: true},
Created: time.Date(2036, 8, 12, 12, 0, 0, 0, time.UTC),
PublicNet: hcloud.ServerPublicNet{
Firewalls: []*hcloud.ServerFirewallStatus{
{
Firewall: hcloud.Firewall{ID: 321},
Status: hcloud.FirewallStatusApplied,
},
},
},
Created: time.Date(2036, 8, 12, 12, 0, 0, 0, time.UTC),
}

fx.Client.ServerClient.EXPECT().
Get(gomock.Any(), "test").
Return(srv, nil, nil)

fx.Client.FirewallClient.EXPECT().
GetByID(gomock.Any(), int64(321)).
Return(&hcloud.Firewall{ID: 321, Name: "test-firewall"}, nil, nil)

out, errOut, err := fx.Run(cmd, []string{"test"})

expOut := fmt.Sprintf(`ID: 123
Expand Down Expand Up @@ -118,6 +130,11 @@ Public Net:
Floating IPs:
No Floating IPs

Firewalls:
- ID: 321
Name: test-firewall
Status: applied

Comment on lines +133 to +137

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also test with some firewall attached?

Private Net:
No Private Networks

Expand Down
Loading