Skip to content

Commit f44d225

Browse files
committed
Migrate deprecated flask-session filesystem backend to cachelib
1 parent 939eec5 commit f44d225

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ssh_keyservice/app_config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from azure.identity import DefaultAzureCredential
44
from azure.keyvault.secrets import SecretClient
55

6+
from cachelib.file import FileSystemCache
7+
68
# Configure Azure Key Vault
79
KEY_VAULT_URL = os.getenv("AZURE_KEY_VAULT_URL", "https://your-keyvault-name.vault.azure.net")
810
credential = DefaultAzureCredential()
@@ -49,7 +51,7 @@ def get_secret(secret_name: str) -> str:
4951
#LIMITS_DB_PORT = os.getenv("LIMITS_DB_PORT") or 6379
5052

5153
# Tells the Flask-session extension to store sessions in the filesystem
52-
SESSION_TYPE = "filesystem"
54+
SESSION_TYPE = "cachelib"
5355
# In production, your setup may use multiple web servers behind a load balancer,
5456
# and the subsequent requests may not be routed to the same web server.
5557
# In that case, you may either use a centralized database-backed session store,
@@ -58,6 +60,8 @@ def get_secret(secret_name: str) -> str:
5860
# [1] https://www.imperva.com/learn/availability/sticky-session-persistence-and-cookies/
5961
# [2] https://azure.github.io/AppService/2016/05/16/Disable-Session-affinity-cookie-(ARR-cookie)-for-Azure-web-apps.html
6062
# [3] https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal#configure-general-settings
63+
SESSION_SERIALIZATION_FORMAT = 'json'
64+
SESSION_CACHELIB = FileSystemCache(threshold=500, cache_dir="flask_session")
6165

6266
# Flask secret key
6367
SECRET_KEY = get_secret("FLASK-SECRET-KEY")

0 commit comments

Comments
 (0)