Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch more specific exceptions in assume role provider #1515

Merged
merged 1 commit into from
Sep 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions awscli/customizations/assumerole.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from botocore import credentials
from botocore.compat import total_seconds
from botocore.exceptions import PartialCredentialsError
from botocore.exceptions import UnknownCredentialError


LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -40,11 +41,12 @@ def inject_assume_role_provider(session, **kwargs):
# * ...
cred_chain = session.get_component('credential_provider')
cred_chain.insert_before('shared-credentials-file', provider)
except Exception:
except (ValueError, UnknownCredentialError):
# Only catch UnknownCredentialError and ValueError
# This is ok, it just means that we couldn't create the credential
# provider object.
LOG.debug("Not registering assume-role provider, credential "
"provider from session could not be created.")
"provider from session could not be created.", exc_info=True)


def create_assume_role_provider(session, provider_cls):
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/customizations/test_assumerole.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def test_assume_role_provider_registration(self):

def test_provider_not_registered_on_error(self):
session = mock.Mock()
session.get_component.side_effect = Exception(
# This is the exception raised when we can't retrieve the component
# from the ComponentLocator.
session.get_component.side_effect = ValueError(
"Couldn't get credential_provider.")
assumerole.inject_assume_role_provider(
session, event_name='building-command-table.foo')
Expand Down