From 29dbdbbd5cc978f75cae0703eab0a553d665dd72 Mon Sep 17 00:00:00 2001 From: Thomas Limoncelli Date: Sun, 30 Nov 2025 20:06:03 -0500 Subject: [PATCH] fixup! --- pkg/rtype/rp.go | 15 +++++++++++---- pkg/rtypecontrol/import.go | 9 ++++++--- pkg/rtypecontrol/rtypecontrol.go | 1 + .../rtypes/cfsingleredirect/cfredirect.go | 12 ++++++------ .../rtypes/cfsingleredirect/cfsingleredirect.go | 6 +++--- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/pkg/rtype/rp.go b/pkg/rtype/rp.go index f133629f8..6bb0681e6 100644 --- a/pkg/rtype/rp.go +++ b/pkg/rtype/rp.go @@ -19,20 +19,27 @@ func (handle *RP) Name() string { return "RP" } +// FromArgs fills in the RecordConfig from []any, which is typically from a parsed config file. func (handle *RP) FromArgs(dc *models.DomainConfig, rec *models.RecordConfig, args []any) error { if err := rtypecontrol.PaveArgs(args[1:], "ss"); err != nil { return err } - rec.F = &RP{ + fields := &RP{ dns.RP{ Mbox: args[1].(string), Txt: args[2].(string), }, } - // TODO: Generate friendly Comparable and ZonefilePartial values. - rec.Comparable = rec.F.(*RP).Mbox + " " + rec.F.(*RP).Txt - rec.ZonefilePartial = rec.Comparable + return handle.FromStruct(dc, rec, args[0].(string), fields) +} + +// FromStruct fills in the RecordConfig from a struct, typically from an API response. +func (handle *RP) FromStruct(dc *models.DomainConfig, rec *models.RecordConfig, name string, fields any) error { + rec.F = fields + + rec.ZonefilePartial = rec.GetTargetRFC1035Quoted() + rec.Comparable = rec.ZonefilePartial return nil } diff --git a/pkg/rtypecontrol/import.go b/pkg/rtypecontrol/import.go index cd9e50125..aba4cece2 100644 --- a/pkg/rtypecontrol/import.go +++ b/pkg/rtypecontrol/import.go @@ -5,7 +5,6 @@ import ( "github.com/StackExchange/dnscontrol/v4/models" "github.com/StackExchange/dnscontrol/v4/pkg/domaintags" - "github.com/miekg/dns" "github.com/miekg/dns/dnsutil" ) @@ -74,8 +73,12 @@ func NewRecordConfigFromStruct(name string, ttl uint32, t string, fields any, dc } setRecordNames(rec, dc, name) - // Fill in the .F/.Fields* fields. - err := Func[t].FromArgs(dc, rec, []any{name, fields.(*dns.RP).Mbox, fields.(*dns.RP).Txt}) + // // Fill in the .F/.Fields* fields. + // err := Func[t].FromArgs(dc, rec, []any{name, fields.(*dns.RP).Mbox, fields.(*dns.RP).Txt}) + // if err != nil { + // return nil, err + // } + err := Func[t].FromStruct(dc, rec, name, fields) if err != nil { return nil, err } diff --git a/pkg/rtypecontrol/rtypecontrol.go b/pkg/rtypecontrol/rtypecontrol.go index c2a916d22..ebfbbd957 100644 --- a/pkg/rtypecontrol/rtypecontrol.go +++ b/pkg/rtypecontrol/rtypecontrol.go @@ -16,6 +16,7 @@ type RType interface { // RecordConfig factory. Updates a RecordConfig's fields based on args. FromArgs(*models.DomainConfig, *models.RecordConfig, []any) error + FromStruct(*models.DomainConfig, *models.RecordConfig, string, any) error CopyToLegacyFields(*models.RecordConfig) } diff --git a/providers/cloudflare/rtypes/cfsingleredirect/cfredirect.go b/providers/cloudflare/rtypes/cfsingleredirect/cfredirect.go index b2e33e0e5..2f47e3ae9 100644 --- a/providers/cloudflare/rtypes/cfsingleredirect/cfredirect.go +++ b/providers/cloudflare/rtypes/cfsingleredirect/cfredirect.go @@ -24,9 +24,9 @@ func (handle *CfRedirect) FromArgs(dc *models.DomainConfig, rec *models.RecordCo return FromArgs_helper(dc, rec, args, 301) } -// func (handle *CfRedirect) FromStruct(dc *models.DomainConfig, rec *models.RecordConfig, fields any) error { -// panic("CF_REDIRECT: FromStruct not implemented") -// } +func (handle *CfRedirect) FromStruct(dc *models.DomainConfig, rec *models.RecordConfig, name string, fields any) error { + panic("CF_REDIRECT: FromStruct not implemented") +} func (handle *CfRedirect) CopyToLegacyFields(rec *models.RecordConfig) { // Nothing needs to be copied. The CLOUDFLAREAPI_SINGLE_REDIRECT FromArgs copies everything needed. @@ -43,9 +43,9 @@ func (handle *CfTempRedirect) FromArgs(dc *models.DomainConfig, rec *models.Reco return FromArgs_helper(dc, rec, args, 302) } -// func (handle *CfTempRedirect) FromStruct(dc *models.DomainConfig, rec *models.RecordConfig, fields any) error { -// panic("CF_TEMP_REDIRECT: FromStruct not implemented") -// } +func (handle *CfTempRedirect) FromStruct(dc *models.DomainConfig, rec *models.RecordConfig, name string, fields any) error { + panic("CF_TEMP_REDIRECT: FromStruct not implemented") +} func (handle *CfTempRedirect) CopyToLegacyFields(rec *models.RecordConfig) { // Nothing needs to be copied. The CLOUDFLAREAPI_SINGLE_REDIRECT FromArgs copies everything needed. diff --git a/providers/cloudflare/rtypes/cfsingleredirect/cfsingleredirect.go b/providers/cloudflare/rtypes/cfsingleredirect/cfsingleredirect.go index 17bdebaca..bf556d268 100644 --- a/providers/cloudflare/rtypes/cfsingleredirect/cfsingleredirect.go +++ b/providers/cloudflare/rtypes/cfsingleredirect/cfsingleredirect.go @@ -76,9 +76,9 @@ func (handle *SingleRedirectConfig) FromArgs(dc *models.DomainConfig, rec *model return nil } -// func (handle *SingleRedirectConfig) FromStruct(dc *models.DomainConfig, rec *models.RecordConfig, fields any) error { -// panic("CLOUDFLAREAPI_SINGLE_REDIRECT: FromStruct not implemented") -// } +func (handle *SingleRedirectConfig) FromStruct(dc *models.DomainConfig, rec *models.RecordConfig, name string, fields any) error { + panic("CLOUDFLAREAPI_SINGLE_REDIRECT: FromStruct not implemented") +} // targetFromRaw create the display text used for a normal Redirect. func targetFromRaw(name string, code uint16, when, then string) string {