mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-09 12:20:27 -07:00
backporting gcp_util changes (#332)
Signed-off-by: Modular Magician <magic-modules@google.com>
This commit is contained in:
parent
adf0c57272
commit
96f4e729f9
1 changed files with 9 additions and 4 deletions
|
@ -18,7 +18,7 @@ except ImportError:
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils._text import to_text, to_native
|
||||||
import ast
|
import ast
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
@ -86,7 +86,7 @@ class GcpSession(object):
|
||||||
|
|
||||||
def post(self, url, body=None, headers=None, **kwargs):
|
def post(self, url, body=None, headers=None, **kwargs):
|
||||||
if headers:
|
if headers:
|
||||||
headers = self.merge_dictionaries(headers, self._headers())
|
headers = self._merge_dictionaries(headers, self._headers())
|
||||||
else:
|
else:
|
||||||
headers = self._headers()
|
headers = self._headers()
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ class GcpSession(object):
|
||||||
|
|
||||||
def post_contents(self, url, file_contents=None, headers=None, **kwargs):
|
def post_contents(self, url, file_contents=None, headers=None, **kwargs):
|
||||||
if headers:
|
if headers:
|
||||||
headers = self.merge_dictionaries(headers, self._headers())
|
headers = self._merge_dictionaries(headers, self._headers())
|
||||||
else:
|
else:
|
||||||
headers = self._headers()
|
headers = self._headers()
|
||||||
|
|
||||||
|
@ -156,7 +156,12 @@ class GcpSession(object):
|
||||||
path = os.path.realpath(os.path.expanduser(self.module.params['service_account_file']))
|
path = os.path.realpath(os.path.expanduser(self.module.params['service_account_file']))
|
||||||
return service_account.Credentials.from_service_account_file(path).with_scopes(self.module.params['scopes'])
|
return service_account.Credentials.from_service_account_file(path).with_scopes(self.module.params['scopes'])
|
||||||
elif cred_type == 'serviceaccount' and self.module.params.get('service_account_contents'):
|
elif cred_type == 'serviceaccount' and self.module.params.get('service_account_contents'):
|
||||||
cred = json.loads(self.module.params.get('service_account_contents'))
|
try:
|
||||||
|
cred = json.loads(self.module.params.get('service_account_contents'))
|
||||||
|
except json.decoder.JSONDecodeError as e:
|
||||||
|
self.module.fail_json(
|
||||||
|
msg="Unable to decode service_account_contents as JSON"
|
||||||
|
)
|
||||||
return service_account.Credentials.from_service_account_info(cred).with_scopes(self.module.params['scopes'])
|
return service_account.Credentials.from_service_account_info(cred).with_scopes(self.module.params['scopes'])
|
||||||
elif cred_type == 'machineaccount':
|
elif cred_type == 'machineaccount':
|
||||||
return google.auth.compute_engine.Credentials(
|
return google.auth.compute_engine.Credentials(
|
||||||
|
|
Loading…
Add table
Reference in a new issue