forked from cloudfoundry/cli
/
bind_staging_security_group_command.go
44 lines (34 loc) · 1.7 KB
/
bind_staging_security_group_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
package v7
import (
"github.com/LukasHeimann/cloudfoundrycli/v8/api/cloudcontroller/ccv3/constant"
"github.com/LukasHeimann/cloudfoundrycli/v8/command/flag"
)
type BindStagingSecurityGroupCommand struct {
BaseCommand
SecurityGroup flag.SecurityGroup `positional-args:"yes"`
usage interface{} `usage:"CF_NAME bind-staging-security-group SECURITY_GROUP\n\nTIP: If Dynamic ASG's are enabled, changes will automatically apply for running and staging applications. Otherwise, changes will require an app restart (for running) or restage (for staging) to apply to existing applications."`
relatedCommands interface{} `related_commands:"apps, bind-running-security-group, bind-security-group, restart, security-groups, staging-security-groups"`
}
func (cmd BindStagingSecurityGroupCommand) Execute(args []string) error {
var err error
err = cmd.SharedActor.CheckTarget(false, false)
if err != nil {
return err
}
user, err := cmd.Actor.GetCurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor("Binding security group {{.security_group}} to staging as {{.username}}...", map[string]interface{}{
"security_group": cmd.SecurityGroup.SecurityGroup,
"username": user.Name,
})
warnings, err := cmd.Actor.UpdateSecurityGroupGloballyEnabled(cmd.SecurityGroup.SecurityGroup, constant.SecurityGroupLifecycleStaging, true)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
cmd.UI.DisplayOK()
cmd.UI.DisplayText("TIP: If Dynamic ASG's are enabled, changes will automatically apply for running and staging applications. Otherwise, changes will require an app restart (for running) or restage (for staging) to apply to existing applications.")
return nil
}