Skip to content

Commit e90ba3a

Browse files
hovaescohashhar
authored andcommitted
Replace host with key in OAuth utils methods
1 parent 5a86e32 commit e90ba3a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

trino/auth.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ class _OAuth2TokenCache(metaclass=abc.ABCMeta):
208208
"""
209209

210210
@abc.abstractmethod
211-
def get_token_from_cache(self, host: Optional[str]) -> Optional[str]:
211+
def get_token_from_cache(self, key: Optional[str]) -> Optional[str]:
212212
pass
213213

214214
@abc.abstractmethod
215-
def store_token_to_cache(self, host: Optional[str], token: str) -> None:
215+
def store_token_to_cache(self, key: Optional[str], token: str) -> None:
216216
pass
217217

218218

@@ -224,11 +224,11 @@ class _OAuth2TokenInMemoryCache(_OAuth2TokenCache):
224224
def __init__(self) -> None:
225225
self._cache: Dict[Optional[str], str] = {}
226226

227-
def get_token_from_cache(self, host: Optional[str]) -> Optional[str]:
228-
return self._cache.get(host)
227+
def get_token_from_cache(self, key: Optional[str]) -> Optional[str]:
228+
return self._cache.get(key)
229229

230-
def store_token_to_cache(self, host: Optional[str], token: str) -> None:
231-
self._cache[host] = token
230+
def store_token_to_cache(self, key: Optional[str], token: str) -> None:
231+
self._cache[key] = token
232232

233233

234234
class _OAuth2KeyRingTokenCache(_OAuth2TokenCache):
@@ -248,18 +248,18 @@ def is_keyring_available(self) -> bool:
248248
return self._keyring is not None \
249249
and not isinstance(self._keyring.get_keyring(), self._keyring.backends.fail.Keyring)
250250

251-
def get_token_from_cache(self, host: Optional[str]) -> Optional[str]:
251+
def get_token_from_cache(self, key: Optional[str]) -> Optional[str]:
252252
try:
253-
return self._keyring.get_password(host, "token")
253+
return self._keyring.get_password(key, "token")
254254
except self._keyring.errors.NoKeyringError as e:
255255
raise trino.exceptions.NotSupportedError("Although keyring module is installed no backend has been "
256256
"detected, check https://pypi.org/project/keyring/ for more "
257257
"information.") from e
258258

259-
def store_token_to_cache(self, host: Optional[str], token: str) -> None:
259+
def store_token_to_cache(self, key: Optional[str], token: str) -> None:
260260
try:
261261
# keyring is installed, so we can store the token for reuse within multiple threads
262-
self._keyring.set_password(host, "token", token)
262+
self._keyring.set_password(key, "token", token)
263263
except self._keyring.errors.NoKeyringError as e:
264264
raise trino.exceptions.NotSupportedError("Although keyring module is installed no backend has been "
265265
"detected, check https://pypi.org/project/keyring/ for more "
@@ -382,13 +382,13 @@ def _get_token(self, token_server: str, response: Response, **kwargs: Any) -> st
382382

383383
raise exceptions.TrinoAuthError("Exceeded max attempts while getting the token")
384384

385-
def _get_token_from_cache(self, host: Optional[str]) -> Optional[str]:
385+
def _get_token_from_cache(self, key: Optional[str]) -> Optional[str]:
386386
with self._token_lock:
387-
return self._token_cache.get_token_from_cache(host)
387+
return self._token_cache.get_token_from_cache(key)
388388

389-
def _store_token_to_cache(self, host: Optional[str], token: str) -> None:
389+
def _store_token_to_cache(self, key: Optional[str], token: str) -> None:
390390
with self._token_lock:
391-
self._token_cache.store_token_to_cache(host, token)
391+
self._token_cache.store_token_to_cache(key, token)
392392

393393
@staticmethod
394394
def _determine_host(url: Optional[str]) -> Any:

0 commit comments

Comments
 (0)