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

Using linked zones with nsone won't resolve to the main zone #1990

Open
dittnamn opened this issue Aug 23, 2024 · 3 comments
Open

Using linked zones with nsone won't resolve to the main zone #1990

dittnamn opened this issue Aug 23, 2024 · 3 comments

Comments

@dittnamn
Copy link

dittnamn commented Aug 23, 2024

Using NS1, if there's two domains example1.tld and example2.tld, where example2.tld is a linked zone to example1.tld, Lexicon won't follow this link and fails with this error:

lexicon nsone create example2.tld TXT --name="test1" --content="test2" --auth-token="..."

requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.nsone.net/v1/zones/example2.tld/test1.example2.tld/TXT

I noticed that linked records were fixed in issue #151, and I'd guess some similar approach would work with linked zones.

Using the NS1 API, it's possible to do a zone info request, View zone details and the linked zone is returned as the "link" property.

@adferrand
Copy link
Collaborator

I would be glad to review a PR for this issue !

@dittnamn
Copy link
Author

dittnamn commented Aug 23, 2024

It seems like the changes in #151 were just to add the possibility to list records and that didn't work for me. I think it was due to a comparison to None instead of comparing to an empty string for the link. With these changes to nsone.py, it works for me and it will also resolve linked zones (no recursion is possible when it comes to linked zones):

@@ -131,7 +131,7 @@
             # - recursion is allowed
             # - link source and link target are always of the same rtype
             # - target can be anywhere on ns1, not necessarily self.domain_id.
-            if record.get("link", None) is None:
+            if record.get("link", None) == '':
                 # not a linked record
                 return record
 
@@ -146,6 +146,11 @@
 
         payload = self._get(f"/zones/{self.domain_id}")
         records = []
+
+        # Check if the zone is a linked zone and if it is, resolve that link
+        if "link" in payload and payload["link"] != '':
+            payload = self._get(f"/zones/{payload["link"]}")
+
         for record in payload["records"]:
             if rtype and record["type"] != rtype:
                 continue

The feature request was about was to be able to add records to these linked zones, and that will need more work.

@dittnamn
Copy link
Author

dittnamn commented Aug 23, 2024

nsone-linked-zones.patch

Alright, I did an easy method to get to the linked zone. I'm not sure if this is the way it's normally done in the rest of the code, but it seems to work as intended for me.

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

No branches or pull requests

2 participants