github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/command/v6/enable_org_isolation_command.go (about) 1 package v6 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/sharedaction" 5 "code.cloudfoundry.org/cli/actor/v3action" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 7 "code.cloudfoundry.org/cli/command" 8 "code.cloudfoundry.org/cli/command/flag" 9 "code.cloudfoundry.org/cli/command/v6/shared" 10 ) 11 12 //go:generate counterfeiter . EnableOrgIsolationActor 13 14 type EnableOrgIsolationActor interface { 15 CloudControllerAPIVersion() string 16 EntitleIsolationSegmentToOrganizationByName(isolationSegmentName string, orgName string) (v3action.Warnings, error) 17 } 18 19 type EnableOrgIsolationCommand struct { 20 RequiredArgs flag.OrgIsolationArgs `positional-args:"yes"` 21 usage interface{} `usage:"CF_NAME enable-org-isolation ORG_NAME SEGMENT_NAME"` 22 relatedCommands interface{} `related_commands:"create-isolation-segment, isolation-segments, set-org-default-isolation-segment, set-space-isolation-segment"` 23 24 UI command.UI 25 Config command.Config 26 SharedActor command.SharedActor 27 Actor EnableOrgIsolationActor 28 } 29 30 func (cmd *EnableOrgIsolationCommand) Setup(config command.Config, ui command.UI) error { 31 cmd.UI = ui 32 cmd.Config = config 33 cmd.SharedActor = sharedaction.NewActor(config) 34 35 client, _, err := shared.NewV3BasedClients(config, ui, true, "") 36 if err != nil { 37 return err 38 } 39 cmd.Actor = v3action.NewActor(client, config, nil, nil) 40 41 return nil 42 } 43 44 func (cmd EnableOrgIsolationCommand) Execute(args []string) error { 45 err := command.MinimumCCAPIVersionCheck(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionIsolationSegmentV3) 46 if err != nil { 47 return err 48 } 49 50 err = cmd.SharedActor.CheckTarget(false, false) 51 if err != nil { 52 return err 53 } 54 55 user, err := cmd.Config.CurrentUser() 56 if err != nil { 57 return err 58 } 59 60 cmd.UI.DisplayTextWithFlavor("Enabling isolation segment {{.SegmentName}} for org {{.OrgName}} as {{.CurrentUser}}...", map[string]interface{}{ 61 "SegmentName": cmd.RequiredArgs.IsolationSegmentName, 62 "OrgName": cmd.RequiredArgs.OrganizationName, 63 "CurrentUser": user.Name, 64 }) 65 66 warnings, err := cmd.Actor.EntitleIsolationSegmentToOrganizationByName(cmd.RequiredArgs.IsolationSegmentName, cmd.RequiredArgs.OrganizationName) 67 cmd.UI.DisplayWarnings(warnings) 68 if err != nil { 69 return err 70 } 71 72 cmd.UI.DisplayOK() 73 74 return nil 75 }