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

Stop search for zones being greedy #79

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davesbell
Copy link

@davesbell davesbell commented Jan 15, 2025

This fixes #78

I have a domain example.com

I have DNS records in the zones:
example.com
test.example.com

I have the following DNS record defined in netbox:

a-test.example.com

This causes two DNS records to be created.

2025-01-15T11:37:03 [6191755264] INFO NetboxSource[netbox] zone example.com. record added: Rr<a-test, A, 300, 127.0.0.1

2025-01-15T10:46:19 [6143684608] INFO NetboxSource[netbox] zone test.example.com. record added: Rr<a-, A, 300, 127.0.0.1

Copy link

sourcery-ai bot commented Jan 15, 2025

Reviewer's Guide by Sourcery

This PR changes the NetBox zone search to stop being greedy by changing the search query to use a trailing wildcard.

Sequence diagram for zone search query modification

sequenceDiagram
    participant Client
    participant OctoDNS
    participant NetBox

    Client->>OctoDNS: Request zone data
    OctoDNS->>NetBox: Search query with '.zone_name'
    Note right of NetBox: More specific search<br/>with leading dot
    NetBox-->>OctoDNS: Return matching zones
    OctoDNS-->>Client: Return zone data
Loading

Flow diagram showing zone name matching behavior

flowchart LR
    A[Zone Name] --> B{Search Query}
    B -->|Before| C[zone_name__ic: name]
    B -->|After| D[zone_name__ic: .name]
    C -->|Matches| E[example.com]
    C -->|Matches| F[myexample.com]
    D -->|Matches| G[example.com]
    D -.-x H[myexample.com]
    style H fill:#ffcccc
    style D fill:#ccffcc
Loading

File-Level Changes

Change Details Files
Updated the search query to prevent greedy matching of zones
  • Changed the search query field from zone.name[:-1] to .zone.name[:-1] to ensure that only zones with matching names are returned.
octodns_netbox/__init__.py

Assessment against linked issues

Issue Objective Addressed Explanation
#78 Prevent DNS record creation for unintended subzones
#78 Ensure DNS records are only created for exact zone matches

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @davesbell - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider expanding the commit message to explain what 'greedy' behavior was being fixed and how adding the dot prefix resolves it. This will help future maintainers understand the context of this change.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@mochipon
Copy link
Contributor

Thank you so much for your Pull Request!

We’ve noticed an issue in our current CI/CD process that’s preventing the tests from running correctly on your commit. It appears that some of our dependencies are out of date, which is likely causing the problem.

I’ll address these issues first, and once everything is back to normal, I’ll review your PR. Thank you for your patience!

@mochipon
Copy link
Contributor

@davesbell We’ve resolved the issues with our CI/CD pipeline. Could you please rebase your branch onto the latest main so we can proceed with reviewing your PR? Once that’s done, our tests should run correctly. Thanks again!

@mochipon
Copy link
Contributor

@davesbell Thank you for pointing out the issue. Your proposed fix does seem to resolve the immediate problem. However, we need to account for the possibility of apex records—for example, a user who wants to create an A record for example.com. With your change, that record would no longer be generated.

Instead of modifying the NetBox query, I’ve updated the code to more accurately determine whether an FQDN is part of the zone. I hope this addresses your concern.

You can test the development version by running:
pip install -i https://test.pypi.org/simple/ octodns-netbox==0.4.1.dev11

Please let me know if this resolves the issue on your end.

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.

Searching DNS records are too greedy
2 participants