github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/v6/set_org_default_isolation_segment_command.go (about) 1 package v6 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/sharedaction" 5 "code.cloudfoundry.org/cli/actor/v2action" 6 "code.cloudfoundry.org/cli/actor/v3action" 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 . SetOrgDefaultIsolationSegmentActor 13 14 type SetOrgDefaultIsolationSegmentActor interface { 15 GetIsolationSegmentByName(isoSegName string) (v3action.IsolationSegment, v3action.Warnings, error) 16 SetOrganizationDefaultIsolationSegment(orgGUID string, isoSegGUID string) (v3action.Warnings, error) 17 } 18 19 //go:generate counterfeiter . SetOrgDefaultIsolationSegmentActorV2 20 21 type SetOrgDefaultIsolationSegmentActorV2 interface { 22 GetOrganizationByName(orgName string) (v2action.Organization, v2action.Warnings, error) 23 } 24 25 type SetOrgDefaultIsolationSegmentCommand struct { 26 RequiredArgs flag.OrgIsolationArgs `positional-args:"yes"` 27 usage interface{} `usage:"CF_NAME set-org-default-isolation-segment ORG_NAME SEGMENT_NAME"` 28 relatedCommands interface{} `related_commands:"org, set-space-isolation-segment"` 29 30 UI command.UI 31 Config command.Config 32 SharedActor command.SharedActor 33 Actor SetOrgDefaultIsolationSegmentActor 34 ActorV2 SetOrgDefaultIsolationSegmentActorV2 35 } 36 37 func (cmd *SetOrgDefaultIsolationSegmentCommand) Setup(config command.Config, ui command.UI) error { 38 cmd.UI = ui 39 cmd.Config = config 40 cmd.SharedActor = sharedaction.NewActor(config) 41 42 client, _, err := shared.NewV3BasedClients(config, ui, true) 43 if err != nil { 44 return err 45 } 46 cmd.Actor = v3action.NewActor(client, config, nil, nil) 47 48 ccClientV2, uaaClientV2, err := shared.GetNewClientsAndConnectToCF(config, ui) 49 if err != nil { 50 return err 51 } 52 cmd.ActorV2 = v2action.NewActor(ccClientV2, uaaClientV2, config) 53 54 return nil 55 } 56 57 func (cmd SetOrgDefaultIsolationSegmentCommand) Execute(args []string) error { 58 err := cmd.SharedActor.CheckTarget(false, false) 59 if err != nil { 60 return err 61 } 62 63 user, err := cmd.Config.CurrentUser() 64 if err != nil { 65 return err 66 } 67 68 cmd.UI.DisplayTextWithFlavor("Setting isolation segment {{.IsolationSegmentName}} to default on org {{.OrgName}} as {{.CurrentUser}}...", map[string]interface{}{ 69 "IsolationSegmentName": cmd.RequiredArgs.IsolationSegmentName, 70 "OrgName": cmd.RequiredArgs.OrganizationName, 71 "CurrentUser": user.Name, 72 }) 73 74 org, v2Warnings, err := cmd.ActorV2.GetOrganizationByName(cmd.RequiredArgs.OrganizationName) 75 cmd.UI.DisplayWarnings(v2Warnings) 76 if err != nil { 77 return err 78 } 79 80 isoSeg, v3Warnings, err := cmd.Actor.GetIsolationSegmentByName(cmd.RequiredArgs.IsolationSegmentName) 81 cmd.UI.DisplayWarnings(v3Warnings) 82 if err != nil { 83 return err 84 } 85 86 v3Warnings, err = cmd.Actor.SetOrganizationDefaultIsolationSegment(org.GUID, isoSeg.GUID) 87 cmd.UI.DisplayWarnings(v3Warnings) 88 if err != nil { 89 return err 90 } 91 92 cmd.UI.DisplayOK() 93 cmd.UI.DisplayText("In order to move running applications to this isolation segment, they must be restarted.") 94 95 return nil 96 }