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

     1  package v7action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     5  )
     6  
     7  type ServiceOfferingWithPlans ccv3.ServiceOfferingWithPlans
     8  
     9  type MarketplaceFilter struct {
    10  	SpaceGUID, ServiceOfferingName, ServiceBrokerName string
    11  	ShowUnavailable                                   bool
    12  }
    13  
    14  func (actor Actor) Marketplace(filter MarketplaceFilter) ([]ServiceOfferingWithPlans, Warnings, error) {
    15  	query := []ccv3.Query{{Key: ccv3.PerPage, Values: []string{ccv3.MaxPerPage}}}
    16  
    17  	if filter.SpaceGUID != "" {
    18  		query = append(query, ccv3.Query{
    19  			Key:    ccv3.SpaceGUIDFilter,
    20  			Values: []string{filter.SpaceGUID},
    21  		})
    22  	}
    23  
    24  	if filter.ServiceOfferingName != "" {
    25  		query = append(query, ccv3.Query{
    26  			Key:    ccv3.ServiceOfferingNamesFilter,
    27  			Values: []string{filter.ServiceOfferingName},
    28  		})
    29  	}
    30  
    31  	if filter.ServiceBrokerName != "" {
    32  		query = append(query, ccv3.Query{
    33  			Key:    ccv3.ServiceBrokerNamesFilter,
    34  			Values: []string{filter.ServiceBrokerName},
    35  		})
    36  	}
    37  
    38  	if !filter.ShowUnavailable {
    39  		query = append(query, ccv3.Query{
    40  			Key:    ccv3.AvailableFilter,
    41  			Values: []string{"true"},
    42  		})
    43  	}
    44  
    45  	serviceOffering, warnings, err := actor.CloudControllerClient.GetServicePlansWithOfferings(query...)
    46  	if err != nil {
    47  		return nil, Warnings(warnings), err
    48  	}
    49  
    50  	result := make([]ServiceOfferingWithPlans, len(serviceOffering))
    51  	for i := range serviceOffering {
    52  		result[i] = ServiceOfferingWithPlans(serviceOffering[i])
    53  	}
    54  
    55  	return result, Warnings(warnings), nil
    56  }