Skip to content
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

Merged
merged 8 commits into from
Feb 10, 2019

Conversation

wfaulk
Copy link

@wfaulk wfaulk commented Jan 18, 2019

Please when making a pull request:

  • make sure changes are up to date with master.
  • please use brief, descriptive commit messages.
  • check code has been go formatted with 'go fmt'.
  • ensure you've added an integration test (under internal/features) or a unit test.
  • check the tests pass (make test).

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!

@barnybug
Copy link
Owner

Thanks for your contribution.
We'd like to merge this pull request, but first please could you:

  • ensure the existing tests pass (run: make test)

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
Given I have a domain "$domain" # internal/features/import.feature:8
When I run "cli53 import --file tests/basic.txt $domain" # internal/features/import.feature:9

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"']
status code: 400, request id: 2f0f557b-1be7-11e9-bad9-014a32bfe690

Then the domain "$domain" export matches file "tests/basic.txt"  # internal/features/import.feature:10

@wfaulk
Copy link
Author

wfaulk commented Jan 21, 2019

It works for me?

% GOCACHE=off go test github.com/barnybug/cli53
ok  	github.com/barnybug/cli53	0.016s

@wfaulk
Copy link
Author

wfaulk commented Jan 21, 2019

Oh, I see. make test does something different from go test. Investigating.

@wfaulk wfaulk changed the title add support for importing NAPTR records add support for importing/exporting NAPTR records Jan 21, 2019
@wfaulk
Copy link
Author

wfaulk commented Jan 21, 2019

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 ., in which case it doesn't quote it. The way I'm parsing it now works, but it's vaguely possible that Amazon might change something in the future that could break the regex.

(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.)

Copy link
Owner

@barnybug barnybug left a 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:]]+) \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" \"?([^\"]+)\"?$")
Copy link
Owner

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.

Copy link
Owner

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.

Copy link
Author

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)
Copy link
Owner

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. Fixed.

@wfaulk
Copy link
Author

wfaulk commented Feb 8, 2019

Fixed your issues above and added a unit test NAPTR record

Copy link
Owner

@barnybug barnybug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks

@barnybug barnybug merged commit 5ac4382 into barnybug:master Feb 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants