github.com/sleungcy-sap/cli@v7.1.0+incompatible/cf/requirements/domain.go (about)

     1  package requirements
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/cf/api"
     5  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
     6  	"code.cloudfoundry.org/cli/cf/models"
     7  )
     8  
     9  //go:generate counterfeiter . DomainRequirement
    10  
    11  type DomainRequirement interface {
    12  	Requirement
    13  	GetDomain() models.DomainFields
    14  }
    15  
    16  type domainAPIRequirement struct {
    17  	name       string
    18  	config     coreconfig.Reader
    19  	domainRepo api.DomainRepository
    20  	domain     models.DomainFields
    21  }
    22  
    23  func NewDomainRequirement(name string, config coreconfig.Reader, domainRepo api.DomainRepository) (req *domainAPIRequirement) {
    24  	req = new(domainAPIRequirement)
    25  	req.name = name
    26  	req.config = config
    27  	req.domainRepo = domainRepo
    28  	return
    29  }
    30  
    31  func (req *domainAPIRequirement) Execute() error {
    32  	var apiErr error
    33  	req.domain, apiErr = req.domainRepo.FindByNameInOrg(req.name, req.config.OrganizationFields().GUID)
    34  
    35  	if apiErr != nil {
    36  		return apiErr
    37  	}
    38  
    39  	return nil
    40  }
    41  
    42  func (req *domainAPIRequirement) GetDomain() models.DomainFields {
    43  	return req.domain
    44  }