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 Sep 5, 2019
1 parent 9a8b1ff commit 5a9c40c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions plugins/module_utils/gcp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -86,16 +87,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, 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)

Expand Down

0 comments on commit 5a9c40c

Please sign in to comment.