diff --git a/commands/getZones.go b/commands/getZones.go index 1d6a0e8ec2..aad4394147 100644 --- a/commands/getZones.go +++ b/commands/getZones.go @@ -286,8 +286,12 @@ func GetZone(args GetZoneArgs) error { } } + ty := rec.Type + if rec.Type == "UNKNOWN" { + ty = rec.UnknownTypeName + } fmt.Fprintf(w, "%s\t%s\t%d\tIN\t%s\t%s%s\n", - rec.NameFQDN, rec.Name, rec.TTL, rec.Type, rec.GetTargetCombinedFunc(nil), cfproxy) + rec.NameFQDN, rec.Name, rec.TTL, ty, rec.GetTargetCombinedFunc(nil), cfproxy) } default: @@ -363,6 +367,8 @@ func formatDsl(zonename string, rec *models.RecordConfig, defaultTTL uint32) str target = `"` + target + `"` case "R53_ALIAS": return makeR53alias(rec, ttl) + case "UNKNOWN": + return makeUknown(rec, ttl) default: target = `"` + target + `"` } @@ -399,3 +405,7 @@ func makeR53alias(rec *models.RecordConfig, ttl uint32) string { } return rec.Type + "(" + strings.Join(items, ", ") + ")" } + +func makeUknown(rc *models.RecordConfig, ttl uint32) string { + return fmt.Sprintf(`// %s("%s")`, rc.UnknownTypeName, rc.GetTargetField()) +} diff --git a/models/record.go b/models/record.go index d49078b12c..4bc008c9d5 100644 --- a/models/record.go +++ b/models/record.go @@ -93,7 +93,7 @@ type RecordConfig struct { Metadata map[string]string `json:"meta,omitempty"` Original interface{} `json:"-"` // Store pointer to provider-specific record object. Used in diffing. - // If you add a field to this struct, also add it to the list on MarshalJSON. + // If you add a field to this struct, also add it to the list in the UnmarshalJSON function. MxPreference uint16 `json:"mxpreference,omitempty"` SrvPriority uint16 `json:"srvpriority,omitempty"` SrvWeight uint16 `json:"srvweight,omitempty"` @@ -129,6 +129,7 @@ type RecordConfig struct { TlsaMatchingType uint8 `json:"tlsamatchingtype,omitempty"` R53Alias map[string]string `json:"r53_alias,omitempty"` AzureAlias map[string]string `json:"azure_alias,omitempty"` + UnknownTypeName string `json:"unknown_type_name,omitempty"` } // MarshalJSON marshals RecordConfig. @@ -196,6 +197,7 @@ func (rc *RecordConfig) UnmarshalJSON(b []byte) error { TlsaMatchingType uint8 `json:"tlsamatchingtype,omitempty"` R53Alias map[string]string `json:"r53_alias,omitempty"` AzureAlias map[string]string `json:"azure_alias,omitempty"` + UnknownTypeName string `json:"unknown_type_name,omitempty"` EnsureAbsent bool `json:"ensure_absent,omitempty"` // Override NO_PURGE and delete this record @@ -318,6 +320,8 @@ func (rc *RecordConfig) ToComparableNoTTL() string { r := txtutil.EncodeQuoted(rc.target) //fmt.Fprintf(os.Stdout, "DEBUG: ToComNoTTL cmp txts=%s q=%q\n", r, r) return r + case "UNKNOWN": + return fmt.Sprintf("rtype=%s rdata=%s", rc.UnknownTypeName, rc.target) } return rc.GetTargetCombined() } diff --git a/models/t_parse.go b/models/t_parse.go index 10d9c94dff..22f99fe064 100644 --- a/models/t_parse.go +++ b/models/t_parse.go @@ -104,8 +104,8 @@ func (rc *RecordConfig) PopulateFromStringFunc(rtype, contents, origin string, t case "TLSA": return rc.SetTargetTLSAString(contents) default: - return fmt.Errorf("unknown rtype (%s) when parsing (%s) domain=(%s)", - rtype, contents, origin) + //return fmt.Errorf("unknown rtype (%s) when parsing (%s) domain=(%s)", rtype, contents, origin) + return MakeUnknown(rc, rtype, contents, origin) } } diff --git a/models/target.go b/models/target.go index d59c598ac2..4194b03342 100644 --- a/models/target.go +++ b/models/target.go @@ -45,6 +45,7 @@ func (rc *RecordConfig) GetTargetCombinedFunc(encodeFn func(s string) string) st // WARNING: How TXT records are handled is buggy but we can't change it because // code depends on the bugs. Use Get GetTargetCombinedFunc() instead. func (rc *RecordConfig) GetTargetCombined() string { + // Pseudo records: if _, ok := dns.StringToType[rc.Type]; !ok { switch rc.Type { // #rtype_variations @@ -60,7 +61,10 @@ func (rc *RecordConfig) GetTargetCombined() string { } } + // Everything else switch rc.Type { + case "UNKNOWN": + return fmt.Sprintf("rtype=%s rdata=%s", rc.UnknownTypeName, rc.target) case "TXT": return rc.zoneFileQuoted() case "SOA": diff --git a/models/unknown.go b/models/unknown.go new file mode 100644 index 0000000000..71dfb696ac --- /dev/null +++ b/models/unknown.go @@ -0,0 +1,9 @@ +package models + +func MakeUnknown(rc *RecordConfig, rtype string, contents string, origin string) error { + rc.Type = "UNKNOWN" + rc.UnknownTypeName = rtype + rc.target = contents + + return nil +} diff --git a/pkg/prettyzone/prettyzone.go b/pkg/prettyzone/prettyzone.go index 481fb8ae79..901b6a1c81 100644 --- a/pkg/prettyzone/prettyzone.go +++ b/pkg/prettyzone/prettyzone.go @@ -137,6 +137,9 @@ func (z *ZoneGenData) generateZoneFileHelper(w io.Writer) error { // type typeStr := rr.Type + if rr.Type == "UNKNOWN" { + typeStr = rr.UnknownTypeName + } // the remaining line target := rr.GetTargetCombinedFunc(txtutil.EncodeQuoted)