Fix DNSimple SRV and MX records (#413)

* Fix SRV and MX records, update knownFailures

This gets us back to tests passing

Signed-off-by: Amy Aronsohn <WagThatTail@Me.com>

* Better comment

Signed-off-by: Amy Aronsohn <WagThatTail@Me.com>
This commit is contained in:
Amy Aronsohn 2018-10-13 21:30:13 -07:00 committed by Craig Peterson
parent cf7f199462
commit 4e417eaa06
2 changed files with 39 additions and 16 deletions

View file

@ -17,10 +17,10 @@
"domain": "$DO_DOMAIN"
},
"DNSIMPLE": {
"COMMENT": "16/17: no ns records managable. Not even for subdomains.",
"COMMENT": "20-22: no ns records managable. Not even for subdomains.",
"baseurl": "https://api.sandbox.dnsimple.com",
"domain": "$DNSIMPLE_DOMAIN",
"knownFailures": "18,19,20",
"knownFailures": "20,21,22",
"token": "$DNSIMPLE_TOKEN"
},
"GANDI": {

View file

@ -90,6 +90,10 @@ func (c *DnsimpleApi) GetDomainCorrections(dc *models.DomainConfig) ([]*models.C
if err := rec.SetTargetMX(uint16(r.Priority), r.Content); err != nil {
panic(errors.Wrap(err, "unparsable record received from dnsimple"))
}
case "SRV":
if err := rec.SetTargetSRVPriorityString(uint16(r.Priority), r.Content); err != nil {
panic(errors.Wrap(err, "unparsable record received from dnsimple"))
}
default:
if err := rec.PopulateFromString(r.Type, r.Content, dc.Name); err != nil {
panic(errors.Wrap(err, "unparsable record received from dnsimple"))
@ -98,20 +102,14 @@ func (c *DnsimpleApi) GetDomainCorrections(dc *models.DomainConfig) ([]*models.C
actual = append(actual, rec)
}
removeOtherNS(dc)
// dc.Filter(func(r *models.RecordConfig) bool {
// if r.Type == "CAA" || r.Type == "SRV" {
// r.MergeToTarget()
// }
// return true
// })
// Normalize
models.PostProcessRecords(actual)
differ := diff.New(dc)
_, create, delete, modify := differ.IncrementalDiff(actual)
_, create, del, modify := differ.IncrementalDiff(actual)
for _, del := range delete {
for _, del := range del {
rec := del.Existing.Original.(dnsimpleapi.ZoneRecord)
corrections = append(corrections, &models.Correction{
Msg: del.String(),
@ -129,10 +127,10 @@ func (c *DnsimpleApi) GetDomainCorrections(dc *models.DomainConfig) ([]*models.C
for _, mod := range modify {
old := mod.Existing.Original.(dnsimpleapi.ZoneRecord)
new := mod.Desired
rec := mod.Desired
corrections = append(corrections, &models.Correction{
Msg: mod.String(),
F: c.updateRecordFunc(&old, new, dc.Name),
F: c.updateRecordFunc(&old, rec, dc.Name),
})
}
@ -283,9 +281,9 @@ func (c *DnsimpleApi) createRecordFunc(rc *models.RecordConfig, domainName strin
record := dnsimpleapi.ZoneRecord{
Name: rc.GetLabel(),
Type: rc.Type,
Content: rc.GetTargetCombined(),
Content: getTargetRecordContent(rc),
TTL: int(rc.TTL),
Priority: int(rc.MxPreference),
Priority: getTargetRecordPriority(rc),
}
_, err = client.Zones.CreateRecord(accountID, domainName, record)
if err != nil {
@ -329,9 +327,9 @@ func (c *DnsimpleApi) updateRecordFunc(old *dnsimpleapi.ZoneRecord, rc *models.R
record := dnsimpleapi.ZoneRecord{
Name: rc.GetLabel(),
Type: rc.Type,
Content: rc.GetTargetCombined(),
Content: getTargetRecordContent(rc),
TTL: int(rc.TTL),
Priority: int(rc.MxPreference),
Priority: getTargetRecordPriority(rc),
}
_, err = client.Zones.UpdateRecord(accountID, domainName, old.ID, record)
@ -384,3 +382,28 @@ func removeOtherNS(dc *models.DomainConfig) {
}
dc.Records = newList
}
// Return the correct combined content for all special record types, Target for everything else
// Using RecordConfig.GetTargetCombined returns priority in the string, which we do not allow
func getTargetRecordContent(rc *models.RecordConfig) string {
switch rtype := rc.Type; rtype {
case "CAA":
return rc.GetTargetCombined()
case "SRV":
return fmt.Sprintf("%d %d %s", rc.SrvWeight, rc.SrvPort, rc.GetTargetField())
default:
return rc.GetTargetField()
}
}
// Return the correct priority for the record type, 0 for records without priority
func getTargetRecordPriority(rc *models.RecordConfig) int {
switch rtype := rc.Type; rtype {
case "MX":
return int(rc.MxPreference)
case "SRV":
return int(rc.SrvPriority)
default:
return 0
}
}