fix AWS plugin credential precedence for environment variables (#52945)

* fix AWS plugin credential precedence for environment variables

* Allow aliases in direct plugins options

Consolidate precedence fix just in the doc fragment using aliases for mismatched options

* Access options with the option name rather than alias

* fix indentation

* update unit tests

* Improve readability
This commit is contained in:
Sloane Hertel 2019-03-25 15:53:11 -05:00 committed by Brian Coca
parent 4fac91bed5
commit 54be769e8d
8 changed files with 54 additions and 83 deletions

View file

@ -129,9 +129,9 @@ def test_get_boto_attr_chain(inventory):
def test_boto3_conn(inventory):
inventory._options = {"boto_profile": "first_precedence",
"aws_access_key_id": "test_access_key",
"aws_secret_access_key": "test_secret_key",
inventory._options = {"aws_profile": "first_precedence",
"aws_access_key": "test_access_key",
"aws_secret_key": "test_secret_key",
"aws_security_token": "test_security_token"}
inventory._set_credentials()
with pytest.raises(AnsibleError) as error_message:
@ -151,10 +151,10 @@ def test_get_hostname(inventory):
def test_set_credentials(inventory):
inventory._options = {'aws_access_key_id': 'test_access_key',
'aws_secret_access_key': 'test_secret_key',
inventory._options = {'aws_access_key': 'test_access_key',
'aws_secret_key': 'test_secret_key',
'aws_security_token': 'test_security_token',
'boto_profile': 'test_profile'}
'aws_profile': 'test_profile'}
inventory._set_credentials()
assert inventory.boto_profile == "test_profile"
@ -165,10 +165,10 @@ def test_set_credentials(inventory):
def test_insufficient_credentials(inventory):
inventory._options = {
'aws_access_key_id': None,
'aws_secret_access_key': None,
'aws_access_key': None,
'aws_secret_key': None,
'aws_security_token': None,
'boto_profile': None
'aws_profile': None
}
with pytest.raises(AnsibleError) as error_message:
inventory._set_credentials()