in src/dynamodb_encryption_sdk/material_providers/most_recent.py [0:0]
def _ttl_action(self, version, action):
# type: (str) -> TtlActions
"""Determine the correct action to take based on the local resources and TTL.
:param action: The action being taken (encrypt or decrypt)
:returns: decision
:rtype: TtlActions
"""
try:
if action == _ENCRYPT_ACTION:
# On encrypt, always check the class-level variable indicating when we last checked for updates.
# The cache timestamps will be updated by calls to decrypt, so we don't want frequent decrypts to
# prevent us from re-checking for a newer encryption version
if self._last_updated is None:
return TtlActions.EXPIRED
timestamp = self._last_updated
else:
timestamp, _ = self._cache.get(version)
time_since_updated = time.time() - timestamp
if time_since_updated < self._version_ttl:
return TtlActions.LIVE
if time_since_updated < self._version_ttl + self._grace_period:
return TtlActions.GRACE_PERIOD
_LOGGER.debug("TTL Expired because known version has expired")
return TtlActions.EXPIRED
except KeyError:
_LOGGER.debug("TTL Expired because the requested version doesn't exist in the cache")
return TtlActions.EXPIRED