github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7action/organization_summary.go (about)

     1  package v7action
     2  
     3  import (
     4  	"sort"
     5  
     6  	"code.cloudfoundry.org/cli/resources"
     7  )
     8  
     9  type OrganizationSummary struct {
    10  	resources.Organization
    11  	DomainNames []string
    12  	QuotaName   string
    13  	SpaceNames  []string
    14  
    15  	// DefaultIsolationSegmentGUID is the unique identifier of the isolation
    16  	// segment this organization is tagged with.
    17  	DefaultIsolationSegmentGUID string
    18  }
    19  
    20  func (actor Actor) GetOrganizationSummaryByName(orgName string) (OrganizationSummary, Warnings, error) {
    21  	var allWarnings Warnings
    22  
    23  	org, warnings, err := actor.GetOrganizationByName(orgName)
    24  	allWarnings = append(allWarnings, warnings...)
    25  	if err != nil {
    26  		return OrganizationSummary{}, allWarnings, err
    27  	}
    28  
    29  	domains, warnings, err := actor.GetOrganizationDomains(org.GUID, "")
    30  	allWarnings = append(allWarnings, warnings...)
    31  	if err != nil {
    32  		return OrganizationSummary{}, allWarnings, err
    33  	}
    34  
    35  	quota, ccv3Warnings, err := actor.CloudControllerClient.GetOrganizationQuota(org.QuotaGUID)
    36  	allWarnings = append(allWarnings, ccv3Warnings...)
    37  	if err != nil {
    38  		return OrganizationSummary{}, allWarnings, err
    39  	}
    40  
    41  	spaces, warnings, err := actor.GetOrganizationSpaces(org.GUID)
    42  	allWarnings = append(allWarnings, warnings...)
    43  	if err != nil {
    44  		return OrganizationSummary{}, allWarnings, err
    45  	}
    46  
    47  	isoSegGUID, warnings, err := actor.GetOrganizationDefaultIsolationSegment(org.GUID)
    48  	allWarnings = append(allWarnings, warnings...)
    49  	if err != nil {
    50  		return OrganizationSummary{}, allWarnings, err
    51  	}
    52  
    53  	domainNames := []string{}
    54  	for _, domain := range domains {
    55  		domainNames = append(domainNames, domain.Name)
    56  	}
    57  
    58  	spaceNames := []string{}
    59  	for _, space := range spaces {
    60  		spaceNames = append(spaceNames, space.Name)
    61  	}
    62  
    63  	sort.Strings(domainNames)
    64  	sort.Strings(spaceNames)
    65  
    66  	organizationSummary := OrganizationSummary{
    67  		Organization:                org,
    68  		DomainNames:                 domainNames,
    69  		QuotaName:                   quota.Name,
    70  		SpaceNames:                  spaceNames,
    71  		DefaultIsolationSegmentGUID: isoSegGUID,
    72  	}
    73  
    74  	return organizationSummary, allWarnings, nil
    75  }