22from abc import abstractmethod
33from enum import IntEnum
44from time import time
5- from typing import AsyncGenerator , Generator , Optional
5+ from typing import AsyncGenerator , Generator , Optional , Tuple
66
77from anyio import Lock
88from httpx import Auth as HttpxAuth
@@ -57,6 +57,17 @@ def __init__(self, use_token_cache: bool = True):
5757 self ._expires : Optional [int ] = None
5858 self ._lock = Lock ()
5959
60+ @property
61+ def account (self ) -> Optional [str ]:
62+ return self ._account_name
63+
64+ @account .setter
65+ def account (self , value : str ) -> None :
66+ self ._account_name = value
67+ # Now we have all the elements to fetch the cached token
68+ if not self ._token :
69+ self ._token , self ._expires = self ._get_cached_token ()
70+
6071 def copy (self ) -> "Auth" :
6172 """Make another auth object with same credentials.
6273
@@ -109,7 +120,7 @@ def expired(self) -> bool:
109120 """
110121 return self ._expires is not None and self ._expires <= int (time ())
111122
112- def _get_cached_token (self ) -> Optional [str ]:
123+ def _get_cached_token (self ) -> Tuple [ Optional [str ], Optional [ int ] ]:
113124 """If caching is enabled, get token from cache.
114125
115126 If caching is disabled, None is returned.
@@ -118,17 +129,17 @@ def _get_cached_token(self) -> Optional[str]:
118129 Optional[str]: Token if any, and if caching is enabled; None otherwise
119130 """
120131 if not self ._use_token_cache :
121- return None
132+ return ( None , None )
122133
123134 cache_key = SecureCacheKey (
124135 [self .principal , self .secret , self ._account_name ], self .secret
125136 )
126137 connection_info = _firebolt_cache .get (cache_key )
127138
128139 if connection_info and connection_info .token :
129- return connection_info .token
140+ return ( connection_info .token , connection_info . expiry_time )
130141
131- return None
142+ return ( None , None )
132143
133144 def _cache_token (self ) -> None :
134145 """If caching is enabled, cache token."""
0 commit comments