1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-05-04 01:13:00 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -235,10 +235,9 @@ with deps.declare("requests"):
def build_url(account, key, is_sandbox):
headers = {'Accept': 'application/json',
'Authorization': f'Bearer {key}'}
sandbox = '.sandbox' if is_sandbox else ''
url = f'https://api{sandbox}.dnsimple.com/v2/{account}'
headers = {"Accept": "application/json", "Authorization": f"Bearer {key}"}
sandbox = ".sandbox" if is_sandbox else ""
url = f"https://api{sandbox}.dnsimple.com/v2/{account}"
req = Request(url=url, headers=headers)
prepped_request = req.prepare()
return prepped_request
@ -247,8 +246,8 @@ 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' not in response.json():
module.fail_json('API Call failed, check ID, key and sandbox values')
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"]
@ -256,25 +255,28 @@ def iterate_data(module, request_object):
while page < total_pages:
page = page + 1
request_object.url = f'{base_url}&page={page}'
request_object.url = f"{base_url}&page={page}"
new_results = Session().send(request_object)
data = data + new_results.json()['data']
data = data + new_results.json()["data"]
return data
def record_info(dnsimple_mod, req_obj):
req_obj.url, req_obj.method = f"{req_obj.url}/zones/{dnsimple_mod.params['name']}/records?name={dnsimple_mod.params['record']}", 'GET'
req_obj.url, req_obj.method = (
f"{req_obj.url}/zones/{dnsimple_mod.params['name']}/records?name={dnsimple_mod.params['record']}",
"GET",
)
return iterate_data(dnsimple_mod, req_obj)
def domain_info(dnsimple_mod, req_obj):
req_obj.url, req_obj.method = f"{req_obj.url}/zones/{dnsimple_mod.params['name']}/records?per_page=100", 'GET'
req_obj.url, req_obj.method = f"{req_obj.url}/zones/{dnsimple_mod.params['name']}/records?per_page=100", "GET"
return iterate_data(dnsimple_mod, req_obj)
def account_info(dnsimple_mod, req_obj):
req_obj.url, req_obj.method = f"{req_obj.url}/zones/?per_page=100", 'GET'
req_obj.url, req_obj.method = f"{req_obj.url}/zones/?per_page=100", "GET"
return iterate_data(dnsimple_mod, req_obj)
@ -285,44 +287,37 @@ def main():
"api_key": {"required": True, "type": "str", "no_log": True},
"name": {"required": False, "type": "str"},
"record": {"required": False, "type": "str"},
"sandbox": {"required": False, "type": "bool", "default": False}
"sandbox": {"required": False, "type": "bool", "default": False},
}
result = {
'changed': False
}
result = {"changed": False}
module = AnsibleModule(
argument_spec=fields,
supports_check_mode=True
)
module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
params = module.params
req = build_url(params['account_id'],
params['api_key'],
params['sandbox'])
req = build_url(params["account_id"], params["api_key"], params["sandbox"])
deps.validate(module)
# At minimum we need account and key
if params['account_id'] and params['api_key']:
if params["account_id"] and params["api_key"]:
# If we have a record return info on that record
if params['name'] and params['record']:
result['dnsimple_record_info'] = record_info(module, req)
if params["name"] and params["record"]:
result["dnsimple_record_info"] = record_info(module, req)
module.exit_json(**result)
# If we have the account only and domain, return records for the domain
elif params['name']:
result['dnsimple_records_info'] = domain_info(module, req)
elif params["name"]:
result["dnsimple_records_info"] = domain_info(module, req)
module.exit_json(**result)
# If we have the account only, return domains
else:
result['dnsimple_domain_info'] = account_info(module, req)
result["dnsimple_domain_info"] = account_info(module, req)
module.exit_json(**result)
else:
module.fail_json(msg="Need at least account_id and api_key")
if __name__ == '__main__':
if __name__ == "__main__":
main()