code.cloudfoundry.org/cli@v7.1.0+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 log.Debugf("filtering out internal domains from all found domains: %#v", domains) 21 var externalDomains []v2action.Domain 22 23 for _, d := range domains { 24 if !d.Internal { 25 externalDomains = append(externalDomains, d) 26 } 27 } 28 29 if len(externalDomains) == 0 { 30 log.Error("no domains found") 31 return v2action.Domain{}, Warnings(warnings), actionerror.NoDomainsFoundError{OrganizationGUID: orgGUID} 32 } 33 34 log.Debugf("selecting first external domain as default domain: %#v", externalDomains) 35 return externalDomains[0], Warnings(warnings), nil 36 }