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

Refactor RecordConfig: Add getters/setters (#314)

* Replace RecordConfig.Name and .NameFQDN with getters and setters.
* Replace RecordConfig.Target with getters and setters.
* Eliminate the CombinedTarget concept.
* Add RecordConfig.PopulateFromString to reduce code in all providers.
* encode and decode name.com txt records (#315)
* Replace fmt.Errorf with errors.Errorf
This commit is contained in:
Tom Limoncelli
2018-02-15 12:02:50 -05:00
committed by GitHub
parent 324b1ea930
commit de4455942b
37 changed files with 1237 additions and 965 deletions

View File

@@ -197,10 +197,11 @@ func toRc(dc *models.DomainConfig, r *godo.DomainRecord) *models.RecordConfig {
target = dc.Name
}
target = dnsutil.AddOrigin(target+".", dc.Name)
// FIXME(tlim): The AddOrigin should be a no-op.
// Test whether or not it is actually needed.
}
return &models.RecordConfig{
NameFQDN: name,
t := &models.RecordConfig{
Type: r.Type,
Target: target,
TTL: uint32(r.TTL),
@@ -210,25 +211,37 @@ func toRc(dc *models.DomainConfig, r *godo.DomainRecord) *models.RecordConfig {
SrvPort: uint16(r.Port),
Original: r,
}
t.SetLabelFromFQDN(name, dc.Name)
switch rtype := r.Type; rtype {
case "TXT":
t.SetTargetTXTString(target)
default:
// nothing additional required
}
return t
}
func toReq(dc *models.DomainConfig, rc *models.RecordConfig) *godo.DomainRecordEditRequest {
// DO wants the short name, e.g. @
name := dnsutil.TrimDomainName(rc.NameFQDN, dc.Name)
name := rc.GetLabel() // DO wants the short name or "@" for apex.
target := rc.GetTargetField() // DO uses the target field only for a single value
priority := 0 // DO uses the same property for MX and SRV priority
// DO uses the same property for MX and SRV priority
priority := 0
switch rc.Type { // #rtype_variations
case "MX":
priority = int(rc.MxPreference)
case "SRV":
priority = int(rc.SrvPriority)
case "TXT":
// TXT records are the one place where DO combines many items into one field.
target = rc.GetTargetCombined()
default:
// no action required
}
return &godo.DomainRecordEditRequest{
Type: rc.Type,
Name: name,
Data: rc.Target,
Data: target,
TTL: int(rc.TTL),
Priority: priority,
Port: int(rc.SrvPort),