-
Notifications
You must be signed in to change notification settings - Fork 927
/
security_groups_command.go
69 lines (58 loc) · 1.81 KB
/
security_groups_command.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package v7
import (
"code.cloudfoundry.org/cli/util/ui"
)
type SecurityGroupsCommand struct {
BaseCommand
usage interface{} `usage:"CF_NAME security-groups"`
relatedCommands interface{} `related_commands:"bind-running-security-group, bind-security-group, bind-staging-security-group, security-group"`
}
func (cmd SecurityGroupsCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(false, false)
if err != nil {
return err
}
user, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor("Getting security groups as {{.Username}}...", map[string]interface{}{
"Username": user.Name,
})
cmd.UI.DisplayNewline()
securityGroupSummaries, warnings, err := cmd.Actor.GetSecurityGroups()
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
if len(securityGroupSummaries) == 0 {
cmd.UI.DisplayText("No security groups found.")
return nil
}
table := [][]string{{
cmd.UI.TranslateText("name"),
cmd.UI.TranslateText("organization"),
cmd.UI.TranslateText("space"),
cmd.UI.TranslateText("lifecycle"),
}}
for _, securityGroupSummary := range securityGroupSummaries {
if len(securityGroupSummary.SecurityGroupSpaces) == 0 {
table = append(table, []string{
cmd.UI.TranslateText(securityGroupSummary.Name),
cmd.UI.TranslateText(""),
cmd.UI.TranslateText(""),
cmd.UI.TranslateText(""),
})
}
for _, securityGroupSpace := range securityGroupSummary.SecurityGroupSpaces {
table = append(table, []string{
cmd.UI.TranslateText(securityGroupSummary.Name),
cmd.UI.TranslateText(securityGroupSpace.OrgName),
cmd.UI.TranslateText(securityGroupSpace.SpaceName),
cmd.UI.TranslateText(securityGroupSpace.Lifecycle),
})
}
}
cmd.UI.DisplayTableWithHeader("", table, ui.DefaultTableSpacePadding)
return nil
}