Using linked zones with nsone won't resolve to the main zone
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.
I would be glad to review a PR for this issue !
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.
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.