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

nsone -- list index out of range. #151

Closed
init-js opened this issue Nov 24, 2017 · 6 comments
Closed

nsone -- list index out of range. #151

init-js opened this issue Nov 24, 2017 · 6 comments

Comments

@init-js
Copy link
Contributor

init-js commented Nov 24, 2017

using dns-lexicon 2.1.11

I'm getting a list index out of range in the process of cleaning up acme/certbot TXT records on nsone.

/opt/certbot # lexicon nsone list sitelabs.io TXT --auth-token MYTOKEN
Arguments: Namespace(action='list', auth_token='MYTOKEN', content=None, delegated=None, domain='sitelabs.io', identifier=None, name=None, priority=None, provider_name='nsone', ttl=None, type='TXT')
Starting new HTTPS connection (1): api.nsone.net
https://api.nsone.net:443 "GET /v1/zones/sitelabs.io HTTP/1.1" 200 None
Starting new HTTPS connection (1): api.nsone.net
https://api.nsone.net:443 "GET /v1/zones/sitelabs.io HTTP/1.1" 200 None
Traceback (most recent call last):
  File "/usr/local/bin/lexicon", line 11, in <module>
    load_entry_point('dns-lexicon==2.1.11', 'console_scripts', 'lexicon')()
  File "/usr/local/lib/python2.7/site-packages/lexicon/__main__.py", line 69, in main
    client.execute()
  File "/usr/local/lib/python2.7/site-packages/lexicon/client.py", line 44, in execute
    return self.provider.list_records(self.options.get('type'), self.options.get('name'), self.options.get('content'))
  File "/usr/local/lib/python2.7/site-packages/lexicon/providers/nsone.py", line 68, in list_records
    'content': record['short_answers'][0],
IndexError: list index out of range

The current record list for TXT records is (from the nsone panel):

image

Has there been an nsone response format change?

@init-js
Copy link
Contributor Author

init-js commented Nov 24, 2017

Adding more info.

Dumping the record information before processing reveals that the problem is with nsone "linked" records.

...
{u'domain': u'sitelabs.io', u'short_answers': [u'dns1.p03.nsone.net', u'dns2.p03.nsone.net', u'dns3.p03.nsone.net', u'dns4.p03.nsone.net'], u'ttl': 3600, u'tier': 1, u'type': u'NS', u'id': u'599ce1d3a632f60001a95c76'}
{u'domain': u'sitelabs.io', u'short_answers': [u'v=spf1 mx -all'], u'link': None, u'ttl': 3600, u'tier': 1, u'type': u'TXT', u'id': u'59a479fda632f6000199e90b'}
{u'domain': u'www.sitelabs.io', u'short_answers': [], u'link': u'sitelabs.ca', u'ttl': 3600, u'tier': 1.0, u'type': u'A', u'id': u'59ac55a1a632f60001df4361'}
...

In this case. www.sitelabs.io is linked to sitelabs.ca

I'll let you decide whether you should recurse (and fetch the linked record), just fake a CNAME, or just skip, but that's a corner case that needs special treatment in any case.

@AnalogJ
Copy link
Owner

AnalogJ commented Nov 25, 2017

Hmm, I'm not really familiar with NSOne's link feature. Is this something you can open a PR to fix?

@init-js
Copy link
Contributor Author

init-js commented Nov 25, 2017

It's a way for nsone users to de-duplicate dns record information, without requiring dns clients to pay the price of a CNAME. It effectively makes a record a symbolic link to another one on their database.

https://ns1.com/articles/cname-alias-and-linked-records

I'm happy to patch it, but should the "linked" status be exposed in the lexicon output? Fetching details for a linked record would require another dnsone API lookup. Is there another provider which has a similar feature, and from which the behaviour could be replicated?

@AnalogJ
Copy link
Owner

AnalogJ commented Nov 27, 2017

Looking at what you said, I think it would make sense to fake a CNAME record for it, with another API lookup.

I don't think there's an example of another provider doing anything similar, unfortunately.

init-js added a commit to init-js/lexicon that referenced this issue Dec 5, 2017
   - if a linked record is encountered, the code will resolve the link,
     recursively, up to 3 times.

   - refactoring: filter records before fetching them, as much as possible.
init-js added a commit to init-js/lexicon that referenced this issue Dec 6, 2017
   - if a linked record is encountered, the code will resolve the link,
     recursively, up to 3 times.

   - refactoring: filter records before fetching them, as much as possible.

   Note: Linked records point to records in the same or another zone on NS1,
         but the source and target are always the same type.
@init-js
Copy link
Contributor Author

init-js commented Dec 6, 2017

Created PR #157 .

@AnalogJ
Copy link
Owner

AnalogJ commented Dec 10, 2017

This should be fixed now thanks to @init-js . Closing.

@AnalogJ AnalogJ closed this as completed Dec 10, 2017
chrisbraucker pushed a commit to chrisbraucker/lexicon that referenced this issue Jan 1, 2020
   - if a linked record is encountered, the code will resolve the link,
     recursively, up to 3 times.

   - refactoring: filter records before fetching them, as much as possible.

   Note: Linked records point to records in the same or another zone on NS1,
         but the source and target are always the same type.
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