make the cert verification optional

This commit is contained in:
Greg Gauthier 2024-07-20 09:46:28 +01:00
parent 9820bb5069
commit 9a135847b9

View File

@ -4,7 +4,7 @@ from requests import RequestException
from requests_oauthlib import OAuth2Session from requests_oauthlib import OAuth2Session
def api_client(call_dict): def api_client(call_dict, verify_cert=False):
url = call_dict["url"] url = call_dict["url"]
headers = call_dict["headers"] headers = call_dict["headers"]
@ -15,15 +15,15 @@ def api_client(call_dict):
try: try:
if method == 'GET': if method == 'GET':
response = client.get(url, headers=headers, params=body, verify=False) response = client.get(url, headers=headers, params=body, verify=verify_cert)
elif method == 'POST': elif method == 'POST':
response = client.post(url, headers=headers, json=body, verify=False) response = client.post(url, headers=headers, json=body, verify=verify_cert)
elif method == 'PUT': elif method == 'PUT':
response = client.put(url, headers=headers, json=body, verify=False) response = client.put(url, headers=headers, json=body, verify=verify_cert)
elif method == 'OPTIONS': elif method == 'OPTIONS':
response = client.options(url, headers=headers, json=body, verify=False) response = client.options(url, headers=headers, json=body, verify=verify_cert)
elif method == 'DELETE': elif method == 'DELETE':
response = client.delete(url, verify=False) response = client.delete(url, verify=verify_cert)
else: else:
raise ValueError(f"Invalid method: {method}") raise ValueError(f"Invalid method: {method}")