github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/command/v6/reset_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 . ResetOrgDefaultIsolationSegmentActor
    13  
    14  type ResetOrgDefaultIsolationSegmentActor interface {
    15  	ResetOrganizationDefaultIsolationSegment(orgGUID string) (v3action.Warnings, error)
    16  }
    17  
    18  //go:generate counterfeiter . ResetOrgDefaultIsolationSegmentActorV2
    19  
    20  type ResetOrgDefaultIsolationSegmentActorV2 interface {
    21  	GetOrganizationByName(orgName string) (v2action.Organization, v2action.Warnings, error)
    22  }
    23  
    24  type ResetOrgDefaultIsolationSegmentCommand struct {
    25  	RequiredArgs    flag.ResetOrgDefaultIsolationArgs `positional-args:"yes"`
    26  	usage           interface{}                       `usage:"CF_NAME reset-org-default-isolation-segment ORG_NAME"`
    27  	relatedCommands interface{}                       `related_commands:"org, restart"`
    28  
    29  	UI          command.UI
    30  	Config      command.Config
    31  	SharedActor command.SharedActor
    32  	Actor       ResetOrgDefaultIsolationSegmentActor
    33  	ActorV2     ResetOrgDefaultIsolationSegmentActorV2
    34  }
    35  
    36  func (cmd *ResetOrgDefaultIsolationSegmentCommand) Setup(config command.Config, ui command.UI) error {
    37  	cmd.UI = ui
    38  	cmd.Config = config
    39  	cmd.SharedActor = sharedaction.NewActor(config)
    40  
    41  	client, _, err := shared.NewV3BasedClients(config, ui, true)
    42  	if err != nil {
    43  		return err
    44  	}
    45  	cmd.Actor = v3action.NewActor(client, config, nil, nil)
    46  
    47  	ccClientV2, uaaClientV2, err := shared.GetNewClientsAndConnectToCF(config, ui)
    48  	if err != nil {
    49  		return err
    50  	}
    51  	cmd.ActorV2 = v2action.NewActor(ccClientV2, uaaClientV2, config)
    52  
    53  	return nil
    54  }
    55  
    56  func (cmd ResetOrgDefaultIsolationSegmentCommand) Execute(args []string) error {
    57  	err := cmd.SharedActor.CheckTarget(true, false)
    58  	if err != nil {
    59  		return err
    60  	}
    61  
    62  	user, err := cmd.Config.CurrentUser()
    63  	if err != nil {
    64  		return err
    65  	}
    66  
    67  	cmd.UI.DisplayTextWithFlavor("Resetting default isolation segment of org {{.OrgName}} as {{.CurrentUser}}...", map[string]interface{}{
    68  		"OrgName":     cmd.RequiredArgs.OrgName,
    69  		"CurrentUser": user.Name,
    70  	})
    71  
    72  	organization, v2Warnings, err := cmd.ActorV2.GetOrganizationByName(cmd.RequiredArgs.OrgName)
    73  	cmd.UI.DisplayWarnings(v2Warnings)
    74  	if err != nil {
    75  		return err
    76  	}
    77  
    78  	warnings, err := cmd.Actor.ResetOrganizationDefaultIsolationSegment(organization.GUID)
    79  	cmd.UI.DisplayWarnings(warnings)
    80  	if err != nil {
    81  		return err
    82  	}
    83  
    84  	cmd.UI.DisplayOK()
    85  	cmd.UI.DisplayText("Applications in spaces of this org that have no isolation segment assigned will be placed in the platform default isolation segment.")
    86  	cmd.UI.DisplayText("Running applications need a restart to be moved there.")
    87  
    88  	return nil
    89  }