mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Gcp auth deprecation (#44866)
This commit is contained in:
parent
a0d7d4b82f
commit
3550f342e0
2 changed files with 10 additions and 15 deletions
|
@ -237,7 +237,7 @@ def _validate_credentials_file(module, credentials_file, require_valid_json=True
|
|||
:param credentials_file: path to file on disk
|
||||
:type credentials_file: ``str``. Complete path to file on disk.
|
||||
|
||||
:param require_valid_json: If true, require credentials to be valid JSON. Default is True.
|
||||
:param require_valid_json: This argument is ignored as of Ansible 2.7.
|
||||
:type require_valid_json: ``bool``
|
||||
|
||||
:params check_libcloud: If true, check the libcloud version available to see if
|
||||
|
@ -263,14 +263,9 @@ def _validate_credentials_file(module, credentials_file, require_valid_json=True
|
|||
credentials_file, changed=False)
|
||||
return False
|
||||
except ValueError as e:
|
||||
if require_valid_json:
|
||||
module.fail_json(
|
||||
msg='GCP Credentials File %s invalid. Must be valid JSON.' % credentials_file, changed=False)
|
||||
else:
|
||||
module.deprecate(msg=("Non-JSON credentials file provided. This format is deprecated. "
|
||||
" Please generate a new JSON key from the Google Cloud console"),
|
||||
version=2.5)
|
||||
return True
|
||||
msg='Non-JSON credentials file provided. Please generate a new JSON key from the Google Cloud console',
|
||||
changed=False)
|
||||
|
||||
|
||||
def gcp_connect(module, provider, get_driver, user_agent_product, user_agent_version):
|
||||
|
|
|
@ -151,16 +151,16 @@ class GCPAuthTestCase(unittest.TestCase):
|
|||
def test_validate_credentials_file(self):
|
||||
# TODO(supertom): Only dealing with p12 here, check the other states
|
||||
# of this function
|
||||
module = mock.MagicMock()
|
||||
module = FakeModule()
|
||||
with mock.patch("ansible.module_utils.gcp.open",
|
||||
mock.mock_open(read_data='foobar'), create=True) as m:
|
||||
# pem condition, warning is suppressed with the return_value
|
||||
credentials_file = '/foopath/pem.pem'
|
||||
is_valid = _validate_credentials_file(module,
|
||||
with self.assertRaises(ValueError):
|
||||
_validate_credentials_file(module,
|
||||
credentials_file=credentials_file,
|
||||
require_valid_json=False,
|
||||
check_libcloud=False)
|
||||
self.assertTrue(is_valid)
|
||||
|
||||
@mock.patch('ansible.module_utils.gcp._get_gcp_environ_var',
|
||||
side_effect=fake_get_gcp_environ_var)
|
||||
|
|
Loading…
Reference in a new issue