From 5a9c40c56523dc13268c0a58405af37066d56ece Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 3 Jan 2019 14:31:19 -0800 Subject: [PATCH] fixing module utils (#153) /cc @rambleraptor --- plugins/module_utils/gcp_utils.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/module_utils/gcp_utils.py b/plugins/module_utils/gcp_utils.py index 881fd16..d08ed82 100644 --- a/plugins/module_utils/gcp_utils.py +++ b/plugins/module_utils/gcp_utils.py @@ -72,7 +72,8 @@ def replace_resource_dict(item, value): except ValueError: return new_item -# Handles all authentication and HTTP sessions for GCP API calls. + +# Handles all authentation and HTTP sessions for GCP API calls. class GcpSession(object): def __init__(self, module, product): self.module = module @@ -86,16 +87,25 @@ class GcpSession(object): except getattr(requests.exceptions, 'RequestException') as inst: self.module.fail_json(msg=inst.message) - def post(self, url, body=None, headers={}, **kwargs): - kwargs.update({'json': body, 'headers': self._merge_dictionaries(headers, self._headers())}) + def post(self, url, body=None, headers=None, **kwargs): + if headers: + headers = self.merge_dictionaries(headers, self._headers()) + else: + headers = self._headers() + try: - return self.session().post(url, data=file_contents, headers=headers) + return self.session().post(url, json=body, headers=headers) except getattr(requests.exceptions, 'RequestException') as inst: self.module.fail_json(msg=inst.message) - def post_contents(self, url, file_contents=None, headers={}, **kwargs): + def post_contents(self, url, file_contents=None, headers=None, **kwargs): + if headers: + headers = self.merge_dictionaries(headers, self._headers()) + else: + headers = self._headers() + try: - return self.session().post(url, data=file_contents, headers=self._headers()) + return self.session().post(url, data=file_contents, headers=headers) except getattr(requests.exceptions, 'RequestException') as inst: self.module.fail_json(msg=inst.message)