mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
dnsimple_info: minor refactor (#6440)
* dns_simple: minor refactor * add changelog frag
This commit is contained in:
parent
91376f7989
commit
27a3d6d85d
2 changed files with 18 additions and 14 deletions
2
changelogs/fragments/6440-dnsimple-info-refactor.yml
Normal file
2
changelogs/fragments/6440-dnsimple-info-refactor.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- dnsimple_info - minor refactor in the code (https://github.com/ansible-collections/community.general/pull/6440).
|
|
@ -239,9 +239,9 @@ with deps.declare("requests"):
|
|||
|
||||
def build_url(account, key, is_sandbox):
|
||||
headers = {'Accept': 'application/json',
|
||||
'Authorization': 'Bearer ' + key}
|
||||
url = 'https://api{sandbox}.dnsimple.com/'.format(
|
||||
sandbox=".sandbox" if is_sandbox else "") + 'v2/' + account
|
||||
'Authorization': 'Bearer {0}'.format(key)}
|
||||
sandbox = '.sandbox' if is_sandbox else ''
|
||||
url = 'https://api{sandbox}.dnsimple.com/v2/{account}'.format(sandbox=sandbox, account=account)
|
||||
req = Request(url=url, headers=headers)
|
||||
prepped_request = req.prepare()
|
||||
return prepped_request
|
||||
|
@ -250,19 +250,21 @@ def build_url(account, key, is_sandbox):
|
|||
def iterate_data(module, request_object):
|
||||
base_url = request_object.url
|
||||
response = Session().send(request_object)
|
||||
if 'pagination' in response.json():
|
||||
data = response.json()["data"]
|
||||
pages = response.json()["pagination"]["total_pages"]
|
||||
if int(pages) > 1:
|
||||
for page in range(1, pages):
|
||||
page = page + 1
|
||||
request_object.url = base_url + '&page=' + str(page)
|
||||
new_results = Session().send(request_object)
|
||||
data = data + new_results.json()["data"]
|
||||
return data
|
||||
else:
|
||||
if 'pagination' not in response.json():
|
||||
module.fail_json('API Call failed, check ID, key and sandbox values')
|
||||
|
||||
data = response.json()["data"]
|
||||
total_pages = response.json()["pagination"]["total_pages"]
|
||||
page = 1
|
||||
|
||||
while page < total_pages:
|
||||
page = page + 1
|
||||
request_object.url = '{url}&page={page}'.format(url=base_url, page=page)
|
||||
new_results = Session().send(request_object)
|
||||
data = data + new_results.json()['data']
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def record_info(dnsimple_mod, req_obj):
|
||||
req_obj.url, req_obj.method = req_obj.url + '/zones/' + dnsimple_mod.params["name"] + '/records?name=' + dnsimple_mod.params["record"], 'GET'
|
||||
|
|
Loading…
Reference in a new issue