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

Incorrect hosted zone match #1190

Closed
sridhar562345 opened this issue Nov 14, 2022 · 6 comments
Closed

Incorrect hosted zone match #1190

sridhar562345 opened this issue Nov 14, 2022 · 6 comments

Comments

@sridhar562345
Copy link
Contributor

Zappa/zappa/core.py

Lines 3197 to 3208 in 9b2a98c

def get_best_match_zone(all_zones, domain):
"""Return zone id which name is closer matched with domain name."""
# Related: https://github.com/Miserlou/Zappa/issues/459
public_zones = [zone for zone in all_zones["HostedZones"] if not zone["Config"]["PrivateZone"]]
zones = {zone["Name"][:-1]: zone["Id"] for zone in public_zones if zone["Name"][:-1] in domain}
if zones:
keys = max(zones.keys(), key=lambda a: len(a)) # get longest key -- best match.
return zones[keys]
else:
return None

Suppose there are two hosted zones api.in and beta.api.in and domain name specified is some-beta.api.in

The current logic selects hosted beta.api.in as the hosted zone for the specified domain.

@monkut
Copy link
Collaborator

monkut commented Nov 15, 2022

What is the expected result?

@sridhar562345
Copy link
Contributor Author

What is the expected result?

It should select api.in as the best match zone

@monkut
Copy link
Collaborator

monkut commented Nov 17, 2022

@sridhar562345 I attempted an improvement PR, can you check it out and let me know if it meets your expectations?

#1193

@sridhar562345
Copy link
Contributor Author

@monkut

I was actually working on it as well and I guess I have a better logic to verify this.

Here is my logic

@staticmethod
def get_best_match_zone(all_zones, domain):
    """Return zone id which name is closer matched with domain name."""

    # Related: https://github.com/Miserlou/Zappa/issues/459
    public_zones = [zone for zone in all_zones['HostedZones'] if not zone['Config']['PrivateZone']]

    zones = {zone['Name'][:-1]: zone['Id'] for zone in public_zones if zone['Name'][:-1] == domain}

    if not zones:
        zones = {zone['Name'][:-1]: zone['Id'] for zone in public_zones if '.' + zone['Name'][:-1] in domain}

    if zones:
        keys = max(zones.keys(), key=lambda a: len(a))  # get longest key -- best match.
        return zones[keys]
    else:
        return None

@monkut
Copy link
Collaborator

monkut commented Nov 18, 2022

Thanks!

monkut added a commit that referenced this issue Nov 24, 2022
monkut added a commit that referenced this issue Dec 1, 2022
* 📝 CHANGELOG.md update for 0.55.1 release

* 📝 add merged PR (#1177) related issues to CHANGELOG.

* 📝 add #1117 to list after merge.

* 📝 adding resolved issue to CHANGELOG

* 🔧 0.55.1 -> 0.56.0
📝 add merged issue to changelog.

* 📝 add #1190

* 🔧 `Pipfile` (pipenv) now used in place of requirements.txt, test_requirements.txt, requirements.in test_requirements.in. Replacing in MANIFEST.in.

Related Issue:
#1199

* 🔧 Add resolved issue #1199
@monkut
Copy link
Collaborator

monkut commented Dec 1, 2022

released in 0.56.0, closing.

@monkut monkut closed this as completed Dec 1, 2022
Ian288 pushed a commit to tackle-io/Zappa that referenced this issue Jul 11, 2023
* 📝 CHANGELOG.md update for 0.55.1 release

* 📝 add merged PR (zappa#1177) related issues to CHANGELOG.

* 📝 add zappa#1117 to list after merge.

* 📝 adding resolved issue to CHANGELOG

* 🔧 0.55.1 -> 0.56.0
📝 add merged issue to changelog.

* 📝 add zappa#1190

* 🔧 `Pipfile` (pipenv) now used in place of requirements.txt, test_requirements.txt, requirements.in test_requirements.in. Replacing in MANIFEST.in.

Related Issue:
zappa#1199

* 🔧 Add resolved issue zappa#1199
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants