// DomainsFind returns the first domain matching the query.
12206
func (e *Empire) DomainsFind(q DomainsQuery) (*Domain, error) {
	return domainsFind(e.db, q)
}
324661
func (c *Client) GetDomainID(domainName string) (string, error) {
	domainList := &DomainListResponse{}

	err := c.do(http.MethodGet, "/v1/domains", nil, domainList)
	if err != nil {
		return "", err
	}

	for _, domain := range domainList.Domains {
		if domain.Name == domainName {
			return domain.ID, nil
		}
	}
	return "", fmt.Errorf("no such domain: %s", domainName)
}
977838
func (c *Client) GetDomainInformation(fqdn string) (*Data, error) {
	authZone, err := dns01.FindZoneByFqdn(fqdn)
	if err != nil {
		return nil, err
	}

	result, err := c.doRequest(http.MethodGet, "domain", nil)
	if err != nil {
		return nil, err
	}

	var domains []Data
	if len(result) > 0 {
		err = json.Unmarshal(result, &domains)
		if err != nil {
			return nil, fmt.Errorf("CloudXNS: domains unmarshaling error: %v", err)
		}
	}

	for _, data := range domains {
		if data.Domain == authZone {
			return &data, nil
		}
	}

	return nil, fmt.Errorf("CloudXNS: zone %s not found for domain %s", authZone, fqdn)
}
389160
func (s *DomainService) GetDomainByID(id string, opts ...OptionFunc) (*Domain, int, error) {
	p := &ListDomainsParams{}
	p.p = make(map[string]interface{})

	p.p["id"] = id

	for _, fn := range append(s.cs.options, opts...) {
		if err := fn(s.cs, p); err != nil {
			return nil, -1, err
		}
	}

	l, err := s.ListDomains(p)
	if err != nil {
		if strings.Contains(err.Error(), fmt.Sprintf(
			"Invalid parameter id value=%s due to incorrect long value format, "+
				"or entity does not exist", id)) {
			return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
		}
		return nil, -1, err
	}

	if l.Count == 0 {
		return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
	}

	if l.Count == 1 {
		return l.Domains[0], l.Count, nil
	}
	return nil, l.Count, fmt.Errorf("There is more then one result for Domain UUID: %s!", id)
}
193738
func (org *Organization) Domains() ([]*Domain, error) {
	var d domainsResponse
	err := org.PPE.get(fmt.Sprintf("/domains/%s", org.PrimaryDomain), &d)
	if err != nil {
		return []*Domain{}, err
	}
	drs := d.Domains
	doms := make([]*Domain, len(org.domains))
	for _, dr := range drs {
		for i, dom := range org.domains {
			if dr.DomainName == dom {
				doms[i] = domainFromDomainResponse(org, dr)
			}
		}
	}
	return doms, nil
}
723654
func MatchDomain(domain string, certDomain string) bool {
	if domain == certDomain {
		return true
	}

	for len(certDomain) > 0 && certDomain[len(certDomain)-1] == '.' {
		certDomain = certDomain[:len(certDomain)-1]
	}

	labels := strings.Split(domain, ".")
	for i := range labels {
		labels[i] = "*"
		candidate := strings.Join(labels, ".")
		if certDomain == candidate {
			return true
		}
	}
	return false
}
191605
func (c *CDN) DomainConfigs(domainName string, resp interface{}, configList ...ConfigName) (err error) {
	config := []string{}
	for _, val := range configList {
		config = append(config, string(val))
	}
	err = c.domainConfigs(domainName, resp, config...)
	return
}
894333
func (ppe *PPE) Domain(domain string) (*Domain, error) {
	var d domainsResponse
	err := ppe.get(fmt.Sprintf("/domains/%s", domain), &d)
	if err != nil {
		return &Domain{}, err
	}
	drs := d.Domains
	var dom *Domain
	for _, dr := range drs {
		if dr.DomainName == domain {
			org, err := ppe.Organization(domain)
			if err != nil {
				return &Domain{}, err
			}
			dom = domainFromDomainResponse(org, dr)
			break
		}
	}
	return dom, nil
}
366046
func (org *Organization) Domain(domain string) (*Domain, error) {
	var d domainsResponse
	err := org.PPE.get(fmt.Sprintf("/domains/%s/%s", org.PrimaryDomain, domain), &d)
	if err != nil {
		return &Domain{}, err
	}
	return domainFromDomainResponse(org, d.Domains[0]), nil
}
629654
func getMainDomain(domain string) string {
	domain = dns01.UnFqdn(domain)

	split := dns.Split(domain)
	if strings.HasSuffix(strings.ToLower(domain), "duckdns.org") {
		if len(split) < 3 {
			return ""
		}

		firstSubDomainIndex := split[len(split)-3]
		return domain[firstSubDomainIndex:]
	}

	return domain[split[len(split)-1]:]
}
669809
func Domain(named Named) string {
	if r, ok := named.(namedRepository); ok {
		return r.Domain()
	}
	domain, _ := splitDomain(named.Name())
	return domain
}
675120
func (e *Empire) AppsFind(q AppsQuery) (*App, error) {
	return appsFind(e.db, q)
}
726506
func (d *DNSProvider) findTxtRecord(fqdn string, zoneID int) (*Record, error) {
	result, err := d.makeRequest(http.MethodGet, fmt.Sprintf("/domains/%d/records?type=TXT&name=%s", zoneID, dns01.UnFqdn(fqdn)), nil)
	if err != nil {
		return nil, err
	}

	var records Records
	err = json.Unmarshal(result, &records)
	if err != nil {
		return nil, err
	}

	switch len(records.Record) {
	case 1:
	case 0:
		return nil, fmt.Errorf("no TXT record found for %s", fqdn)
	default:
		return nil, fmt.Errorf("more than 1 TXT record found for %s", fqdn)
	}

	return &records.Record[0], nil
}
1039090
func (s *DomainService) GetDomainChildrenID(name string, opts ...OptionFunc) (string, int, error) {
	p := &ListDomainChildrenParams{}
	p.p = make(map[string]interface{})

	p.p["name"] = name

	for _, fn := range append(s.cs.options, opts...) {
		if err := fn(s.cs, p); err != nil {
			return "", -1, err
		}
	}

	l, err := s.ListDomainChildren(p)
	if err != nil {
		return "", -1, err
	}

	if l.Count == 0 {
		return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
	}

	if l.Count == 1 {
		return l.DomainChildren[0].Id, l.Count, nil
	}

	if l.Count > 1 {
		for _, v := range l.DomainChildren {
			if v.Name == name {
				return v.Id, l.Count, nil
			}
		}
	}
	return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
848776
func Domain(domain string) Option {
	return func(c *Client) error {
		c.domain = domain
		return nil
	}
}
1191748
func (c *Config) Domain() (string, error) {
	domain := ""
	for _, v := range strings.Split(strings.ToLower(c.BaseDN), ",") {
		if trimmed := strings.TrimSpace(v); strings.HasPrefix(trimmed, "dc=") {
			domain = domain + "." + trimmed[3:]
		}
	}
	if len(domain) <= 1 {
		return "", errors.New("Configuration error: invalid BaseDN")
	}
	return domain[1:], nil
}
1064682
func domainMatch(requestHost string, r Route) bool {
	// if there is no domain, no need to worry about matching
	if r.Domain == "" {
		return true
	}
	domain := ""
	hostBits := strings.Split(requestHost, ".")
	if len(hostBits) >= 2 {
		domain = strings.Join(hostBits[len(hostBits)-2:], ".")
		lumber.Trace("[NANOBOX-ROUTER] Domain: '%s'", domain)
	}
	match := domain == r.Domain
	lumber.Trace("[NANOBOX-ROUTER] Domain match? '%t'", match)
	return match
}