Skip to content

Fix suggest zone to make sure the zone name is a dns component #32

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jschewebbn
Copy link

Need to include '.' before the name to keep from picking a zone based
on the end of the hostname that isn't the subdomain.

This fixes #30

Need to include '.' before the name to keep from picking a zone based
on the end of the hostname that isn't the subdomain.
@kindlich
Copy link

This would introduce another edge case:
Apex records/Root records (where the record's FQDN is the same as the zone's)

api_client = PDNSApiClient(...)

server = api_client.servers[0]
zone = server.create_zone('xxx.yyy.zzz.', ...)

# Would now return None instead of 'zone'
server.suggest_zone('xxx.yyy.zzz.')

Though you could probably get around that by either checking for equality in a 2nd step or by prepending a . to the record as well 😉

Another way to implement this would be splitting like

 def suggest_zone(self, r_name: str):
        LOG.info("suggesting zone for: %s", r_name)
        if not r_name.endswith('.'):
            raise PDNSCanonicalError(r_name)
        
        best_match = None
        record_name_split = list(reversed(r_name.split('.')))

        for zone in self.pdns_server.zones:
            zone_name_split = list(reversed(zone.name.split('.')))

            if zone_name_split == record_name_split[: len(zone_name_split)]:
                if not best_match:
                    best_match = zone
                if best_match and len(zone.name) > len(best_match.name):
                    best_match = zone
        logger.info("zone best match: %s", best_match)
        return best_match

I'm not sure, however, if this project is still maintained...

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.

suggest_zone doesn't handle hyphen properly
2 participants