mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-02-23 15:12:57 +08:00
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:
parent
cf7f199462
commit
4e417eaa06
2 changed files with 39 additions and 16 deletions
|
@ -17,10 +17,10 @@
|
||||||
"domain": "$DO_DOMAIN"
|
"domain": "$DO_DOMAIN"
|
||||||
},
|
},
|
||||||
"DNSIMPLE": {
|
"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",
|
"baseurl": "https://api.sandbox.dnsimple.com",
|
||||||
"domain": "$DNSIMPLE_DOMAIN",
|
"domain": "$DNSIMPLE_DOMAIN",
|
||||||
"knownFailures": "18,19,20",
|
"knownFailures": "20,21,22",
|
||||||
"token": "$DNSIMPLE_TOKEN"
|
"token": "$DNSIMPLE_TOKEN"
|
||||||
},
|
},
|
||||||
"GANDI": {
|
"GANDI": {
|
||||||
|
|
|
@ -90,6 +90,10 @@ func (c *DnsimpleApi) GetDomainCorrections(dc *models.DomainConfig) ([]*models.C
|
||||||
if err := rec.SetTargetMX(uint16(r.Priority), r.Content); err != nil {
|
if err := rec.SetTargetMX(uint16(r.Priority), r.Content); err != nil {
|
||||||
panic(errors.Wrap(err, "unparsable record received from dnsimple"))
|
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:
|
default:
|
||||||
if err := rec.PopulateFromString(r.Type, r.Content, dc.Name); err != nil {
|
if err := rec.PopulateFromString(r.Type, r.Content, dc.Name); err != nil {
|
||||||
panic(errors.Wrap(err, "unparsable record received from dnsimple"))
|
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)
|
actual = append(actual, rec)
|
||||||
}
|
}
|
||||||
removeOtherNS(dc)
|
removeOtherNS(dc)
|
||||||
// dc.Filter(func(r *models.RecordConfig) bool {
|
|
||||||
// if r.Type == "CAA" || r.Type == "SRV" {
|
|
||||||
// r.MergeToTarget()
|
|
||||||
// }
|
|
||||||
// return true
|
|
||||||
// })
|
|
||||||
|
|
||||||
// Normalize
|
// Normalize
|
||||||
models.PostProcessRecords(actual)
|
models.PostProcessRecords(actual)
|
||||||
|
|
||||||
differ := diff.New(dc)
|
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)
|
rec := del.Existing.Original.(dnsimpleapi.ZoneRecord)
|
||||||
corrections = append(corrections, &models.Correction{
|
corrections = append(corrections, &models.Correction{
|
||||||
Msg: del.String(),
|
Msg: del.String(),
|
||||||
|
@ -129,10 +127,10 @@ func (c *DnsimpleApi) GetDomainCorrections(dc *models.DomainConfig) ([]*models.C
|
||||||
|
|
||||||
for _, mod := range modify {
|
for _, mod := range modify {
|
||||||
old := mod.Existing.Original.(dnsimpleapi.ZoneRecord)
|
old := mod.Existing.Original.(dnsimpleapi.ZoneRecord)
|
||||||
new := mod.Desired
|
rec := mod.Desired
|
||||||
corrections = append(corrections, &models.Correction{
|
corrections = append(corrections, &models.Correction{
|
||||||
Msg: mod.String(),
|
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{
|
record := dnsimpleapi.ZoneRecord{
|
||||||
Name: rc.GetLabel(),
|
Name: rc.GetLabel(),
|
||||||
Type: rc.Type,
|
Type: rc.Type,
|
||||||
Content: rc.GetTargetCombined(),
|
Content: getTargetRecordContent(rc),
|
||||||
TTL: int(rc.TTL),
|
TTL: int(rc.TTL),
|
||||||
Priority: int(rc.MxPreference),
|
Priority: getTargetRecordPriority(rc),
|
||||||
}
|
}
|
||||||
_, err = client.Zones.CreateRecord(accountID, domainName, record)
|
_, err = client.Zones.CreateRecord(accountID, domainName, record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -329,9 +327,9 @@ func (c *DnsimpleApi) updateRecordFunc(old *dnsimpleapi.ZoneRecord, rc *models.R
|
||||||
record := dnsimpleapi.ZoneRecord{
|
record := dnsimpleapi.ZoneRecord{
|
||||||
Name: rc.GetLabel(),
|
Name: rc.GetLabel(),
|
||||||
Type: rc.Type,
|
Type: rc.Type,
|
||||||
Content: rc.GetTargetCombined(),
|
Content: getTargetRecordContent(rc),
|
||||||
TTL: int(rc.TTL),
|
TTL: int(rc.TTL),
|
||||||
Priority: int(rc.MxPreference),
|
Priority: getTargetRecordPriority(rc),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = client.Zones.UpdateRecord(accountID, domainName, old.ID, record)
|
_, err = client.Zones.UpdateRecord(accountID, domainName, old.ID, record)
|
||||||
|
@ -384,3 +382,28 @@ func removeOtherNS(dc *models.DomainConfig) {
|
||||||
}
|
}
|
||||||
dc.Records = newList
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue