forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unbind_staging_security_group_command.go
51 lines (40 loc) · 1.63 KB
/
unbind_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
45
46
47
48
49
50
51
package v7
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/command/flag"
)
type UnbindStagingSecurityGroupCommand struct {
BaseCommand
RequiredArgs flag.SecurityGroup `positional-args:"yes"`
usage interface{} `usage:"CF_NAME unbind-staging-security-group SECURITY_GROUP\n\nTIP: Changes require an app restart (for running) or restage (for staging) to apply to existing applications."`
relatedCommands interface{} `related_commands:"apps, restart, security-groups, staging-security-groups"`
}
func (cmd UnbindStagingSecurityGroupCommand) Execute(args []string) error {
var err 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("Unbinding security group {{.security_group}} from defaults for staging as {{.username}}...", map[string]interface{}{
"security_group": cmd.RequiredArgs.SecurityGroup,
"username": user.Name,
})
warnings, err := cmd.Actor.UpdateSecurityGroupGloballyEnabled(cmd.RequiredArgs.SecurityGroup, constant.SecurityGroupLifecycleStaging, false)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
if _, isGroupNotFoundError := err.(actionerror.SecurityGroupNotFoundError); isGroupNotFoundError {
cmd.UI.DisplayWarning(err.Error())
cmd.UI.DisplayOK()
return nil
}
return err
}
cmd.UI.DisplayOK()
cmd.UI.DisplayText("TIP: Changes require an app restart (for running) or restage (for staging) to apply to existing applications.")
return nil
}