11from abc import abstractmethod
22from enum import IntEnum
33from time import time
4- from typing import AsyncGenerator , Generator , Optional
4+ from typing import AsyncGenerator , Generator , Optional , Tuple
55
66from anyio import Lock , get_current_task
77from httpx import Auth as HttpxAuth
@@ -54,6 +54,17 @@ def __init__(self, use_token_cache: bool = True):
5454 self ._expires : Optional [int ] = None
5555 self ._lock = Lock ()
5656
57+ @property
58+ def account (self ) -> Optional [str ]:
59+ return self ._account_name
60+
61+ @account .setter
62+ def account (self , value : str ) -> None :
63+ self ._account_name = value
64+ # Now we have all the elements to fetch the cached token
65+ if not self ._token :
66+ self ._token , self ._expires = self ._get_cached_token ()
67+
5768 def copy (self ) -> "Auth" :
5869 """Make another auth object with same credentials.
5970
@@ -106,7 +117,7 @@ def expired(self) -> bool:
106117 """
107118 return self ._expires is not None and self ._expires <= int (time ())
108119
109- def _get_cached_token (self ) -> Optional [str ]:
120+ def _get_cached_token (self ) -> Tuple [ Optional [str ], Optional [ int ] ]:
110121 """If caching is enabled, get token from cache.
111122
112123 If caching is disabled, None is returned.
@@ -115,17 +126,17 @@ def _get_cached_token(self) -> Optional[str]:
115126 Optional[str]: Token if any, and if caching is enabled; None otherwise
116127 """
117128 if not self ._use_token_cache :
118- return None
129+ return ( None , None )
119130
120131 cache_key = SecureCacheKey (
121132 [self .principal , self .secret , self ._account_name ], self .secret
122133 )
123134 connection_info = _firebolt_cache .get (cache_key )
124135
125136 if connection_info and connection_info .token :
126- return connection_info .token
137+ return ( connection_info .token , connection_info . expiry_time )
127138
128- return None
139+ return ( None , None )
129140
130141 def _cache_token (self ) -> None :
131142 """If caching is enabled, cache token."""
0 commit comments