github.com/loafoe/cli@v7.1.0+incompatible/command/v7/update_security_group_command.go (about) 1 package v7 2 3 import ( 4 "encoding/json" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 "code.cloudfoundry.org/cli/command/flag" 8 ) 9 10 type UpdateSecurityGroupCommand struct { 11 BaseCommand 12 13 RequiredArgs flag.SecurityGroupArgs `positional-args:"yes"` 14 usage interface{} `usage:"CF_NAME update-security-group SECURITY_GROUP PATH_TO_JSON_RULES_FILE\n\n The provided path can be an absolute or relative path to a file. The file should have\n a single array with JSON objects inside describing the rules. The JSON Base Object is\n omitted and only the square brackets and associated child object are required in the file.\n\n Valid json file example:\n [\n {\n \"protocol\": \"tcp\",\n \"destination\": \"10.0.11.0/24\",\n \"ports\": \"80,443\",\n \"description\": \"Allow http and https traffic from ZoneA\"\n }\n ]\n\nTIP: Changes require an app restart (for running) or restage (for staging) to apply to existing applications."` 15 relatedCommands interface{} `related_commands:"restage, security-groups"` 16 } 17 18 func (cmd UpdateSecurityGroupCommand) Execute(args []string) error { 19 err := cmd.SharedActor.CheckTarget(false, false) 20 if err != nil { 21 return err 22 } 23 24 user, err := cmd.Config.CurrentUser() 25 if err != nil { 26 return err 27 } 28 29 cmd.UI.DisplayTextWithFlavor("Updating security group {{.Name}} as {{.Username}}...", map[string]interface{}{ 30 "Name": cmd.RequiredArgs.SecurityGroup, 31 "Username": user.Name, 32 }) 33 cmd.UI.DisplayNewline() 34 35 warnings, err := cmd.Actor.UpdateSecurityGroup(cmd.RequiredArgs.SecurityGroup, string(cmd.RequiredArgs.PathToJSONRules)) 36 cmd.UI.DisplayWarnings(warnings) 37 if _, ok := err.(*json.SyntaxError); ok { 38 return actionerror.SecurityGroupJsonSyntaxError{Path: string(cmd.RequiredArgs.PathToJSONRules)} 39 } 40 41 if err != nil { 42 return err 43 } 44 45 cmd.UI.DisplayOK() 46 cmd.UI.DisplayNewline() 47 cmd.UI.DisplayText("TIP: Changes require an app restart (for running) or restage (for staging) to apply to existing applications.") 48 return nil 49 }