From 1469b7cca64c8a446c5a22597c1d5970a3c2868b Mon Sep 17 00:00:00 2001 From: Connor McFarlane Date: Tue, 16 Jan 2024 12:44:04 +0000 Subject: [PATCH 1/3] Enable CanUseLOC for CLOUDFLAREAPI --- commands/types/dnscontrol.d.ts | 8 ++++---- documentation/providers.md | 2 +- providers/cloudflare/cloudflareProvider.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/commands/types/dnscontrol.d.ts b/commands/types/dnscontrol.d.ts index 76a8a10af1..5df946bfb5 100644 --- a/commands/types/dnscontrol.d.ts +++ b/commands/types/dnscontrol.d.ts @@ -363,7 +363,7 @@ declare function AZURE_ALIAS(name: string, type: "A" | "AAAA" | "CNAME", target: * ); * ``` * - * DNSControl contains a [`CAA_BUILDER`](../record/CAA_BUILDER.md) which can be used to simply create `CAA()` records for your domains. Instead of creating each CAA record individually, you can simply configure your report mail address, the authorized certificate authorities and the builder cares about the rest. + * DNSControl contains a [`CAA_BUILDER`](CAA_BUILDER.md) which can be used to simply create `CAA()` records for your domains. Instead of creating each CAA record individually, you can simply configure your report mail address, the authorized certificate authorities and the builder cares about the rest. * * @see https://docs.dnscontrol.org/language-reference/domain-modifiers/caa */ @@ -2230,9 +2230,9 @@ declare function PANIC(message: string): never; * of `REV("1.2.3.4")` is `4.3.2.1.in-addr.arpa.`, which means the following * are all equivalent: * - * * `PTR(REV("1.2.3.4"), ` - * * `PTR("4.3.2.1.in-addr.arpa."), ` - * * `PTR("4.3",` // Assuming the domain is `2.1.in-addr.arpa` + * * `PTR(REV("1.2.3.4", ...` + * * `PTR("4.3.2.1.in-addr.arpa.", ...` + * * `PTR("4.3", ...` // Assuming the domain is `2.1.in-addr.arpa` * * All magic is RFC2317-aware. We use the first format listed in the * RFC for both [`REV()`](../global/REV.md) and `PTR()`. The format is diff --git a/documentation/providers.md b/documentation/providers.md index 9efd84de74..e8ebda9832 100644 --- a/documentation/providers.md +++ b/documentation/providers.md @@ -21,7 +21,7 @@ If a feature is definitively not supported for whatever reason, we would also li | [`AZURE_PRIVATE_DNS`](providers/azure_private_dns.md) | ✅ | ✅ | ❌ | ❌ | ❌ | ❔ | ❌ | ❌ | ✅ | ❔ | ✅ | ❌ | ❌ | ❔ | ❔ | ✅ | ✅ | ✅ | ✅ | | [`BIND`](providers/bind.md) | ✅ | ✅ | ❌ | ❔ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | | [`BUNNY_DNS`](providers/bunny_dns.md) | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | -| [`CLOUDFLAREAPI`](providers/cloudflareapi.md) | ✅ | ✅ | ❌ | ✅ | ✅ | ❔ | ❌ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ | ❔ | ❌ | ✅ | ✅ | ✅ | +| [`CLOUDFLAREAPI`](providers/cloudflareapi.md) | ✅ | ✅ | ❌ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ | ❔ | ❌ | ✅ | ✅ | ✅ | | [`CLOUDNS`](providers/cloudns.md) | ❌ | ✅ | ❌ | ✅ | ✅ | ❔ | ❌ | ❔ | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ | ✅ | ✅ | | [`CSCGLOBAL`](providers/cscglobal.md) | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | ❔ | ❔ | ✅ | ❔ | ❔ | ❔ | ❔ | ❔ | ❌ | ✅ | ✅ | | [`DESEC`](providers/desec.md) | ❌ | ✅ | ❌ | ❔ | ✅ | ✅ | ❔ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ✅ | ✅ | ✅ | diff --git a/providers/cloudflare/cloudflareProvider.go b/providers/cloudflare/cloudflareProvider.go index 8a502810b2..29390b2e67 100644 --- a/providers/cloudflare/cloudflareProvider.go +++ b/providers/cloudflare/cloudflareProvider.go @@ -43,7 +43,7 @@ var features = providers.DocumentationNotes{ providers.CanUseAlias: providers.Can("CF automatically flattens CNAME records into A records dynamically"), providers.CanUseCAA: providers.Can(), providers.CanUseDSForChildren: providers.Can(), - providers.CanUseLOC: providers.Cannot(), + providers.CanUseLOC: providers.Can(), providers.CanUseNAPTR: providers.Can(), providers.CanUsePTR: providers.Can(), providers.CanUseSRV: providers.Can(), From 6d98ae9f2e0432e7be52f5f66a25ef4e8c1caa7a Mon Sep 17 00:00:00 2001 From: Connor McFarlane Date: Tue, 16 Jan 2024 14:01:00 +0000 Subject: [PATCH 2/3] Pass original LOC values to Cloudflare API --- models/record.go | 50 +++++++++++++++++++++ models/t_loc.go | 16 +++++++ providers/cloudflare/cloudflareProvider.go | 52 +++++++++++++--------- providers/cloudflare/rest.go | 21 +++++++++ 4 files changed, 119 insertions(+), 20 deletions(-) diff --git a/models/record.go b/models/record.go index 4bc008c9d5..6521a5b55f 100644 --- a/models/record.go +++ b/models/record.go @@ -95,15 +95,19 @@ type RecordConfig struct { // 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"` SrvPort uint16 `json:"srvport,omitempty"` + CaaTag string `json:"caatag,omitempty"` CaaFlag uint8 `json:"caaflag,omitempty"` + DsKeyTag uint16 `json:"dskeytag,omitempty"` DsAlgorithm uint8 `json:"dsalgorithm,omitempty"` DsDigestType uint8 `json:"dsdigesttype,omitempty"` DsDigest string `json:"dsdigest,omitempty"` + LocVersion uint8 `json:"locversion,omitempty"` LocSize uint8 `json:"locsize,omitempty"` LocHorizPre uint8 `json:"lochorizpre,omitempty"` @@ -111,24 +115,45 @@ type RecordConfig struct { LocLatitude uint32 `json:"loclatitude,omitempty"` LocLongitude uint32 `json:"loclongitude,omitempty"` LocAltitude uint32 `json:"localtitude,omitempty"` + + LocLatDegrees uint8 `json:"loclatdegrees,omitempty"` + LocLatMinutes uint8 `json:"lotlatminutes,omitempty"` + LocLatSeconds float32 `json:"loclatseconds,omitempty"` + LocLatDirection string `json:"loclatdirection,omitempty"` + LocLongDegrees uint8 `json:"loclongdegrees,omitempty"` + LocLongMinutes uint8 `json:"lotlongminutes,omitempty"` + LocLongSeconds float32 `json:"loclongseconds,omitempty"` + LocLongDirection string `json:"loclongdirection,omitempty"` + + LocOrigAltitude int32 `json:"locorigaltitude,omitempty"` + LocOrigSize float32 `json:"locorigsize,omitempty"` + LocOrigHorizPre float32 `json:"locorighorizpre,omitempty"` + LocOrigVertPre float32 `json:"locorigvertpre,omitempty"` + NaptrOrder uint16 `json:"naptrorder,omitempty"` NaptrPreference uint16 `json:"naptrpreference,omitempty"` NaptrFlags string `json:"naptrflags,omitempty"` NaptrService string `json:"naptrservice,omitempty"` NaptrRegexp string `json:"naptrregexp,omitempty"` + SshfpAlgorithm uint8 `json:"sshfpalgorithm,omitempty"` SshfpFingerprint uint8 `json:"sshfpfingerprint,omitempty"` + SoaMbox string `json:"soambox,omitempty"` SoaSerial uint32 `json:"soaserial,omitempty"` SoaRefresh uint32 `json:"soarefresh,omitempty"` SoaRetry uint32 `json:"soaretry,omitempty"` SoaExpire uint32 `json:"soaexpire,omitempty"` SoaMinttl uint32 `json:"soaminttl,omitempty"` + TlsaUsage uint8 `json:"tlsausage,omitempty"` TlsaSelector uint8 `json:"tlsaselector,omitempty"` 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"` } @@ -163,15 +188,19 @@ func (rc *RecordConfig) UnmarshalJSON(b []byte) error { Original interface{} `json:"-"` // Store pointer to provider-specific record object. Used in diffing. MxPreference uint16 `json:"mxpreference,omitempty"` + SrvPriority uint16 `json:"srvpriority,omitempty"` SrvWeight uint16 `json:"srvweight,omitempty"` SrvPort uint16 `json:"srvport,omitempty"` + CaaTag string `json:"caatag,omitempty"` CaaFlag uint8 `json:"caaflag,omitempty"` + DsKeyTag uint16 `json:"dskeytag,omitempty"` DsAlgorithm uint8 `json:"dsalgorithm,omitempty"` DsDigestType uint8 `json:"dsdigesttype,omitempty"` DsDigest string `json:"dsdigest,omitempty"` + LocVersion uint8 `json:"locversion,omitempty"` LocSize uint8 `json:"locsize,omitempty"` LocHorizPre uint8 `json:"lochorizpre,omitempty"` @@ -179,24 +208,45 @@ func (rc *RecordConfig) UnmarshalJSON(b []byte) error { LocLatitude int `json:"loclatitude,omitempty"` LocLongitude int `json:"loclongitude,omitempty"` LocAltitude uint32 `json:"localtitude,omitempty"` + + LocLatDegrees uint8 `json:"loclatdegrees,omitempty"` + LocLatMinutes uint8 `json:"lotlatminutes,omitempty"` + LocLatSeconds float32 `json:"loclatseconds,omitempty"` + LocLatDirection string `json:"loclatdirection,omitempty"` + LocLongDegrees uint8 `json:"loclongdegrees,omitempty"` + LocLongMinutes uint8 `json:"lotlongminutes,omitempty"` + LocLongSeconds float32 `json:"loclongseconds,omitempty"` + LocLongDirection string `json:"loclongdirection,omitempty"` + + LocOrigAltitude int32 `json:"locorigaltitude,omitempty"` + LocOrigSize float32 `json:"locorigsize,omitempty"` + LocOrigHorizPre float32 `json:"locorighorizpre,omitempty"` + LocOrigVertPre float32 `json:"locorigvertpre,omitempty"` + NaptrOrder uint16 `json:"naptrorder,omitempty"` NaptrPreference uint16 `json:"naptrpreference,omitempty"` NaptrFlags string `json:"naptrflags,omitempty"` NaptrService string `json:"naptrservice,omitempty"` NaptrRegexp string `json:"naptrregexp,omitempty"` + SshfpAlgorithm uint8 `json:"sshfpalgorithm,omitempty"` SshfpFingerprint uint8 `json:"sshfpfingerprint,omitempty"` + SoaMbox string `json:"soambox,omitempty"` SoaSerial uint32 `json:"soaserial,omitempty"` SoaRefresh uint32 `json:"soarefresh,omitempty"` SoaRetry uint32 `json:"soaretry,omitempty"` SoaExpire uint32 `json:"soaexpire,omitempty"` SoaMinttl uint32 `json:"soaminttl,omitempty"` + TlsaUsage uint8 `json:"tlsausage,omitempty"` TlsaSelector uint8 `json:"tlsaselector,omitempty"` 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 diff --git a/models/t_loc.go b/models/t_loc.go index f4c641f588..a477437781 100644 --- a/models/t_loc.go +++ b/models/t_loc.go @@ -107,6 +107,22 @@ func (rc *RecordConfig) calculateLOCFields(d1 uint8, m1 uint8, s1 float32, ns st const LOCDegrees = 60 * LOCHours const LOCAltitudeBase int32 = 100000 + // Some providers want the original values, so we should keep them around + rc.LocLatDegrees = d1 + rc.LocLatMinutes = m1 + rc.LocLatSeconds = s1 + rc.LocLatDirection = ns + + rc.LocLongDegrees = d2 + rc.LocLongMinutes = m2 + rc.LocLongSeconds = s2 + rc.LocLongDirection = ew + + rc.LocOrigAltitude = al + rc.LocOrigSize = sz + rc.LocOrigHorizPre = hp + rc.LocOrigVertPre = vp + lat := uint64((uint32(d1) * LOCDegrees) + (uint32(m1) * LOCHours) + uint32(s1*1000)) lon := uint64((uint32(d2) * LOCDegrees) + (uint32(m2) * LOCHours) + uint32(s2*1000)) if strings.ToUpper(ns) == "N" { diff --git a/providers/cloudflare/cloudflareProvider.go b/providers/cloudflare/cloudflareProvider.go index 29390b2e67..cd4c44f0fa 100644 --- a/providers/cloudflare/cloudflareProvider.go +++ b/providers/cloudflare/cloudflareProvider.go @@ -628,26 +628,38 @@ func newCloudflare(m map[string]string, metadata json.RawMessage) (providers.DNS // Used on the "existing" records. type cfRecData struct { - Name string `json:"name"` - Target cfTarget `json:"target"` - Service string `json:"service"` // SRV - Proto string `json:"proto"` // SRV - Priority uint16 `json:"priority"` // SRV - Weight uint16 `json:"weight"` // SRV - Port uint16 `json:"port"` // SRV - Tag string `json:"tag"` // CAA - Flags uint8 `json:"flags"` // CAA - Value string `json:"value"` // CAA - Usage uint8 `json:"usage"` // TLSA - Selector uint8 `json:"selector"` // TLSA - MatchingType uint8 `json:"matching_type"` // TLSA - Certificate string `json:"certificate"` // TLSA - Algorithm uint8 `json:"algorithm"` // SSHFP/DS - HashType uint8 `json:"type"` // SSHFP - Fingerprint string `json:"fingerprint"` // SSHFP - KeyTag uint16 `json:"key_tag"` // DS - DigestType uint8 `json:"digest_type"` // DS - Digest string `json:"digest"` // DS + Name string `json:"name"` + Target cfTarget `json:"target"` + Service string `json:"service"` // SRV + Proto string `json:"proto"` // SRV + Priority uint16 `json:"priority"` // SRV + Weight uint16 `json:"weight"` // SRV + Port uint16 `json:"port"` // SRV + Tag string `json:"tag"` // CAA + Flags uint8 `json:"flags"` // CAA + Value string `json:"value"` // CAA + Usage uint8 `json:"usage"` // TLSA + Selector uint8 `json:"selector"` // TLSA + MatchingType uint8 `json:"matching_type"` // TLSA + Certificate string `json:"certificate"` // TLSA + Algorithm uint8 `json:"algorithm"` // SSHFP/DS + HashType uint8 `json:"type"` // SSHFP + Fingerprint string `json:"fingerprint"` // SSHFP + KeyTag uint16 `json:"key_tag"` // DS + DigestType uint8 `json:"digest_type"` // DS + Digest string `json:"digest"` // DS + LatDegrees uint8 `json:"lat_degrees"` // LOC + LatMinutes uint8 `json:"lat_minutes"` // LOC + LatSeconds float32 `json:"lat_seconds"` // LOC + LatDirection string `json:"lat_direction"` // LOC + LongDegrees uint8 `json:"long_degrees"` // LOC + LongMinutes uint8 `json:"long_minutes"` // LOC + LongSeconds float32 `json:"long_seconds"` // LOC + LongDirection string `json:"long_direction"` // LOC + PrecisionHorz float32 `json:"precision_horz"` // LOC + PrecisionVert float32 `json:"precision_vert"` // LOC + Altitude int32 `json:"altitude"` // LOC + Size float32 `json:"size"` // LOC } // cfTarget is a SRV target. A null target is represented by an empty string, but diff --git a/providers/cloudflare/rest.go b/providers/cloudflare/rest.go index 8b8c708459..9d84ebc127 100644 --- a/providers/cloudflare/rest.go +++ b/providers/cloudflare/rest.go @@ -68,6 +68,25 @@ func cfDSData(rec *models.RecordConfig) *cfRecData { } } +func cfLocData(rec *models.RecordConfig) *cfRecData { + return &cfRecData{ + LatDegrees: rec.LocLatDegrees, + LatMinutes: rec.LocLatMinutes, + LatSeconds: rec.LocLatSeconds, + LatDirection: rec.LocLatDirection, + + LongDegrees: rec.LocLongDegrees, + LongMinutes: rec.LocLongMinutes, + LongSeconds: rec.LocLongSeconds, + LongDirection: rec.LocLongDirection, + + PrecisionHorz: rec.LocOrigHorizPre, + PrecisionVert: rec.LocOrigVertPre, + Altitude: rec.LocOrigAltitude, + Size: rec.LocOrigSize, + } +} + func cfSrvData(rec *models.RecordConfig) *cfRecData { serverParts := strings.Split(rec.GetLabelFQDN(), ".") c := &cfRecData{ @@ -168,6 +187,8 @@ func (c *cloudflareProvider) createRecDiff2(rec *models.RecordConfig, domainID s } else if rec.Type == "NAPTR" { cf.Data = cfNaptrData(rec) cf.Name = rec.GetLabelFQDN() + } else if rec.Type == "LOC" { + cf.Data = cfLocData(rec) } resp, err := c.cfClient.CreateDNSRecord(context.Background(), cloudflare.ZoneIdentifier(domainID), cf) if err != nil { From 1b8896841c86a1f747f6ce6a506b87dc82be2336 Mon Sep 17 00:00:00 2001 From: Connor McFarlane Date: Tue, 16 Jan 2024 17:38:59 +0000 Subject: [PATCH 3/3] Spacing --- providers/cloudflare/rest.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/providers/cloudflare/rest.go b/providers/cloudflare/rest.go index 9d84ebc127..f935772fff 100644 --- a/providers/cloudflare/rest.go +++ b/providers/cloudflare/rest.go @@ -70,20 +70,20 @@ func cfDSData(rec *models.RecordConfig) *cfRecData { func cfLocData(rec *models.RecordConfig) *cfRecData { return &cfRecData{ - LatDegrees: rec.LocLatDegrees, - LatMinutes: rec.LocLatMinutes, - LatSeconds: rec.LocLatSeconds, - LatDirection: rec.LocLatDirection, - - LongDegrees: rec.LocLongDegrees, - LongMinutes: rec.LocLongMinutes, - LongSeconds: rec.LocLongSeconds, + LatDegrees: rec.LocLatDegrees, + LatMinutes: rec.LocLatMinutes, + LatSeconds: rec.LocLatSeconds, + LatDirection: rec.LocLatDirection, + + LongDegrees: rec.LocLongDegrees, + LongMinutes: rec.LocLongMinutes, + LongSeconds: rec.LocLongSeconds, LongDirection: rec.LocLongDirection, PrecisionHorz: rec.LocOrigHorizPre, PrecisionVert: rec.LocOrigVertPre, - Altitude: rec.LocOrigAltitude, - Size: rec.LocOrigSize, + Altitude: rec.LocOrigAltitude, + Size: rec.LocOrigSize, } }