diff --git a/models/t_parse.go b/models/t_parse.go index 9f8544f45..8d8c47531 100644 --- a/models/t_parse.go +++ b/models/t_parse.go @@ -59,7 +59,9 @@ func (rc *RecordConfig) PopulateFromStringFunc(rtype, contents, origin string, t return fmt.Errorf("assertion failed: rtype already set (%s) (%s)", rtype, rc.Type) } - switch rc.Type = rtype; rtype { // #rtype_variations + rc.Type = rtype + + switch rtype { // #rtype_variations case "A": ip := net.ParseIP(contents) if ip == nil || ip.To4() == nil { diff --git a/pkg/rtypecontrol/import.go b/pkg/rtypecontrol/import.go index ddc43bdc4..c59d4582d 100644 --- a/pkg/rtypecontrol/import.go +++ b/pkg/rtypecontrol/import.go @@ -60,19 +60,19 @@ func NewRecordConfigFromRaw(t string, args []any, dc *models.DomainConfig) (*mod return rec, nil } -func stringifyMetas(metas []map[string]any) map[string]string { - result := make(map[string]string) - for _, m := range metas { - for mk, mv := range m { - if v, ok := mv.(string); ok { - result[mk] = v // Already a string. No new malloc. - } else { - result[mk] = fmt.Sprintf("%v", mv) - } - } - } - return result -} +// func stringifyMetas(metas []map[string]any) map[string]string { +// result := make(map[string]string) +// for _, m := range metas { +// for mk, mv := range m { +// if v, ok := mv.(string); ok { +// result[mk] = v // Already a string. No new malloc. +// } else { +// result[mk] = fmt.Sprintf("%v", mv) +// } +// } +// } +// return result +// } func setRecordNames(rec *models.RecordConfig, dc *models.DomainConfig, n string) { diff --git a/pkg/rtypecontrol/rtypecontrol.go b/pkg/rtypecontrol/rtypecontrol.go index 7f101423d..09e702de1 100644 --- a/pkg/rtypecontrol/rtypecontrol.go +++ b/pkg/rtypecontrol/rtypecontrol.go @@ -8,7 +8,7 @@ import ( ) // backwards compatibility: -var validTypes = map[string]struct{}{} +//var validTypes = map[string]struct{}{} type RType interface { // Returns the name of the rtype ("A", "MX", etc.) @@ -16,9 +16,6 @@ type RType interface { // RecordConfig factory. Updates a RecordConfig's fields based on args. FromArgs(*models.DomainConfig, *models.RecordConfig, []any) error - - // Returns a string representation of the record in RFC1038 format. - // AsRFC1038String([]string) (string, error) } // Map of registered rtypes. diff --git a/providers/cloudflare/rtypes/cfsingleredirect/cfredirect.go b/providers/cloudflare/rtypes/cfsingleredirect/cfredirect.go index dcdc15059..47db6c167 100644 --- a/providers/cloudflare/rtypes/cfsingleredirect/cfredirect.go +++ b/providers/cloudflare/rtypes/cfsingleredirect/cfredirect.go @@ -78,6 +78,6 @@ func FromArgs_helper(dc *models.DomainConfig, rec *models.RecordConfig, args []a if err != nil { return err } - rec.SetTarget(target) // Overwrite target to old-style for compatibility + _ = rec.SetTarget(target) // Overwrite target to old-style for compatibility return nil } diff --git a/providers/cloudflare/rtypes/cfsingleredirect/cfsingleredirect.go b/providers/cloudflare/rtypes/cfsingleredirect/cfsingleredirect.go index b1485b9b9..8fc1e0c3b 100644 --- a/providers/cloudflare/rtypes/cfsingleredirect/cfsingleredirect.go +++ b/providers/cloudflare/rtypes/cfsingleredirect/cfsingleredirect.go @@ -32,34 +32,39 @@ func (handle *SingleRedirectConfig) Name() string { func (handle *SingleRedirectConfig) FromArgs(dc *models.DomainConfig, rec *models.RecordConfig, args []any) error { //fmt.Printf("DEBUG: CLOUDFLAREAPI_SINGLE_REDIRECT FromArgs called with args=%+v\n", args) + // Pave the args to be the expected types. if err := rtypecontrol.PaveArgs(args, "siss"); err != nil { return err } // Unpack the args: - var name, when, then string - var code uint16 + var name = args[0].(string) + var code = args[1].(uint16) + var when = args[2].(string) + var then = args[3].(string) - name = args[0].(string) - code = args[1].(uint16) + // Validate if code != 301 && code != 302 && code != 303 && code != 307 && code != 308 { return fmt.Errorf("%s: code (%03d) is not 301,302,303,307,308", rec.FilePos, code) } - when = args[2].(string) - then = args[3].(string) - display := targetFromRaw(name, code, when, then) + // Calclate the Comparable and ZonefilePartial values: + display := targetFromRaw(name, code, when, then) + rec.Comparable = display + rec.ZonefilePartial = display + + // Set the fields rec.F = &SingleRedirectConfig{ - Code: code, - // + Code: code, SRName: name, SRWhen: when, SRThen: then, SRDisplay: display, } - //rec.Name = name + // Usually these fields do not need to be changed. The caller sets appropriate values. + // But Cloudflare Single Redirects always use "@" as the name and TTL=1. We override here. rec.Name = "@" rec.NameRaw = "@" rec.NameUnicode = "@" @@ -67,10 +72,9 @@ func (handle *SingleRedirectConfig) FromArgs(dc *models.DomainConfig, rec *model rec.NameFQDNRaw = dc.NameRaw rec.NameFQDNUnicode = dc.NameUnicode rec.TTL = 1 - rec.Comparable = display - rec.ZonefilePartial = display - _ = rec.SetTarget(name) + // Fill in the legacy fields: + handle.CopyToLegacyFields(rec) return nil } @@ -84,12 +88,9 @@ func targetFromRaw(name string, code uint16, when, then string) string { ) } -func (handle *SingleRedirectConfig) AsRFC1038String(*models.RecordConfig) string { - return handle.SRDisplay -} - func (handle *SingleRedirectConfig) CopyToLegacyFields(rec *models.RecordConfig) { - rec.SetTarget(handle.SRDisplay) + //rec.SetTarget(handle.SRDisplay) + _ = rec.SetTarget(handle.SRName) } //func (handle *SingleRedirectConfig) IDNFields(argsRaw) (argsIDN, argsUnicode, error) {}