-
Notifications
You must be signed in to change notification settings - Fork 270
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
add support for importing/exporting NAPTR records #267
Conversation
Thanks for your contribution.
As it is, this only implements import, and cli53 actually errors on attempting to export. See failing test: Scenario: I can import a basic zone # internal/features/import.feature:7 Error: exit status 1 Output: Error: InvalidChangeBatch: [Invalid Resource Record: FATAL problem: IncompleteOctalEscapeSequence (Value contains incomplete octal escape sequence) encountered with '"" "" "/urn:cid:.+@([^\.]+.)(.*)$/\2/i"']
|
It works for me?
|
Oh, I see. |
First, despite being examples pulled directly from the NAPTR RFC, Route 53 didn't like the records I had put in the zone file. I updated them to some that it did like. I also added support for exporting NAPTR records, and it passes the test now. However, Route 53 seems to return NAPTR records in an odd/incorrect format. It always quotes the last field (replacement), which seems to be wrong, unless the last field is just (Also, go's regex support is pretty lousy. It doesn't support backreferences, which would have made this cleaner, and it claims to support non-capturing groups, but they get captured anyway.) |
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.
A unit test for the route53 <-> dns conversion too wouldn't hurt, here: https://github.com/barnybug/cli53/blob/master/bind_test.go#L432
Also, to come to go's defence, it doesn't sound as though you're using regexps correctly if non-capturing groups were not working for you. Rather than go itself being broken.
bind.go
Outdated
case "NAPTR": | ||
for _, rr := range rrset.ResourceRecords { | ||
// parse value | ||
naptrRE, err := regexp.Compile("^([[:digit:]]+) ([[:digit:]]+) \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" \"?([^\"]+)\"?$") |
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.
It's better to put regexs in the file scope and use MustCompile(...)
, so it's only compiled once.
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.
Also, this regexp can be written more legibly using raw strings (backticks), to cut down on the escaping required.
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.
Got it. Fixed.
bind.go
Outdated
// parse value | ||
naptrRE, err := regexp.Compile("^([[:digit:]]+) ([[:digit:]]+) \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" \"?([^\"]+)\"?$") | ||
naptr := naptrRE.FindStringSubmatch(*rr.Value) | ||
fmt.Printf("naptr slice: %q\n", naptr) |
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.
Please don't leave debugging prints in the code.
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.
Whoops. Fixed.
Fixed your issues above and added a unit test NAPTR record |
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.
Great, thanks
Please when making a pull request:
cli53 has very good existing test coverage, so I'm unlikely to accept a pull request without
a test, but please do ping me if you're struggling to add a test case and I'll help!