Skip to content

Commit

Permalink
Make refresh token expiry a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
gmertes committed Jul 12, 2024
1 parent 4ff1339 commit b3ae738
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/anemoi/training/diagnostics/mlflow/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,26 @@

from anemoi.training.utils.logger import get_code_logger

REFRESH_EXPIRE_DAYS = 29


class TokenAuth:
"""Manage authentication with a keycloak token server."""

def __init__(
self,
url,
refresh_expire_days=29,
enabled=True,
):
"""Parameters
----------
url : str
URL of the authentication server.
refresh_expire_days : int, optional
Number of days before the refresh token expires, by default 29
enabled : bool, optional
Set this to False to turn off authentication, by default True
"""

self.url = url
self.refresh_expire_days = refresh_expire_days
self._enabled = enabled

self.config_file = "mlflow-token.json"
Expand All @@ -66,7 +64,7 @@ def refresh_token(self):
@refresh_token.setter
def refresh_token(self, value):
self._refresh_token = value
self.refresh_expires = time.time() + (self.refresh_expire_days * 86400) # 86400 seconds in a day
self.refresh_expires = time.time() + (REFRESH_EXPIRE_DAYS * 86400) # 86400 seconds in a day

def enabled(fn):
"""Decorator to call or ignore a function based on the `enabled` flag."""
Expand Down

0 comments on commit b3ae738

Please sign in to comment.