From 3ee7c0f65210b5145a32a36a1c64f07267ba1119 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Fri, 21 Feb 2025 11:26:47 +0100 Subject: [PATCH] fix(backend): load jwt secret from disk --- backend/bec_atlas/authentication.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/bec_atlas/authentication.py b/backend/bec_atlas/authentication.py index 288ed5d..2d19640 100644 --- a/backend/bec_atlas/authentication.py +++ b/backend/bec_atlas/authentication.py @@ -2,7 +2,7 @@ from __future__ import annotations import os from datetime import datetime, timedelta -from functools import wraps +from functools import lru_cache, wraps import jwt from fastapi import Depends, HTTPException, Request, status @@ -37,9 +37,17 @@ def convert_to_user(func): return wrapper +@lru_cache() def get_secret_key(): - val = os.getenv("SECRET_KEY", "test_secret") - return val + """ + Load the JWT secret from disk or use a default value. + """ + deployment_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "deployment") + secret_file = os.path.join(deployment_dir, ".jwt_secret") + if not os.path.exists(secret_file): + return "test_secret" + with open(secret_file, "r", encoding="utf-8") as token_file: + return token_file.read().strip() def verify_password(plain_password, hashed_password):