github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/actor/pushaction/domain.go (about)

     1  package pushaction
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/actor/v2action"
     6  	log "github.com/sirupsen/logrus"
     7  )
     8  
     9  // DefaultDomain looks up the shared and then private domains and returns back
    10  // the first one in the list as the default.
    11  func (actor Actor) DefaultDomain(orgGUID string) (v2action.Domain, Warnings, error) {
    12  	log.Infoln("getting org domains for org GUID:", orgGUID)
    13  	// the domains object contains all the shared domains AND all domains private to this org
    14  	domains, warnings, err := actor.V2Actor.GetOrganizationDomains(orgGUID)
    15  	if err != nil {
    16  		log.Errorln("searching for domains in org:", err)
    17  		return v2action.Domain{}, Warnings(warnings), err
    18  	}
    19  
    20  	if len(domains) == 0 {
    21  		log.Error("no domains found")
    22  		return v2action.Domain{}, Warnings(warnings), actionerror.NoDomainsFoundError{OrganizationGUID: orgGUID}
    23  	}
    24  
    25  	log.Debugf("selecting first domain as default domain: %#v", domains)
    26  	return domains[0], Warnings(warnings), nil
    27  }