Skip to content

Commit b753d75

Browse files
authored
Merge pull request #9 from lyft/connection-errors
Differentiate AWS network errors
2 parents d1d7a13 + 664e511 commit b753d75

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

kmsauth/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import copy
99

1010
from botocore.vendored import six
11+
from botocore.exceptions import (ConnectionError,
12+
EndpointConnectionError)
1113

1214
import kmsauth.services
1315
from kmsauth.utils import lru
@@ -248,6 +250,11 @@ def decrypt_token(self, username, token):
248250
ret = {'payload': payload, 'key_alias': key_alias}
249251
except TokenValidationError:
250252
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+
)
251258
# We don't care what exception is thrown. For paranoia's sake, fail
252259
# here.
253260
except Exception:
@@ -458,13 +465,21 @@ def get_token(self):
458465
else:
459466
token_bytes = bytes(token, 'utf8')
460467
token = base64.b64encode(token_bytes)
468+
except (ConnectionError, EndpointConnectionError) as e:
469+
logging.exception('Failure connecting to AWS: {}'.format(str(e)))
470+
raise ServiceConnectionError()
461471
except Exception:
462472
logging.exception('Failed to create auth token.')
463473
raise TokenGenerationError()
464474
self._cache_token(token, not_after)
465475
return token
466476

467477

478+
class ServiceConnectionError(Exception):
479+
"""An exception raised when there was an AWS connection error."""
480+
pass
481+
482+
468483
class ConfigurationError(Exception):
469484

470485
"""An exception raised when a token was unsuccessfully created."""

0 commit comments

Comments
 (0)