Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
fixing module utils (#153)
Browse files Browse the repository at this point in the history
<!-- This change is generated by MagicModules. -->
/cc @rambleraptor
  • Loading branch information
modular-magician authored and rambleraptor committed Jan 3, 2019
1 parent 8263c82 commit 6c80682
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/ansible/module_utils/gcp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def replace_resource_dict(item, value):
except ValueError:
return new_item


# Handles all authentation and HTTP sessions for GCP API calls.
class GcpSession(object):
def __init__(self, module, product):
Expand All @@ -85,16 +86,25 @@ def get(self, url, body=None, **kwargs):
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, json=body, headers=self._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)

Expand Down

0 comments on commit 6c80682

Please sign in to comment.