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 <noreply@anthropic.com>
This commit is contained in:
airano
2026-02-17 18:32:44 +03:30
parent c619089403
commit 0aefc29dee
2 changed files with 11 additions and 5 deletions

View File

@@ -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)

View File

@@ -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