mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-12-26 17:50:55 +08:00
Mark RecordConfig when Target contains multiple embedded fields.
This commit is contained in:
parent
28d0b0c5a0
commit
caa71c4031
3 changed files with 31 additions and 8 deletions
|
@ -72,10 +72,16 @@ type RecordConfig struct {
|
||||||
SrvWeight uint16 `json:"srvweight,omitempty"`
|
SrvWeight uint16 `json:"srvweight,omitempty"`
|
||||||
SrvPort uint16 `json:"srvport,omitempty"`
|
SrvPort uint16 `json:"srvport,omitempty"`
|
||||||
|
|
||||||
|
CombinedTarget bool `json:"omit"`
|
||||||
|
|
||||||
Original interface{} `json:"-"` // Store pointer to provider-specific record object. Used in diffing.
|
Original interface{} `json:"-"` // Store pointer to provider-specific record object. Used in diffing.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RecordConfig) String() (content string) {
|
func (r *RecordConfig) String() (content string) {
|
||||||
|
if r.CombinedTarget {
|
||||||
|
return r.Target
|
||||||
|
}
|
||||||
|
|
||||||
switch r.Type {
|
switch r.Type {
|
||||||
case "A", "AAAA", "PTR":
|
case "A", "AAAA", "PTR":
|
||||||
content = fmt.Sprintf("%s %s %s %d", r.Type, r.NameFQDN, r.Target, r.TTL)
|
content = fmt.Sprintf("%s %s %s %d", r.Type, r.NameFQDN, r.Target, r.TTL)
|
||||||
|
@ -94,6 +100,9 @@ func (r *RecordConfig) String() (content string) {
|
||||||
|
|
||||||
// Content combines Target and other fields into one string.
|
// Content combines Target and other fields into one string.
|
||||||
func (r *RecordConfig) Content() string {
|
func (r *RecordConfig) Content() string {
|
||||||
|
if r.CombinedTarget {
|
||||||
|
return r.Target
|
||||||
|
}
|
||||||
|
|
||||||
// If this is a pseudo record, just return the target.
|
// If this is a pseudo record, just return the target.
|
||||||
if _, ok := dns.StringToType[r.Type]; !ok {
|
if _, ok := dns.StringToType[r.Type]; !ok {
|
||||||
|
@ -115,6 +124,11 @@ func (r *RecordConfig) Content() string {
|
||||||
|
|
||||||
// MergeToTarget combines "extra" fields into .Target, and zeros the merged fields.
|
// MergeToTarget combines "extra" fields into .Target, and zeros the merged fields.
|
||||||
func (r *RecordConfig) MergeToTarget() {
|
func (r *RecordConfig) MergeToTarget() {
|
||||||
|
if r.CombinedTarget {
|
||||||
|
pm := strings.Join([]string{"MergeToTarget: Already collapsed: ", r.Name, r.Target}, " ")
|
||||||
|
panic(pm)
|
||||||
|
}
|
||||||
|
|
||||||
// Merge "extra" fields into the Target.
|
// Merge "extra" fields into the Target.
|
||||||
r.Target = r.Content()
|
r.Target = r.Content()
|
||||||
|
|
||||||
|
@ -123,6 +137,8 @@ func (r *RecordConfig) MergeToTarget() {
|
||||||
r.SrvPriority = 0
|
r.SrvPriority = 0
|
||||||
r.SrvWeight = 0
|
r.SrvWeight = 0
|
||||||
r.SrvPort = 0
|
r.SrvPort = 0
|
||||||
|
|
||||||
|
r.CombinedTarget = true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert RecordConfig -> dns.RR.
|
/// Convert RecordConfig -> dns.RR.
|
||||||
|
@ -259,8 +275,13 @@ func (dc *DomainConfig) Punycode() error {
|
||||||
func (dc *DomainConfig) CombineMXs() {
|
func (dc *DomainConfig) CombineMXs() {
|
||||||
for _, rec := range dc.Records {
|
for _, rec := range dc.Records {
|
||||||
if rec.Type == "MX" {
|
if rec.Type == "MX" {
|
||||||
|
if rec.CombinedTarget {
|
||||||
|
pm := strings.Join([]string{"CombineMXs: Already collapsed: ", rec.Name, rec.Target}, " ")
|
||||||
|
panic(pm)
|
||||||
|
}
|
||||||
rec.Target = fmt.Sprintf("%d %s", rec.MxPreference, rec.Target)
|
rec.Target = fmt.Sprintf("%d %s", rec.MxPreference, rec.Target)
|
||||||
rec.MxPreference = 0
|
rec.MxPreference = 0
|
||||||
|
rec.CombinedTarget = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,10 +116,11 @@ func (g *gcloud) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correc
|
||||||
oldRRs[keyFor(set)] = set
|
oldRRs[keyFor(set)] = set
|
||||||
for _, rec := range set.Rrdatas {
|
for _, rec := range set.Rrdatas {
|
||||||
r := &models.RecordConfig{
|
r := &models.RecordConfig{
|
||||||
NameFQDN: nameWithoutDot,
|
NameFQDN: nameWithoutDot,
|
||||||
Type: set.Type,
|
Type: set.Type,
|
||||||
Target: rec,
|
Target: rec,
|
||||||
TTL: uint32(set.Ttl),
|
TTL: uint32(set.Ttl),
|
||||||
|
CombinedTarget: true,
|
||||||
}
|
}
|
||||||
existingRecords = append(existingRecords, r)
|
existingRecords = append(existingRecords, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,10 +133,11 @@ func (r *route53Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
r := &models.RecordConfig{
|
r := &models.RecordConfig{
|
||||||
NameFQDN: unescape(set.Name),
|
NameFQDN: unescape(set.Name),
|
||||||
Type: *set.Type,
|
Type: *set.Type,
|
||||||
Target: *rec.Value,
|
Target: *rec.Value,
|
||||||
TTL: uint32(*set.TTL),
|
TTL: uint32(*set.TTL),
|
||||||
|
CombinedTarget: true,
|
||||||
}
|
}
|
||||||
existingRecords = append(existingRecords, r)
|
existingRecords = append(existingRecords, r)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue