Skip to content

Commit

Permalink
add ip type, source and subnet size to firewall rule printer (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
afady authored Feb 4, 2022
1 parent fdf7937 commit 3484f23
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cmd/printer/firewallRule.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
package printer

import (
"fmt"

"github.com/vultr/govultr/v2"
)

func FirewallRules(fwr []govultr.FirewallRule, meta *govultr.Meta) {
col := columns{"RULE NUMBER", "ACTION", "PROTOCOL", "PORT", "NETWORK", "NOTES"}
col := columns{"RULE NUMBER", "ACTION", "TYPE", "PROTOCOL", "PORT", "NETWORK", "SOURCE", "NOTES"}
display(col)
for _, f := range fwr {
display(columns{f.ID, f.Action, f.Protocol, f.Port, f.Subnet, f.Notes})
display(columns{f.ID, f.Action, f.Type, f.Protocol, f.Port, getFirewallNetwork(f.Subnet, f.SubnetSize), getFirewallSource(f.Source), f.Notes})
}

Meta(meta)
flush()
}

func FirewallRule(fwr *govultr.FirewallRule) {
col := columns{"RULE NUMBER", "ACTION", "PROTOCOL", "PORT", "NETWORK", "NOTES"}
col := columns{"RULE NUMBER", "ACTION", "TYPE", "PROTOCOL", "PORT", "NETWORK", "SOURCE", "NOTES"}
display(col)

display(columns{fwr.ID, fwr.Action, fwr.Protocol, fwr.Port, fwr.Subnet, fwr.Notes})
display(columns{fwr.ID, fwr.Action, fwr.Type, fwr.Protocol, fwr.Port, getFirewallNetwork(fwr.Subnet, fwr.SubnetSize), getFirewallSource(fwr.Source), fwr.Notes})
flush()
}

func getFirewallSource(source string) string {
if source == "" {
return "anywhere"
}
return source
}

func getFirewallNetwork(subnet string, size int) string {
return fmt.Sprintf("%s/%d", subnet, size)
}

0 comments on commit 3484f23

Please sign in to comment.