// DNSRecord returns a single DNS record for the given zone & record
// identifiers.
//
// API reference: https://api.cloudflare.com/#dns-records-for-a-zone-dns-record-details
778461
func (api *API) DNSRecord(zoneID, recordID string) (DNSRecord, error) {
	uri := "/zones/" + zoneID + "/dns_records/" + recordID
	res, err := api.makeRequest("GET", uri, nil)
	if err != nil {
		return DNSRecord{}, errors.Wrap(err, errMakeRequestError)
	}
	var r DNSRecordResponse
	err = json.Unmarshal(res, &r)
	if err != nil {
		return DNSRecord{}, errors.Wrap(err, errUnmarshalError)
	}
	return r.Result, nil
}
531206
func (client *AuroraDNSClient) RemoveRecord(zoneID string, recordID string) (*records.RemoveRecordResponse, error) {
	logrus.Debugf("RemoveRecord(%s, %s)", zoneID, recordID)
	relativeURL := fmt.Sprintf("zones/%s/records/%s", zoneID, recordID)

	_, err := client.requestor.Request(relativeURL, "DELETE", nil)
	if err != nil {
		logrus.Errorf("Failed to remove record: %s", err)

		return nil, err
	}

	return &records.RemoveRecordResponse{}, nil
}
557097
func (s *DnsConfigChange) SetDnsRecords(v []*DnsRecord) *DnsConfigChange {
	s.DnsRecords = v
	return s
}
1099098
func (records *Records) Create(ctx context.Context, record *Record) (err error) {
	buffer := new(bytes.Buffer)
	err = json.NewEncoder(buffer).Encode(record)
	if err != nil {
		return
	}
	response, err := httpDo(ctx, records.Options, "POST", apiURL("/zones/%s/dns_records", record.ZoneID), buffer)
	if err != nil {
		return
	}
	defer response.Body.Close()
	result, err := readResponse(response.Body)
	if err != nil {
		return
	}
	res := new(Record)
	err = json.Unmarshal(result.Result, &res)
	if err != nil {
		return
	}
	record.ID = res.ID
	record.TTL = res.TTL
	record.Locked = res.Locked
	record.Proxied = res.Proxied
	record.Proxiable = res.Proxiable
	record.CreatedOn = res.CreatedOn
	record.ModifiedOn = res.ModifiedOn
	return
}
841062
func (z *Zone) Records(zoneInfo Info) record.Manager {
	return record.New(z.Client, fmt.Sprintf("/zones/%s", zoneInfo.UUID))
}
154110
func (self *Record) Delete(zoneId, version int64, recordId string) (bool, error) {
	var res int64
	deleteArgs := map[string]interface{}{"id": recordId}
	params := []interface{}{self.Key, zoneId, version, deleteArgs}
	if err := self.Call("domain.zone.record.delete", params, &res); err != nil {
		return false, err
	}
	return (res == 1), nil
}
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
}
785365
func (client *Client) DeleteZoneRecord(args *DeleteZoneRecordArgs) (err error) {
	response := &DeleteZoneRecordResponse{}
	err = client.Invoke("DeleteZoneRecord", args, &response)

	return err
}
879456
func (s *DomainsService) GetRecord(domain string, recordID string) (Record, *Response, error) {
	path := recordAction("Info")

	payload := newPayLoad(s.client.CommonParams)

	payload.Add("domain_id", domain)
	payload.Add("record_id", recordID)

	returnedRecord := recordWrapper{}

	res, err := s.client.post(path, payload, &returnedRecord)
	if err != nil {
		return Record{}, res, err
	}

	if returnedRecord.Status.Code != "1" {
		return returnedRecord.Record, nil, fmt.Errorf("Could not get domains: %s", returnedRecord.Status.Message)
	}

	return returnedRecord.Record, res, nil
}
85330
func (c *Client) CreateRecord(domainID string, record Record) error {
	return c.do(http.MethodPost, fmt.Sprintf("/v1/domains/%s/records", domainID), record, nil)
}
805654
func (client *Client) DescribeSubDomainRecords(args *DescribeSubDomainRecordsArgs) (response *DescribeSubDomainRecordsResponse, err error) {
	action := "DescribeSubDomainRecords"
	response = &DescribeSubDomainRecordsResponse{}
	err = client.Invoke(action, args, response)
	if err == nil {
		return response, nil
	} else {
		return nil, err
	}
}
358799
func (self *Record) SetRecords(zone_id, version_id int64, args []RecordSet) ([]*RecordInfo, error) {
	var res []interface{}

	params := []interface{}{self.Key, zone_id, version_id, args}
	if err := self.Call("domain.zone.record.set", params, &res); err != nil {
		return nil, err
	}

	records := make([]*RecordInfo, 0)
	for _, r := range res {
		record := ToRecordInfo(r.(map[string]interface{}))
		records = append(records, record)
	}
	return records, nil
}
149049
func (d *DNSServer) serviceSRVRecords(cfg *dnsConfig, dc string, nodes structs.CheckServiceNodes, req, resp *dns.Msg, ttl time.Duration, maxRecursionLevel int) {
	handled := make(map[string]struct{})
	edns := req.IsEdns0() != nil

	for _, node := range nodes {
		// Avoid duplicate entries, possible if a node has
		// the same service the same port, etc.
		tuple := fmt.Sprintf("%s:%s:%d", node.Node.Node, node.Service.Address, node.Service.Port)
		if _, ok := handled[tuple]; ok {
			continue
		}
		handled[tuple] = struct{}{}

		weight := findWeight(node)
		// Add the SRV record
		srvRec := &dns.SRV{
			Hdr: dns.RR_Header{
				Name:   req.Question[0].Name,
				Rrtype: dns.TypeSRV,
				Class:  dns.ClassINET,
				Ttl:    uint32(ttl / time.Second),
			},
			Priority: 1,
			Weight:   uint16(weight),
			Port:     uint16(node.Service.Port),
			Target:   fmt.Sprintf("%s.node.%s.%s", node.Node.Node, dc, d.domain),
		}
		resp.Answer = append(resp.Answer, srvRec)

		// Start with the translated address but use the service address,
		// if specified.
		addr := d.agent.TranslateAddress(dc, node.Node.Address, node.Node.TaggedAddresses)
		if node.Service.Address != "" {
			addr = node.Service.Address
		}

		// Add the extra record
		records, meta := d.formatNodeRecord(cfg, node.Node, addr, srvRec.Target, dns.TypeANY, ttl, edns, maxRecursionLevel, cfg.NodeMetaTXT)
		if len(records) > 0 {
			// Use the node address if it doesn't differ from the service address
			if addr == node.Node.Address {
				resp.Extra = append(resp.Extra, records...)
			} else {
				// If it differs from the service address, give a special response in the
				// 'addr.consul' domain with the service IP encoded in it. We have to do
				// this because we can't put an IP in the target field of an SRV record.
				switch record := records[0].(type) {
				// IPv4
				case *dns.A:
					addr := hex.EncodeToString(record.A)

					// Take the last 8 chars (4 bytes) of the encoded address to avoid junk bytes
					srvRec.Target = fmt.Sprintf("%s.addr.%s.%s", addr[len(addr)-(net.IPv4len*2):], dc, d.domain)
					record.Hdr.Name = srvRec.Target
					resp.Extra = append(resp.Extra, record)

				// IPv6
				case *dns.AAAA:
					srvRec.Target = fmt.Sprintf("%s.addr.%s.%s", hex.EncodeToString(record.AAAA), dc, d.domain)
					record.Hdr.Name = srvRec.Target
					resp.Extra = append(resp.Extra, record)

				// Something else (probably a CNAME; just add the records).
				default:
					resp.Extra = append(resp.Extra, records...)
				}
			}

			if meta != nil && cfg.NodeMetaTXT {
				resp.Extra = append(resp.Extra, meta...)
			}
		}
	}
}
843190
func (c *Client) CreateRecord(domain *Domain, record *Record) error {
	url := fmt.Sprintf("%s/%d/%s", "/dns/managed", domain.ID, "records")

	resp, err := c.sendRequest(http.MethodPost, url, record)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	return nil
}
1269254
func createRecord(c *godo.Client, zoneName string, createRequest *godo.DomainRecordEditRequest) error {
	_, _, err := c.Domains.CreateRecord(context.TODO(), zoneName, createRequest)
	if err != nil {
		return fmt.Errorf("error creating record: %v", err)
	}

	return nil
}
939015
func (client *Client) AddDomainRecord(args *AddDomainRecordArgs) (response *AddDomainRecordResponse, err error) {
	action := "AddDomainRecord"
	response = &AddDomainRecordResponse{}
	err = client.Invoke(action, args, response)
	if err == nil {
		return response, nil
	} else {
		log.Printf("%s error, %v", action, err)
		return response, err
	}
}
267571
func (records *Records) Patch(ctx context.Context, record *Record) (err error) {
	buffer := new(bytes.Buffer)
	err = json.NewEncoder(buffer).Encode(record)
	if err != nil {
		return
	}
	response, err := httpDo(ctx, records.Options, "PUT", apiURL("/zones/%s/dns_records/%s", record.ZoneID, record.ID), buffer)
	if err != nil {
		return
	}
	defer response.Body.Close()
	_, err = readResponse(response.Body)
	return
}