mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-07 11:20:28 -07:00
fixing module utils (#153)
<!-- This change is generated by MagicModules. --> /cc @rambleraptor
This commit is contained in:
parent
9a8b1ff291
commit
5a9c40c565
1 changed files with 16 additions and 6 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue