github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/v7/unbind_security_group.go (about) 1 package v7 2 3 import ( 4 "github.com/LukasHeimann/cloudfoundrycli/v8/actor/actionerror" 5 "github.com/LukasHeimann/cloudfoundrycli/v8/actor/v7action" 6 "github.com/LukasHeimann/cloudfoundrycli/v8/api/cloudcontroller/ccv3/constant" 7 "github.com/LukasHeimann/cloudfoundrycli/v8/command/flag" 8 ) 9 10 type UnbindSecurityGroupCommand struct { 11 BaseCommand 12 13 RequiredArgs flag.UnbindSecurityGroupV7Args `positional-args:"yes"` 14 Lifecycle flag.SecurityGroupLifecycle `long:"lifecycle" choice:"running" choice:"staging" default:"running" description:"Lifecycle phase the group applies to"` 15 usage interface{} `usage:"CF_NAME unbind-security-group SECURITY_GROUP ORG SPACE [--lifecycle (running | staging)]\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."` 16 relatedCommands interface{} `related_commands:"apps, restart, security-groups"` 17 } 18 19 func (cmd UnbindSecurityGroupCommand) Execute(args []string) error { 20 var ( 21 err error 22 warnings v7action.Warnings 23 orgName string 24 spaceName string 25 ) 26 27 err = cmd.SharedActor.CheckTarget(false, false) 28 if err != nil { 29 return err 30 } 31 32 user, err := cmd.Actor.GetCurrentUser() 33 if err != nil { 34 return err 35 } 36 37 orgName = cmd.RequiredArgs.OrganizationName 38 spaceName = cmd.RequiredArgs.SpaceName 39 40 cmd.UI.DisplayTextWithFlavor("Unbinding {{.Lifecycle}} security group {{.SecurityGroupName}} from org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ 41 "Lifecycle": string(cmd.Lifecycle), 42 "SecurityGroupName": cmd.RequiredArgs.SecurityGroupName, 43 "OrgName": orgName, 44 "SpaceName": spaceName, 45 "Username": user.Name, 46 }) 47 48 warnings, err = cmd.Actor.UnbindSecurityGroup(cmd.RequiredArgs.SecurityGroupName, orgName, spaceName, constant.SecurityGroupLifecycle(cmd.Lifecycle)) 49 cmd.UI.DisplayWarnings(warnings) 50 if err != nil { 51 if _, isNotBoundError := err.(actionerror.SecurityGroupNotBoundToSpaceError); isNotBoundError { 52 cmd.UI.DisplayWarning(err.Error()) 53 54 cmd.UI.DisplayOK() 55 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.") 56 return nil 57 } 58 59 return err 60 } 61 62 cmd.UI.DisplayOK() 63 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.") 64 65 return nil 66 }