// Domains retrieves the domains associated with an organization
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
}
1364828
func (actor Actor) DefaultDomain(orgGUID string) (v2action.Domain, Warnings, error) {
	log.Infoln("getting org domains for org GUID:", orgGUID)
	// the domains object contains all the shared domains AND all domains private to this org
	domains, warnings, err := actor.V2Actor.GetOrganizationDomains(orgGUID)
	if err != nil {
		log.Errorln("searching for domains in org:", err)
		return v2action.Domain{}, Warnings(warnings), err
	}

	log.Debugf("filtering out internal domains from all found domains: %#v", domains)
	var externalDomains []v2action.Domain

	for _, d := range domains {
		if !d.Internal {
			externalDomains = append(externalDomains, d)
		}
	}

	if len(externalDomains) == 0 {
		log.Error("no domains found")
		return v2action.Domain{}, Warnings(warnings), actionerror.NoDomainsFoundError{OrganizationGUID: orgGUID}
	}

	log.Debugf("selecting first external domain as default domain: %#v", externalDomains)
	return externalDomains[0], Warnings(warnings), nil
}
1117535
func (o *Domain) Zones(info *bambou.FetchingInfo) (ZonesList, *bambou.Error) {

	var list ZonesList
	err := bambou.CurrentSession().FetchChildren(o, ZoneIdentity, &list, info)
	return list, err
}
215777
func (s *OrganizationsStore) All(ctx context.Context) ([]chronograf.Organization, error) {
	err := validOrganization(ctx)
	if err != nil {
		return nil, err
	}

	ds, err := s.store.All(ctx)
	if err != nil {
		return nil, err
	}

	defaultOrg, err := s.store.DefaultOrganization(ctx)
	if err != nil {
		return nil, err
	}

	defaultOrgID := defaultOrg.ID

	// This filters organizations without allocating
	// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
	organizations := ds[:0]
	for _, d := range ds {
		id := d.ID
		switch id {
		case s.organization, defaultOrgID:
			organizations = append(organizations, d)
		default:
			continue
		}
	}

	return organizations, nil
}
110968
func GetDomain(ctx sessionctx.Context) *Domain {
	v, ok := ctx.Value(domainKey).(*Domain)
	if !ok {
		return nil
	}
	return v
}
290204
func Domain(s string) string {
	d, err := publicsuffix.EffectiveTLDPlusOne(s)
	if err != nil {
		panic(errors.Wrap(err, "effective domain"))
	}

	return d
}
56802
func (s *App) SetDomains(v []*string) *App {
	s.Domains = v
	return s
}
321182
func (q DomainsQuery) scope(db *gorm.DB) *gorm.DB {
	var scope composedScope

	if q.Hostname != nil {
		scope = append(scope, fieldEquals("hostname", *q.Hostname))
	}

	if q.App != nil {
		scope = append(scope, forApp(q.App))
	}

	return scope.scope(db)
}
1298411
func (ditr debugIterator) Domain() (start []byte, end []byte) {
	defer func() {
		fmt.Printf("%v.itr.Domain() (%X,%X)\n", ditr.label, start, end)
	}()
	start, end = ditr.itr.Domain()
	return
}
207006
func (s *CreateAppInput) SetDomains(v []*string) *CreateAppInput {
	s.Domains = v
	return s
}
960206
func (remote *RemoteDebugger) GetDomains() ([]Domain, error) {
	res, err := remote.sendRawReplyRequest("Schema.getDomains", nil)
	if err != nil {
		return nil, err
	}

	var domains struct {
		Domains []Domain
	}

	err = json.Unmarshal(res, &domains)
	if err != nil {
		return nil, err
	}

	return domains.Domains, nil
}
10565
func (actor Actor) GetDomainsByNameAndOrganization(domainNames []string, orgGUID string) ([]Domain, Warnings, error) {
	if len(domainNames) == 0 {
		return nil, nil, nil
	}

	var domains []Domain
	var allWarnings Warnings

	// TODO: If the following causes URI length problems, break domainNames into
	// batched (based on character length?) and loop over them.

	sharedDomains, warnings, err := actor.CloudControllerClient.GetSharedDomains(ccv2.Filter{
		Type:     constant.NameFilter,
		Operator: constant.InOperator,
		Values:   domainNames,
	})
	allWarnings = append(allWarnings, warnings...)
	if err != nil {
		return nil, allWarnings, err
	}

	for _, domain := range sharedDomains {
		domains = append(domains, Domain(domain))
		actor.saveDomain(domain)
	}

	privateDomains, warnings, err := actor.CloudControllerClient.GetOrganizationPrivateDomains(
		orgGUID,
		ccv2.Filter{
			Type:     constant.NameFilter,
			Operator: constant.InOperator,
			Values:   domainNames,
		})
	allWarnings = append(allWarnings, warnings...)
	if err != nil {
		return nil, allWarnings, err
	}

	for _, domain := range privateDomains {
		domains = append(domains, Domain(domain))
		actor.saveDomain(domain)
	}

	return domains, allWarnings, err
}
292158
func (s *DirectStore) Organizations(ctx context.Context) chronograf.OrganizationsStore {
	return s.OrganizationsStore
}
587046
func (client *Client) GetDomain(ctx context.Context, name string) (*DNSDomain, error) {
	resp, err := client.dnsRequest(ctx, "/v1/domains/"+name, nil, "", "GET")
	if err != nil {
		return nil, err
	}

	var d *DNSDomainResponse
	if err := json.Unmarshal(resp, &d); err != nil {
		return nil, err
	}

	return d.Domain, nil
}
755968
func (s *DomainsService) ListDomains(accountID string, options *DomainListOptions) (*domainsResponse, error) {
	path := versioned(domainPath(accountID, ""))
	domainsResponse := &domainsResponse{}

	path, err := addURLQueryOptions(path, options)
	if err != nil {
		return nil, err
	}

	resp, err := s.client.get(path, domainsResponse)
	if err != nil {
		return nil, err
	}

	domainsResponse.HttpResponse = resp
	return domainsResponse, nil
}
1200660
func DomainsRemove(appID, domain string) error {
	c, appID, err := load(appID)

	if err != nil {
		return err
	}

	fmt.Printf("Removing %s from %s... ", domain, appID)

	quit := progress()
	err = domains.Delete(c, appID, domain)
	quit <- true
	<-quit

	if err != nil {
		return err
	}

	fmt.Println("done")
	return nil
}
622043
func (inv *Investigate) DomainTags(domain string) ([]DomainTag, error) {
	var resp []DomainTag
	err := inv.GetParse(fmt.Sprintf(urls["tags"], domain), &resp)
	if err != nil {
		return nil, err
	}
	return resp, nil
}