forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
running_security_groups.go
76 lines (65 loc) · 2.21 KB
/
running_security_groups.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
70
71
72
73
74
75
76
package securitygroup
import (
"code.cloudfoundry.org/cli/cf/api/securitygroups/defaults/running"
"code.cloudfoundry.org/cli/cf/commandregistry"
"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
"code.cloudfoundry.org/cli/cf/flags"
. "code.cloudfoundry.org/cli/cf/i18n"
"code.cloudfoundry.org/cli/cf/requirements"
"code.cloudfoundry.org/cli/cf/terminal"
)
type listRunningSecurityGroups struct {
ui terminal.UI
runningSecurityGroupRepo running.SecurityGroupsRepo
configRepo coreconfig.Reader
}
func init() {
commandregistry.Register(&listRunningSecurityGroups{})
}
func (cmd *listRunningSecurityGroups) MetaData() commandregistry.CommandMetadata {
return commandregistry.CommandMetadata{
Name: "running-security-groups",
Description: T("List security groups in the set of security groups for running applications"),
Usage: []string{
"CF_NAME running-security-groups",
},
}
}
func (cmd *listRunningSecurityGroups) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
usageReq := requirements.NewUsageRequirement(commandregistry.CLICommandUsagePresenter(cmd),
T("No argument required"),
func() bool {
return len(fc.Args()) != 0
},
)
reqs := []requirements.Requirement{
usageReq,
requirementsFactory.NewLoginRequirement(),
}
return reqs, nil
}
func (cmd *listRunningSecurityGroups) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command {
cmd.ui = deps.UI
cmd.configRepo = deps.Config
cmd.runningSecurityGroupRepo = deps.RepoLocator.GetRunningSecurityGroupsRepository()
return cmd
}
func (cmd *listRunningSecurityGroups) Execute(context flags.FlagContext) error {
cmd.ui.Say(T("Acquiring running security groups as '{{.username}}'", map[string]interface{}{
"username": terminal.EntityNameColor(cmd.configRepo.Username()),
}))
defaultSecurityGroupsFields, err := cmd.runningSecurityGroupRepo.List()
if err != nil {
return err
}
cmd.ui.Ok()
cmd.ui.Say("")
if len(defaultSecurityGroupsFields) > 0 {
for _, value := range defaultSecurityGroupsFields {
cmd.ui.Say(value.Name)
}
} else {
cmd.ui.Say(T("No running security groups set"))
}
return nil
}