-
Notifications
You must be signed in to change notification settings - Fork 18
/
firewall_show.go
55 lines (45 loc) · 1.08 KB
/
firewall_show.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
44
45
46
47
48
49
50
51
52
53
54
55
package cmd
import (
"errors"
"os"
"github.com/exoscale/cli/table"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
func init() {
firewallCmd.AddCommand(firewallShow)
}
var firewallShow = &cobra.Command{
Use: "show <security group name | id>",
Short: "Show a security group rules details",
Aliases: gListAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("show expects one security group by name or id")
}
t := table.NewTable(os.Stdout)
err := firewallListRules(t, args[0])
if err == nil {
t.Render()
}
return err
},
}
func firewallListRules(t *table.Table, name string) error {
sg, err := getSecurityGroupByNameOrID(name)
if err != nil {
return err
}
t.SetHeader([]string{"Type", "Source", "Protocol", "Port", "Description", "ID"})
heading := "INGRESS"
for _, in := range sg.IngressRule {
t.Append(formatRules(heading, in))
heading = ""
}
heading = "EGRESS"
for _, out := range sg.EgressRule {
t.Append(formatRules(heading, (egoscale.IngressRule)(out)))
heading = ""
}
return nil
}