mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-01-06 11:09:57 -08:00
c93f470371
* Bump pyjwt from 2.6.0 to 2.8.0 Bumps [pyjwt](https://github.com/jpadilla/pyjwt) from 2.6.0 to 2.8.0. - [Release notes](https://github.com/jpadilla/pyjwt/releases) - [Changelog](https://github.com/jpadilla/pyjwt/blob/master/CHANGELOG.rst) - [Commits](https://github.com/jpadilla/pyjwt/compare/2.6.0...2.8.0) --- updated-dependencies: - dependency-name: pyjwt dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Update pyjwt==2.8.0 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> [skip ci]
32 lines
959 B
Python
32 lines
959 B
Python
import time
|
|
from typing import Optional
|
|
|
|
from .api_jwk import PyJWKSet, PyJWTSetWithTimestamp
|
|
|
|
|
|
class JWKSetCache:
|
|
def __init__(self, lifespan: int) -> None:
|
|
self.jwk_set_with_timestamp: Optional[PyJWTSetWithTimestamp] = None
|
|
self.lifespan = lifespan
|
|
|
|
def put(self, jwk_set: PyJWKSet) -> None:
|
|
if jwk_set is not None:
|
|
self.jwk_set_with_timestamp = PyJWTSetWithTimestamp(jwk_set)
|
|
else:
|
|
# clear cache
|
|
self.jwk_set_with_timestamp = None
|
|
|
|
def get(self) -> Optional[PyJWKSet]:
|
|
if self.jwk_set_with_timestamp is None or self.is_expired():
|
|
return None
|
|
|
|
return self.jwk_set_with_timestamp.get_jwk_set()
|
|
|
|
def is_expired(self) -> bool:
|
|
return (
|
|
self.jwk_set_with_timestamp is not None
|
|
and self.lifespan > -1
|
|
and time.monotonic()
|
|
> self.jwk_set_with_timestamp.get_timestamp() + self.lifespan
|
|
)
|