1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

ROUTE53: (CHORE) Rename variables for clarity (#2010)

This commit is contained in:
Tom Limoncelli
2023-01-28 12:42:05 -05:00
committed by GitHub
parent a136621052
commit 37aa9fc838

View File

@@ -346,8 +346,8 @@ func (r *route53Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
changes := []r53Types.Change{} changes := []r53Types.Change{}
changeDesc := []string{} changeDesc := []string{}
for _, k := range updateOrder { for _, currentKey := range updateOrder {
recs := updates[k] recs := updates[currentKey]
// If there are no records in our desired state for a key, this // If there are no records in our desired state for a key, this
// indicates we should delete all records at that key. // indicates we should delete all records at that key.
if len(recs) == 0 { if len(recs) == 0 {
@@ -357,16 +357,16 @@ func (r *route53Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
found bool found bool
) )
// Find the original resource set: // Find the original resource set:
for _, r := range r.originalRecords { for _, orec := range r.originalRecords {
if unescape(r.Name) == k.NameFQDN && (string(r.Type) == k.Type || k.Type == "R53_ALIAS_"+string(r.Type)) { if unescape(orec.Name) == currentKey.NameFQDN && (string(orec.Type) == currentKey.Type || currentKey.Type == "R53_ALIAS_"+string(orec.Type)) {
rrset = r rrset = orec
found = true found = true
break break
} }
} }
if !found { if !found {
// This should not happen. // This should not happen.
return nil, fmt.Errorf("no record set found to delete. Name: '%s'. Type: '%s'", k.NameFQDN, k.Type) return nil, fmt.Errorf("no record set found to delete. Name: '%s'. Type: '%s'", currentKey.NameFQDN, currentKey.Type)
} }
// Assemble the change and add it to the list: // Assemble the change and add it to the list:
chg := r53Types.Change{ chg := r53Types.Change{
@@ -374,41 +374,41 @@ func (r *route53Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
ResourceRecordSet: &rrset, ResourceRecordSet: &rrset,
} }
dels = append(dels, chg) dels = append(dels, chg)
delDesc = append(delDesc, strings.Join(namesToUpdate[k], "\n")) delDesc = append(delDesc, strings.Join(namesToUpdate[currentKey], "\n"))
} else { } else {
// If it isn't a delete, it must be either a change or create. In // If it isn't a delete, it must be either a change or create. In
// either case, we build a new record set from the desired state and // either case, we build a new record set from the desired state and
// UPSERT it. // UPSERT it.
if strings.HasPrefix(k.Type, "R53_ALIAS_") { if strings.HasPrefix(currentKey.Type, "R53_ALIAS_") {
// Each R53_ALIAS_* requires an individual change. // Each R53_ALIAS_* requires an individual change.
if len(recs) != 1 { if len(recs) != 1 {
log.Fatal("Only one R53_ALIAS_ permitted on a label") log.Fatal("Only one R53_ALIAS_ permitted on a label")
} }
for _, r := range recs { for _, rec := range recs {
rrset := aliasToRRSet(zone, r) rrset := aliasToRRSet(zone, rec)
rrset.Name = aws.String(k.NameFQDN) rrset.Name = aws.String(currentKey.NameFQDN)
// Assemble the change and add it to the list: // Assemble the change and add it to the list:
chg := r53Types.Change{ chg := r53Types.Change{
Action: r53Types.ChangeActionUpsert, Action: r53Types.ChangeActionUpsert,
ResourceRecordSet: rrset, ResourceRecordSet: rrset,
} }
changes = append(changes, chg) changes = append(changes, chg)
changeDesc = append(changeDesc, strings.Join(namesToUpdate[k], "\n")) changeDesc = append(changeDesc, strings.Join(namesToUpdate[currentKey], "\n"))
} }
} else { } else {
// All other keys combine their updates into one rrset: // All other keys combine their updates into one rrset:
rrset := &r53Types.ResourceRecordSet{ rrset := &r53Types.ResourceRecordSet{
Name: aws.String(k.NameFQDN), Name: aws.String(currentKey.NameFQDN),
Type: r53Types.RRType(k.Type), Type: r53Types.RRType(currentKey.Type),
} }
for _, r := range recs { for _, rec := range recs {
val := r.GetTargetCombined() val := rec.GetTargetCombined()
rr := r53Types.ResourceRecord{ rr := r53Types.ResourceRecord{
Value: aws.String(val), Value: aws.String(val),
} }
rrset.ResourceRecords = append(rrset.ResourceRecords, rr) rrset.ResourceRecords = append(rrset.ResourceRecords, rr)
i := int64(r.TTL) i := int64(rec.TTL)
rrset.TTL = &i // TODO: make sure that ttls are consistent within a set rrset.TTL = &i // TODO: make sure that ttls are consistent within a set
} }
// Assemble the change and add it to the list: // Assemble the change and add it to the list:
@@ -417,7 +417,7 @@ func (r *route53Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
ResourceRecordSet: rrset, ResourceRecordSet: rrset,
} }
changes = append(changes, chg) changes = append(changes, chg)
changeDesc = append(changeDesc, strings.Join(namesToUpdate[k], "\n")) changeDesc = append(changeDesc, strings.Join(namesToUpdate[currentKey], "\n"))
} }
} }