-
-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support defining records by dns zone format #1360
Changes from 4 commits
654518e
19a5a62
ee1ad7f
ea9077d
3cf218f
68a1ba9
21f395e
b64d658
c6fc0dd
1ddaa60
463ac47
1bf1383
bb67203
026d513
36676c6
f86b199
37a39f2
9f9cfa1
44ed91c
cab953a
7cd3eb0
efa5283
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ package config | |
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net" | ||
"strings" | ||
|
||
"github.com/creasty/defaults" | ||
"github.com/miekg/dns" | ||
|
@@ -67,7 +69,7 @@ var _ = Describe("CustomDNSConfig", func() { | |
}) | ||
}) | ||
|
||
Describe("UnmarshalYAML", func() { | ||
Describe("#CustomDNSEntries UnmarshalYAML", func() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope! I will remove it when I work on this next |
||
It("Should parse config as map", func() { | ||
c := CustomDNSEntries{} | ||
err := c.UnmarshalYAML(func(i interface{}) error { | ||
|
@@ -102,4 +104,71 @@ var _ = Describe("CustomDNSConfig", func() { | |
Expect(err).Should(MatchError("some err")) | ||
}) | ||
}) | ||
|
||
Describe("#ZoneFileDNS UnmarshalYAML", func() { | ||
It("Should parse config as map", func() { | ||
z := ZoneFileDNS{} | ||
err := z.UnmarshalYAML(func(i interface{}) error { | ||
*i.(*string) = strings.TrimSpace(` | ||
$ORIGIN example.com. | ||
www 3600 A 1.2.3.4 | ||
www6 3600 AAAA 2001:0db8:85a3:0000:0000:8a2e:0370:7334 | ||
cname 3600 CNAME www | ||
`) | ||
|
||
return nil | ||
}) | ||
Expect(err).Should(Succeed()) | ||
Expect(z).Should(HaveLen(3)) | ||
|
||
for url, records := range z { | ||
if url == "www.example.com." { | ||
Expect(records).Should(HaveLen(1)) | ||
|
||
record, isA := records[0].(*dns.A) | ||
|
||
Expect(isA).Should(BeTrue()) | ||
Expect(record.A).Should(Equal(net.ParseIP("1.2.3.4"))) | ||
} else if url == "www6.example.com." { | ||
Expect(records).Should(HaveLen(1)) | ||
|
||
record, isAAAA := records[0].(*dns.AAAA) | ||
|
||
Expect(isAAAA).Should(BeTrue()) | ||
Expect(record.AAAA).Should(Equal(net.ParseIP("2001:db8:85a3::8a2e:370:7334"))) | ||
} else if url == "cname.example.com." { | ||
Expect(records).Should(HaveLen(1)) | ||
|
||
record, isCNAME := records[0].(*dns.CNAME) | ||
|
||
Expect(isCNAME).Should(BeTrue()) | ||
Expect(record.Target).Should(Equal("www.example.com.")) | ||
} else { | ||
Fail("unexpected record") | ||
} | ||
} | ||
}) | ||
|
||
It("Should return an error if the zone file is malformed", func() { | ||
z := ZoneFileDNS{} | ||
err := z.UnmarshalYAML(func(i interface{}) error { | ||
*i.(*string) = strings.TrimSpace(` | ||
$ORIGIN example.com. | ||
www A 1.2.3.4 | ||
`) | ||
|
||
return nil | ||
}) | ||
Expect(err).Should(HaveOccurred()) | ||
Expect(err.Error()).Should(ContainSubstring("dns: missing TTL with no previous value")) | ||
}) | ||
It("Should return an error if the unmarshall function returns an error", func() { | ||
z := ZoneFileDNS{} | ||
err := z.UnmarshalYAML(func(i interface{}) error { | ||
return fmt.Errorf("Failed to unmarshal") | ||
}) | ||
Expect(err).Should(HaveOccurred()) | ||
Expect(err).Should(MatchError("Failed to unmarshal")) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,6 +264,7 @@ domain must be separated by a comma. | |
| customTTL | duration (no unit is minutes) | no | 1h | | ||
| rewrite | string: string (domain: domain) | no | | | ||
| mapping | string: string (hostname: address or CNAME) | no | | | ||
| zoneFileMapping | multiline string containing a DNS Zone File | no | | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it supports already more than the simple mapping and is no file by itself I would opt for |
||
| filterUnmappedTypes | boolean | no | true | | ||
|
||
!!! example | ||
|
@@ -279,6 +280,10 @@ domain must be separated by a comma. | |
printer.lan: 192.168.178.3 | ||
otherdevice.lan: 192.168.178.15,2001:0db8:85a3:08d3:1319:8a2e:0370:7344 | ||
anothername.lan: CNAME(otherdevice.lan) | ||
zoneFileMapping: | | ||
$ORIGIN example.com. | ||
www 3600 A 1.2.3.4 | ||
@ 3600 CNAME www | ||
``` | ||
|
||
This configuration will also resolve any subdomain of the defined domain, recursively. For example querying any of | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor copy-paste typo (
1
seems sensible since you're probably at least going to have a domain if you specify the option):