Skip to content

Commit

Permalink
Merge ccd1b15 into d240f5e
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwacky42 committed Nov 17, 2016
2 parents d240f5e + ccd1b15 commit 4518753
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions lexicon/providers/digitalocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,29 @@ def create_record(self, type, name, content):
# type, name and content are used to filter records.
# If possible filter during the query, otherwise filter after response is received.
def list_records(self, type=None, name=None, content=None):
filter = {}

payload = self._get('/domains/{0}/records'.format(self.domain_id))
url = '/domains/{0}/records'.format(self.domain_id)
records = []
for record in payload['domain_records']:
processed_record = {
'type': record['type'],
'name': "{0}.{1}".format(record['name'], self.domain_id),
'ttl': '',
'content': record['data'],
'id': record['id']
}
records.append(processed_record)
payload = {}

next = url
while next is not None:
payload = self._get(next)
if 'links' in payload \
and 'pages' in payload['links'] \
and 'next' in payload['links']['pages']:
next = payload['links']['pages']['next']
else:
next = None

for record in payload['domain_records']:
processed_record = {
'type': record['type'],
'name': "{0}.{1}".format(record['name'], self.domain_id),
'ttl': '',
'content': record['data'],
'id': record['id']
}
records.append(processed_record)

if type:
records = [record for record in records if record['type'] == type]
Expand Down Expand Up @@ -104,8 +114,10 @@ def _request(self, action='GET', url='/', data=None, query_params=None):
'Content-Type': 'application/json',
'Authorization': 'Bearer {0}'.format(self.options.get('auth_token'))
}
if not url.startswith(self.api_endpoint):
url = self.api_endpoint + url

r = requests.request(action, self.api_endpoint + url, params=query_params,
r = requests.request(action, url, params=query_params,
data=json.dumps(data),
headers=default_headers)
r.raise_for_status() # if the request fails for any reason, throw an error.
Expand Down

0 comments on commit 4518753

Please sign in to comment.