From 8cb4ac2acb3a314f7ecb3017903d0cccf9f745de Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Thu, 19 Jan 2023 11:20:08 +0200 Subject: [PATCH] Allow requesting custom token expiration using the `api.auth.req_token_expiration_sec` configuration setting --- clearml/backend_api/config/default/api.conf | 4 ++++ clearml/backend_api/session/session.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clearml/backend_api/config/default/api.conf b/clearml/backend_api/config/default/api.conf index 554348d4..8746dbbf 100644 --- a/clearml/backend_api/config/default/api.conf +++ b/clearml/backend_api/config/default/api.conf @@ -54,5 +54,9 @@ auth { # When creating a request, if token will expire in less than this value, try to refresh the token token_expiration_threshold_sec = 360 + + # token expiration time in seconds to request from the server. if not specified, + # server will set the default expiration + req_token_expiration_sec: null } } diff --git a/clearml/backend_api/session/session.py b/clearml/backend_api/session/session.py index f9d41013..490821eb 100644 --- a/clearml/backend_api/session/session.py +++ b/clearml/backend_api/session/session.py @@ -139,6 +139,8 @@ class Session(TokenManager): "auth.token_expiration_threshold_sec", 60 ) + req_token_expiration_sec = self.config.get("api.auth.req_token_expiration_sec", None) + self._verbose = verbose if verbose is not None else ENV_VERBOSE.get() self._logger = logger if self._verbose and not self._logger: @@ -165,7 +167,9 @@ class Session(TokenManager): # init the token manager super(Session, self).__init__( - token_expiration_threshold_sec=token_expiration_threshold_sec, **kwargs + token_expiration_threshold_sec=token_expiration_threshold_sec, + req_token_expiration_sec=req_token_expiration_sec, + **kwargs ) host = host or self.get_api_server_host(config=self.config)