Keep dependency defaults encrypted and bound secret-service failure retries
This commit is contained in:
@@ -13,6 +13,7 @@ from .domain import Failure
|
||||
_lock = threading.Lock()
|
||||
_values = {}
|
||||
_valid_until = 0.0
|
||||
_retry_after = 0.0
|
||||
|
||||
|
||||
def request(path, *, data=None, token=None):
|
||||
@@ -30,12 +31,14 @@ def request(path, *, data=None, token=None):
|
||||
|
||||
|
||||
def refresh():
|
||||
global _values, _valid_until
|
||||
global _values, _valid_until, _retry_after
|
||||
if not os.getenv("BAO_ROLE"):
|
||||
return
|
||||
with _lock:
|
||||
if time.monotonic() < _valid_until:
|
||||
return
|
||||
if time.monotonic() < _retry_after:
|
||||
raise Failure(503, "Сервис секретов временно недоступен")
|
||||
try:
|
||||
role = os.environ["BAO_ROLE"]
|
||||
auth = request("auth/cert/login", data={"name": role})["auth"]
|
||||
@@ -44,10 +47,14 @@ def refresh():
|
||||
]
|
||||
# Never keep credentials usable beyond the auth token's short lease.
|
||||
_values = values
|
||||
_retry_after = 0.0
|
||||
_valid_until = time.monotonic() + min(float(auth["lease_duration"]), 30) - 1
|
||||
except (OSError, ValueError, KeyError, urllib.error.URLError):
|
||||
except (OSError, ValueError, TypeError, KeyError, urllib.error.URLError):
|
||||
_values = {}
|
||||
_valid_until = 0
|
||||
# Bound concurrent failures: one network attempt, then a brief
|
||||
# fail-closed negative cache instead of serial timeout storms.
|
||||
_retry_after = time.monotonic() + 1
|
||||
raise Failure(503, "Сервис секретов временно недоступен") from None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user