|
8 | 8 | import copy |
9 | 9 |
|
10 | 10 | from botocore.vendored import six |
| 11 | +from botocore.exceptions import (ConnectionError, |
| 12 | + EndpointConnectionError) |
11 | 13 |
|
12 | 14 | import kmsauth.services |
13 | 15 | from kmsauth.utils import lru |
@@ -248,6 +250,11 @@ def decrypt_token(self, username, token): |
248 | 250 | ret = {'payload': payload, 'key_alias': key_alias} |
249 | 251 | except TokenValidationError: |
250 | 252 | raise |
| 253 | + except (ConnectionError, EndpointConnectionError): |
| 254 | + logging.exception('Failure connecting to AWS endpoint.') |
| 255 | + raise TokenValidationError( |
| 256 | + 'Authentication error. Failure connecting to AWS endpoint.' |
| 257 | + ) |
251 | 258 | # We don't care what exception is thrown. For paranoia's sake, fail |
252 | 259 | # here. |
253 | 260 | except Exception: |
@@ -458,13 +465,21 @@ def get_token(self): |
458 | 465 | else: |
459 | 466 | token_bytes = bytes(token, 'utf8') |
460 | 467 | token = base64.b64encode(token_bytes) |
| 468 | + except (ConnectionError, EndpointConnectionError) as e: |
| 469 | + logging.exception('Failure connecting to AWS: {}'.format(str(e))) |
| 470 | + raise ServiceConnectionError() |
461 | 471 | except Exception: |
462 | 472 | logging.exception('Failed to create auth token.') |
463 | 473 | raise TokenGenerationError() |
464 | 474 | self._cache_token(token, not_after) |
465 | 475 | return token |
466 | 476 |
|
467 | 477 |
|
| 478 | +class ServiceConnectionError(Exception): |
| 479 | + """An exception raised when there was an AWS connection error.""" |
| 480 | + pass |
| 481 | + |
| 482 | + |
468 | 483 | class ConfigurationError(Exception): |
469 | 484 |
|
470 | 485 | """An exception raised when a token was unsuccessfully created.""" |
|
0 commit comments