Skip to content

Commit

Permalink
Cache JWT manager so it's not reimported dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
patrys committed Jun 13, 2024
1 parent 543e161 commit d278d32
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions saleor/core/jwt_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
from functools import cache
from os.path import exists, join
from typing import Optional, Union, cast

Expand Down Expand Up @@ -74,6 +75,7 @@ def get_domain(cls) -> str:
return get_domain()

@classmethod
@cache
def get_private_key(cls) -> rsa.RSAPrivateKey:
pem = settings.RSA_PRIVATE_KEY
if not pem:
Expand Down Expand Up @@ -130,6 +132,7 @@ def _create_local_private_key(cls, path) -> rsa.RSAPrivateKey:
return private_key

@classmethod
@cache
def get_public_key(cls) -> rsa.RSAPublicKey:
global PUBLIC_KEY

Expand Down Expand Up @@ -211,6 +214,8 @@ def validate_configuration(cls):
)
logger.warning(color_style().WARNING(msg))

cls.get_private_key.cache_clear()
cls.get_public_key.cache_clear()
try:
cls.get_private_key()
except Exception as e:
Expand All @@ -221,5 +226,6 @@ def get_issuer(cls) -> str:
return build_absolute_uri(reverse("api"), domain=cls.get_domain())


@cache
def get_jwt_manager() -> JWTManagerBase:
return import_string(settings.JWT_MANAGER_PATH)

0 comments on commit d278d32

Please sign in to comment.