// GetDomainsByNameAndOrganization returns back a list of domains given a list
// of domains names and the organization GUID. If no domains are given, than this
// command will not lookup any domains.
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
}
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)
}
280222
func (client *Client) GetMainDomainName(args *GetMainDomainNameArgs) (response *GetMainDomainNameResponse, err error) {
	action := "GetMainDomainName"
	response = &GetMainDomainNameResponse{}
	err = client.Invoke(action, args, response)
	if err == nil {
		return response, nil
	} else {
		return nil, err
	}
}
1139766
func listDomains(c *godo.Client) ([]godo.Domain, error) {
	// TODO (andrewsykim): pagination in ListOptions
	domains, _, err := c.Domains.List(context.TODO(), &godo.ListOptions{})
	if err != nil {
		return nil, fmt.Errorf("failed to list domains: %v", err)
	}

	return domains, err
}
305747
func (c *Connect) LookupDomainByName(id string) (*Domain, error) {
	cName := C.CString(id)
	defer C.free(unsafe.Pointer(cName))
	var err C.virError
	ptr := C.virDomainLookupByNameWrapper(c.ptr, cName, &err)
	if ptr == nil {
		return nil, makeError(&err)
	}
	return &Domain{ptr: ptr}, nil
}
1185286
func (jolokiaClient *JolokiaClient) ListDomains() ([]string, error) {
	request := NewJolokiaRequest(LIST, "", nil, "")
	resp, requestErr := jolokiaClient.ExecuteRequest(request, "maxDepth=1")
	if requestErr != nil {
		return nil, requestErr
	}
	ret := make([]string, 0, len(resp.Value))
	for key, _ := range resp.Value {
		ret = append(ret, key)
	}
	sort.Strings(ret)
	return ret, nil
}
669440
func GetDomain(user string) (string, string) {
	domain := ""

	if strings.Contains(user, "\\") {
		ucomponents := strings.SplitN(user, "\\", 2)
		domain = ucomponents[0]
		user = ucomponents[1]
	}
	return user, domain
}
1040410
func (id *identity) GetOrganizationalUnits() []*OUIdentifier {
	if id.cert == nil {
		return nil
	}

	cid, err := id.msp.getCertificationChainIdentifier(id)
	if err != nil {
		mspIdentityLogger.Errorf("Failed getting certification chain identifier for [%v]: [%+v]", id, err)

		return nil
	}

	res := []*OUIdentifier{}
	for _, unit := range id.cert.Subject.OrganizationalUnit {
		res = append(res, &OUIdentifier{
			OrganizationalUnitIdentifier: unit,
			CertifiersIdentifier:         cid,
		})
	}

	return res
}
1108098
func (t *Template) GetAWSElasticsearchDomainWithName(name string) (*resources.AWSElasticsearchDomain, error) {
	if untyped, ok := t.Resources[name]; ok {
		switch resource := untyped.(type) {
		case *resources.AWSElasticsearchDomain:
			return resource, nil
		}
	}
	return nil, fmt.Errorf("resource %q of type AWSElasticsearchDomain not found", name)
}
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
}
1182585
func (a *API) GetDomainConfig(domain int, key string) (string, error) {
	url := a.BuildURL("/v2/domain/%d/config/%s/", domain, key)
	return a.getTextPlain(url, Params{})
}
1172342
func (g *OrganizationService) YourOrganizations(uri *Hyperlink, params M) (
	organizations []Organization, result *Result) {
	if uri == nil {
		uri = &YourOrganizationsURL
	}
	url, err := uri.Expand(params)
	if err != nil {
		return nil, &Result{Err: err}
	}
	result = g.client.get(url, &organizations)
	return
}
1056274
func (u *User) GetOrganizations(showPrivate bool) error {
	orgIDs, err := GetOrgIDsByUserID(u.ID, showPrivate)
	if err != nil {
		return fmt.Errorf("GetOrgIDsByUserID: %v", err)
	}
	if len(orgIDs) == 0 {
		return nil
	}

	u.Orgs = make([]*User, 0, len(orgIDs))
	if err = x.Where("type = ?", USER_TYPE_ORGANIZATION).In("id", orgIDs).Find(&u.Orgs); err != nil {
		return err
	}
	return nil
}
997207
func (t *Template) GetAWSSDBDomainWithName(name string) (*resources.AWSSDBDomain, error) {
	if untyped, ok := t.Resources[name]; ok {
		switch resource := untyped.(type) {
		case *resources.AWSSDBDomain:
			return resource, nil
		}
	}
	return nil, fmt.Errorf("resource %q of type AWSSDBDomain not found", name)
}
702275
func (a *API) GetDomainSet(user *User) ([]int, error) {
	dst := make([]int, 0)
	url := a.BuildURL("/v2/user/%d/domains", user.Id)
	err := a.Get(url, Params{}, &dst)
	return dst, err
}
677065
func (d *DNS) GetDomainResources(domainID int) ([]*Resource, error) {
	params := linode.Parameters{
		"DomainID": strconv.Itoa(domainID),
	}

	var list []*Resource
	_, err := d.linode.Request("domain.resource.list", params, &list)
	if err != nil {
		return nil, err
	}
	return list, nil
}
5081
func (s *DomainService) GetDomainChildrenByID(id string, opts ...OptionFunc) (*DomainChildren, int, error) {
	p := &ListDomainChildrenParams{}
	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.ListDomainChildren(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.DomainChildren[0], l.Count, nil
	}
	return nil, l.Count, fmt.Errorf("There is more then one result for DomainChildren UUID: %s!", id)
}