github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/actor/v2action/service.go (about)

     1  package v2action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant"
     7  )
     8  
     9  type Service ccv2.Service
    10  
    11  func (actor Actor) GetService(serviceGUID string) (Service, Warnings, error) {
    12  	service, warnings, err := actor.CloudControllerClient.GetService(serviceGUID)
    13  	return Service(service), Warnings(warnings), err
    14  }
    15  
    16  // GetServiceByName returns a service based on the name provided.
    17  // If there are no services, an ServiceNotFoundError will be returned.
    18  // If there are multiple services, the first will be returned.
    19  func (actor Actor) GetServiceByName(serviceName string) (Service, Warnings, error) {
    20  	services, warnings, err := actor.CloudControllerClient.GetServices(ccv2.Filter{
    21  		Type:     constant.LabelFilter,
    22  		Operator: constant.EqualOperator,
    23  		Values:   []string{serviceName},
    24  	})
    25  	if err != nil {
    26  		return Service{}, Warnings(warnings), err
    27  	}
    28  
    29  	if len(services) == 0 {
    30  		return Service{}, Warnings(warnings), actionerror.ServiceNotFoundError{Name: serviceName}
    31  	}
    32  
    33  	return Service(services[0]), Warnings(warnings), nil
    34  }