<commit_before>package dns

import (
	"github.com/alekar/route53/src/route53"
	"github.com/crowdmob/goamz/aws"
	"strings"
	"time"
)

type Route53Provider struct {
	r53    *route53.Route53
	Zone   route53.HostedZone
	ZoneId string
	TTL    uint
}

func (r *Route53Provider) createRecords(comment string, rrsets ...route53.RRSet) (error, chan error) {
	changes := make([]route53.RRSetChange, len(rrsets))
	for i, rrset := range rrsets {
		changes[i] = route53.RRSetChange{
			Action: "CREATE",
			RRSet:  rrset,
		}
	}
	info, err := r.r53.ChangeRRSet(r.ZoneId, changes, comment)
	if err != nil {
		return err, nil
	}
	return nil, info.PollForSync(time.Second, 60*time.Second)
}

func (r *Route53Provider) baseRRSet(id, name, failover string) route53.RRSet {
	rrset := route53.RRSet{
		Name:          name,
		Type:          "A",
		TTL:           r.TTL,
		SetIdentifier: id,
		Weight:        0,
	}
	if failover == "PRIMARY" || failover == "SECONDARY" {
		rrset.Failover = failover
	}
	return rrset
}

func (r *Route53Provider) CreateAliases(comment string, aliases []Alias) (error, chan error) {
	rrsets := make([]route53.RRSet, len(aliases))
	count := 0
	for _, alias := range aliases {
		rrsets[count] = r.baseRRSet(alias.Id(), alias.Alias, alias.Failover)
		rrsets[count].HostedZoneId = r.ZoneId
		rrsets[count].DNSName = alias.Original
		rrsets[count].EvaluateTargetHealth = true
		count++
	}
	return r.createRecords(comment, rrsets...)
}

func (r *Route53Provider) CreateCNames(comment string, cnames []CName) (error, chan error) {
	rrsets := make([]route53.RRSet, len(cnames))
	count := 0
	for _, cname := range cnames {
		rrsets[count] = r.baseRRSet(cname.Id(), cname.CName, cname.Failover)
		rrsets[count].Values = []string{cname.IP}
		rrsets[count].HealthCheckId = cname.HealthCheckId
		count++
	}
	return r.createRecords(comment, rrsets...)
}

func (r *Route53Provider) DeleteRecords(comment string, ids ...string) (error, chan error) {
	if len(ids) == 0 {
		errChan := make(chan error)
		go func(ch chan error) { // fake channel with nil error
			ch <- nil
		}(errChan)
		return nil, errChan
	}<commit_msg>only set health check if it exists<commit_after>package dns

import (
	"github.com/alekar/route53/src/route53"
	"github.com/crowdmob/goamz/aws"
	"strings"
	"time"
)

type Route53Provider struct {
	r53    *route53.Route53
	Zone   route53.HostedZone
	ZoneId string
	TTL    uint
}

func (r *Route53Provider) createRecords(comment string, rrsets ...route53.RRSet) (error, chan error) {
	changes := make([]route53.RRSetChange, len(rrsets))
	for i, rrset := range rrsets {
		changes[i] = route53.RRSetChange{
			Action: "CREATE",
			RRSet:  rrset,
		}
	}
	info, err := r.r53.ChangeRRSet(r.ZoneId, changes, comment)
	if err != nil {
		return err, nil
	}
	return nil, info.PollForSync(time.Second, 60*time.Second)
}

func (r *Route53Provider) baseRRSet(id, name, failover string) route53.RRSet {
	rrset := route53.RRSet{
		Name:          name,
		Type:          "A",
		TTL:           r.TTL,
		SetIdentifier: id,
		Weight:        0,
	}
	if failover == "PRIMARY" || failover == "SECONDARY" {
		rrset.Failover = failover
	}
	return rrset
}

func (r *Route53Provider) CreateAliases(comment string, aliases []Alias) (error, chan error) {
	rrsets := make([]route53.RRSet, len(aliases))
	count := 0
	for _, alias := range aliases {
		rrsets[count] = r.baseRRSet(alias.Id(), alias.Alias, alias.Failover)
		rrsets[count].HostedZoneId = r.ZoneId
		rrsets[count].DNSName = alias.Original
		rrsets[count].EvaluateTargetHealth = true
		count++
	}
	return r.createRecords(comment, rrsets...)
}

func (r *Route53Provider) CreateCNames(comment string, cnames []CName) (error, chan error) {
	rrsets := make([]route53.RRSet, len(cnames))
	count := 0
	for _, cname := range cnames {
		rrsets[count] = r.baseRRSet(cname.Id(), cname.CName, cname.Failover)
		rrsets[count].Values = []string{cname.IP}
		if cname.HealthCheckId != "" {
			rrsets[count].HealthCheckId = cname.HealthCheckId
		}
		count++
	}
	return r.createRecords(comment, rrsets...)
}

func (r *Route53Provider) DeleteRecords(comment string, ids ...string) (error, chan error) {
	if len(ids) == 0 {
		errChan := make(chan error)
		go func(ch chan error) { // fake channel with nil error
			ch <- nil
		}(errChan)
		return nil, errChan
	}
{'fraction_non_alphanumeric': 0.14172309129115107, 'fraction_numerical': 0.021480270838197525, 'mean_word_length': 3.840677966101695, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2869983', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1586, 'n_words': 370}