forked from cloudfoundry/cli
/
update_security_group_command.go
49 lines (39 loc) · 2 KB
/
update_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
package v7
import (
"encoding/json"
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/command/flag"
)
type UpdateSecurityGroupCommand struct {
BaseCommand
RequiredArgs flag.SecurityGroupArgs `positional-args:"yes"`
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."`
relatedCommands interface{} `related_commands:"restage, security-groups"`
}
func (cmd UpdateSecurityGroupCommand) Execute(args []string) 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("Updating security group {{.Name}} as {{.Username}}...", map[string]interface{}{
"Name": cmd.RequiredArgs.SecurityGroup,
"Username": user.Name,
})
cmd.UI.DisplayNewline()
warnings, err := cmd.Actor.UpdateSecurityGroup(cmd.RequiredArgs.SecurityGroup, string(cmd.RequiredArgs.PathToJSONRules))
cmd.UI.DisplayWarnings(warnings)
if _, ok := err.(*json.SyntaxError); ok {
return actionerror.SecurityGroupJsonSyntaxError{Path: string(cmd.RequiredArgs.PathToJSONRules)}
}
if err != nil {
return err
}
cmd.UI.DisplayOK()
cmd.UI.DisplayNewline()
cmd.UI.DisplayText("TIP: Changes require an app restart (for running) or restage (for staging) to apply to existing applications.")
return nil
}