From 0aefc29dee8c981274cc707397c54a8036bff466 Mon Sep 17 00:00:00 2001 From: airano Date: Tue, 17 Feb 2026 18:32:44 +0330 Subject: [PATCH] fix(oauth): fallback storage path for CI and local dev Both JSONStorage and ClientRegistry now use ./data when /app doesn't exist (Docker vs local/CI environments). Co-Authored-By: Claude Opus 4.6 --- core/oauth/client_registry.py | 6 +++++- core/oauth/storage.py | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/oauth/client_registry.py b/core/oauth/client_registry.py index 15fc47f..36a0ce0 100644 --- a/core/oauth/client_registry.py +++ b/core/oauth/client_registry.py @@ -13,6 +13,9 @@ from .schemas import OAuthClient logger = logging.getLogger(__name__) +# Default data directory: /app/data in Docker, ./data elsewhere +_DEFAULT_DATA_DIR = "/app/data" if Path("/app").exists() else "./data" + class ClientRegistry: """ @@ -21,7 +24,8 @@ class ClientRegistry: Storage: data/oauth_clients.json """ - def __init__(self, data_dir: str = "/app/data"): + def __init__(self, data_dir: str | None = None): + data_dir = data_dir or _DEFAULT_DATA_DIR self.data_dir = Path(data_dir) self.data_dir.mkdir(parents=True, exist_ok=True) diff --git a/core/oauth/storage.py b/core/oauth/storage.py index 04d0a0b..bfcde90 100644 --- a/core/oauth/storage.py +++ b/core/oauth/storage.py @@ -13,6 +13,9 @@ from .schemas import AccessToken, AuthorizationCode, RefreshToken logger = logging.getLogger(__name__) +# Default data directory: /app/data in Docker, ./data elsewhere +_DEFAULT_DATA_DIR = "/app/data" if Path("/app").exists() else "./data" + class BaseStorage: """Base storage interface""" @@ -55,8 +58,8 @@ class JSONStorage(BaseStorage): data/oauth_refresh_tokens.json - Refresh tokens """ - def __init__(self, data_dir: str = "/app/data"): - self.data_dir = Path(data_dir) + def __init__(self, data_dir: str | None = None): + self.data_dir = Path(data_dir or _DEFAULT_DATA_DIR) self.data_dir.mkdir(parents=True, exist_ok=True) self.codes_file = self.data_dir / "oauth_codes.json" @@ -213,8 +216,7 @@ def get_storage() -> BaseStorage: storage_type = os.getenv("OAUTH_STORAGE_TYPE", "json") if storage_type == "json": - default_path = "/app/data" if Path("/app").exists() else "./data" - storage_path = os.getenv("OAUTH_STORAGE_PATH", default_path) + storage_path = os.getenv("OAUTH_STORAGE_PATH", _DEFAULT_DATA_DIR) return JSONStorage(storage_path) # Future: Redis support