github.com/jasonkeene/cli@v6.14.1-0.20160816203908-ca5715166dfb+incompatible/cf/requirements/service_instance.go (about)

     1  package requirements
     2  
     3  import (
     4  	"github.com/cloudfoundry/cli/cf/api"
     5  	"github.com/cloudfoundry/cli/cf/models"
     6  )
     7  
     8  //go:generate counterfeiter . ServiceInstanceRequirement
     9  
    10  type ServiceInstanceRequirement interface {
    11  	Requirement
    12  	GetServiceInstance() models.ServiceInstance
    13  }
    14  
    15  type serviceInstanceAPIRequirement struct {
    16  	name            string
    17  	serviceRepo     api.ServiceRepository
    18  	serviceInstance models.ServiceInstance
    19  }
    20  
    21  func NewServiceInstanceRequirement(name string, sR api.ServiceRepository) (req *serviceInstanceAPIRequirement) {
    22  	req = new(serviceInstanceAPIRequirement)
    23  	req.name = name
    24  	req.serviceRepo = sR
    25  	return
    26  }
    27  
    28  func (req *serviceInstanceAPIRequirement) Execute() error {
    29  	var apiErr error
    30  	req.serviceInstance, apiErr = req.serviceRepo.FindInstanceByName(req.name)
    31  
    32  	if apiErr != nil {
    33  		return apiErr
    34  	}
    35  
    36  	return nil
    37  }
    38  
    39  func (req *serviceInstanceAPIRequirement) GetServiceInstance() models.ServiceInstance {
    40  	return req.serviceInstance
    41  }