40 lines
1.8 KiB
Diff
40 lines
1.8 KiB
Diff
|
From 642a3b4d3133d0cff3ea5b8300757045b2bda09d Mon Sep 17 00:00:00 2001
|
||
|
From: Abhijeet Kasurde <akasurde@redhat.com>
|
||
|
Date: Tue, 23 Jul 2019 14:14:13 +0530
|
||
|
Subject: [PATCH] gcp_utils: Handle JSON decode exception
|
||
|
|
||
|
Handle json.loads exception rather than providing stacktrace
|
||
|
|
||
|
Fixes: #56269
|
||
|
|
||
|
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
|
||
|
---
|
||
|
lib/ansible/module_utils/gcp_utils.py | 9 +++++++--
|
||
|
1 file changed, 7 insertions(+), 2 deletions(-)
|
||
|
|
||
|
--- a/lib/ansible/module_utils/gcp_utils.py
|
||
|
+++ b/lib/ansible/module_utils/gcp_utils.py
|
||
|
@@ -18,7 +18,7 @@ except ImportError:
|
||
|
|
||
|
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
||
|
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 os
|
||
|
import json
|
||
|
@@ -157,7 +157,12 @@ class GcpSession(object):
|
||
|
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'])
|
||
|
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 : %s" % to_native(e)
|
||
|
+ )
|
||
|
return service_account.Credentials.from_service_account_info(cred).with_scopes(self.module.params['scopes'])
|
||
|
elif cred_type == 'machineaccount':
|
||
|
return google.auth.compute_engine.Credentials(
|