github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/v7/unbind_running_security_group_command.go (about)

     1  package v7
     2  
     3  import (
     4  	"github.com/LukasHeimann/cloudfoundrycli/v8/actor/actionerror"
     5  	"github.com/LukasHeimann/cloudfoundrycli/v8/api/cloudcontroller/ccv3/constant"
     6  	"github.com/LukasHeimann/cloudfoundrycli/v8/command/flag"
     7  )
     8  
     9  type UnbindRunningSecurityGroupCommand struct {
    10  	BaseCommand
    11  
    12  	RequiredArgs    flag.SecurityGroup `positional-args:"yes"`
    13  	usage           interface{}        `usage:"CF_NAME unbind-running-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."`
    14  	relatedCommands interface{}        `related_commands:"apps, restart, running-security-groups, security-groups"`
    15  }
    16  
    17  func (cmd UnbindRunningSecurityGroupCommand) Execute(args []string) error {
    18  	var err error
    19  
    20  	err = cmd.SharedActor.CheckTarget(false, false)
    21  	if err != nil {
    22  		return err
    23  	}
    24  
    25  	user, err := cmd.Actor.GetCurrentUser()
    26  	if err != nil {
    27  		return err
    28  	}
    29  
    30  	cmd.UI.DisplayTextWithFlavor("Unbinding security group {{.security_group}} from defaults for running as {{.username}}...", map[string]interface{}{
    31  		"security_group": cmd.RequiredArgs.SecurityGroup,
    32  		"username":       user.Name,
    33  	})
    34  
    35  	warnings, err := cmd.Actor.UpdateSecurityGroupGloballyEnabled(cmd.RequiredArgs.SecurityGroup, constant.SecurityGroupLifecycleRunning, false)
    36  	cmd.UI.DisplayWarnings(warnings)
    37  	if err != nil {
    38  		if _, isGroupNotFoundError := err.(actionerror.SecurityGroupNotFoundError); isGroupNotFoundError {
    39  			cmd.UI.DisplayWarning(err.Error())
    40  			cmd.UI.DisplayOK()
    41  			return nil
    42  		}
    43  
    44  		return err
    45  	}
    46  
    47  	cmd.UI.DisplayOK()
    48  	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.")
    49  
    50  	return nil
    51  }