-
Notifications
You must be signed in to change notification settings - Fork 5
/
firewall.go
43 lines (34 loc) · 1.14 KB
/
firewall.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package tableprinters
import (
"strings"
"time"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/pointer"
)
func (t *TablePrinter) FirewallTable(data []*models.V1FirewallResponse, wide bool) ([]string, [][]string, error) {
var (
header = []string{"ID", "Age", "Hostname", "Project", "Networks", "IPs", "Partition"}
rows [][]string
)
for _, firewall := range data {
partition := pointer.SafeDeref(pointer.SafeDeref(firewall.Partition).ID)
alloc := pointer.SafeDeref(firewall.Allocation)
project := pointer.SafeDeref(alloc.Project)
hostname := pointer.SafeDeref(alloc.Hostname)
var nwIPs []string
var nws []string
for _, nw := range alloc.Networks {
nwIPs = append(nwIPs, nw.Ips...)
nws = append(nws, *nw.Networkid)
}
ips := strings.Join(nwIPs, "\n")
networks := strings.Join(nws, "\n")
firewallID := *firewall.ID
age := ""
if alloc.Created != nil && !time.Time(*alloc.Created).IsZero() {
age = humanizeDuration(time.Since(time.Time(*alloc.Created)))
}
rows = append(rows, []string{firewallID, age, hostname, project, networks, ips, partition})
}
return header, rows, nil
}