github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/command/v3/disable_org_isolation_command.go (about) 1 package v3 2 3 import ( 4 "net/http" 5 6 "code.cloudfoundry.org/cli/actor/sharedaction" 7 "code.cloudfoundry.org/cli/actor/v3action" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 10 "code.cloudfoundry.org/cli/command" 11 "code.cloudfoundry.org/cli/command/flag" 12 "code.cloudfoundry.org/cli/command/translatableerror" 13 "code.cloudfoundry.org/cli/command/v3/shared" 14 ) 15 16 //go:generate counterfeiter . DisableOrgIsolationActor 17 18 type DisableOrgIsolationActor interface { 19 CloudControllerAPIVersion() string 20 RevokeIsolationSegmentFromOrganizationByName(isolationSegmentName string, orgName string) (v3action.Warnings, error) 21 } 22 type DisableOrgIsolationCommand struct { 23 RequiredArgs flag.OrgIsolationArgs `positional-args:"yes"` 24 usage interface{} `usage:"CF_NAME disable-org-isolation ORG_NAME SEGMENT_NAME"` 25 relatedCommands interface{} `related_commands:"enable-org-isolation, isolation-segments"` 26 27 UI command.UI 28 Config command.Config 29 SharedActor command.SharedActor 30 Actor DisableOrgIsolationActor 31 } 32 33 func (cmd *DisableOrgIsolationCommand) Setup(config command.Config, ui command.UI) error { 34 cmd.UI = ui 35 cmd.Config = config 36 cmd.SharedActor = sharedaction.NewActor(config) 37 38 client, _, err := shared.NewClients(config, ui, true) 39 if err != nil { 40 if v3Err, ok := err.(ccerror.V3UnexpectedResponseError); ok && v3Err.ResponseCode == http.StatusNotFound { 41 return translatableerror.MinimumAPIVersionNotMetError{MinimumVersion: ccversion.MinVersionIsolationSegmentV3} 42 } 43 44 return err 45 } 46 cmd.Actor = v3action.NewActor(nil, client, config) 47 48 return nil 49 } 50 51 func (cmd DisableOrgIsolationCommand) Execute(args []string) error { 52 err := command.MinimumAPIVersionCheck(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionIsolationSegmentV3) 53 if err != nil { 54 return err 55 } 56 57 err = cmd.SharedActor.CheckTarget(cmd.Config, false, false) 58 if err != nil { 59 return shared.HandleError(err) 60 } 61 user, err := cmd.Config.CurrentUser() 62 if err != nil { 63 return err 64 } 65 66 cmd.UI.DisplayTextWithFlavor("Removing entitlement to isolation segment {{.SegmentName}} from org {{.OrgName}} as {{.CurrentUser}}...", map[string]interface{}{ 67 "SegmentName": cmd.RequiredArgs.IsolationSegmentName, 68 "OrgName": cmd.RequiredArgs.OrganizationName, 69 "CurrentUser": user.Name, 70 }) 71 72 warnings, err := cmd.Actor.RevokeIsolationSegmentFromOrganizationByName(cmd.RequiredArgs.IsolationSegmentName, cmd.RequiredArgs.OrganizationName) 73 74 cmd.UI.DisplayWarnings(warnings) 75 76 if err != nil { 77 return shared.HandleError(err) 78 } 79 80 cmd.UI.DisplayOK() 81 82 return nil 83 }