role.py: only strip 'Role' from 'get_role' response if present (passes placebo tests)
Showing
1 changed file
with
8 additions
and
4 deletions
... | @@ -38,11 +38,13 @@ class Role(object): | ... | @@ -38,11 +38,13 @@ class Role(object): |
38 | 38 | ||
39 | Path = '/kappa/' | 39 | Path = '/kappa/' |
40 | 40 | ||
41 | - def __init__(self, context, config): | 41 | + def __init__(self, context, config, iam_client=None): |
42 | self._context = context | 42 | self._context = context |
43 | self._config = config | 43 | self._config = config |
44 | - self._iam_client = kappa.awsclient.create_client( | 44 | + self._iam_client = iam_client |
45 | - 'iam', context.session) | 45 | + if not iam_client: |
46 | + self._iam_client = kappa.awsclient.create_client( | ||
47 | + 'iam', context.session) | ||
46 | self._arn = None | 48 | self._arn = None |
47 | 49 | ||
48 | @property | 50 | @property |
... | @@ -62,7 +64,9 @@ class Role(object): | ... | @@ -62,7 +64,9 @@ class Role(object): |
62 | def _get_role(self): | 64 | def _get_role(self): |
63 | try: | 65 | try: |
64 | response = self._iam_client.call('get_role', RoleName=self.name) | 66 | response = self._iam_client.call('get_role', RoleName=self.name) |
65 | - return response['Role'] | 67 | + if response and 'Role' in response: |
68 | + response = response['Role'] | ||
69 | + return response | ||
66 | except ClientError as e: | 70 | except ClientError as e: |
67 | if e.response['Error']['Code'] != 'NoSuchEntity': | 71 | if e.response['Error']['Code'] != 'NoSuchEntity': |
68 | LOG.exception('Error getting role') | 72 | LOG.exception('Error getting role') | ... | ... |
-
Please register or login to post a comment