diff --git a/backend/api/server_fastapi_router.py b/backend/api/server_fastapi_router.py index 417a6cc..42aef2d 100644 --- a/backend/api/server_fastapi_router.py +++ b/backend/api/server_fastapi_router.py @@ -20,7 +20,7 @@ class ServerFastAPIRouter: def __init__( self, server_instance, - is_internal_env: bool, + is_file_change_enabled: bool, environment: str = "dev", processing_service_cls=None ): @@ -30,12 +30,12 @@ def __init__( Args: server_instance: The Modal server instance for accessing connectors and spawning local methods - is_internal_env: Whether this is an internal (dev/staging) environment + is_file_change_enabled: Whether this file change is enabled in this environment environment: Environment name (dev, staging, prod) for cross-app lookups processing_service_cls: Optional ProcessingService class for dev combined mode (direct access) """ self.server_instance = server_instance - self.is_internal_env = is_internal_env + self.is_file_change_enabled = is_file_change_enabled self.environment = environment self.processing_service_cls = processing_service_cls self.router = APIRouter() @@ -211,7 +211,7 @@ async def delete_video(self, hashed_identifier: str, filename: str, namespace: s - 403 Forbidden if deletion is not allowed. """ logger.info(f"[Delete Video] Request to delete video: {filename} ({hashed_identifier}) | namespace='{namespace}'") - if not self.is_internal_env: + if not self.is_file_change_enabled: raise HTTPException(status_code=403, detail="Video deletion is not allowed in the current environment.") job_id = str(uuid.uuid4()) @@ -247,7 +247,7 @@ async def clear_cache(self, namespace: str = "__default__"): HTTPException: If cache clearing is not allowed (403 Forbidden) """ logger.info(f"[Clear Cache] Request to clear cache for namespace: {namespace}") - if not self.is_internal_env: + if not self.is_file_change_enabled: raise HTTPException(status_code=403, detail="Cache clearing is not allowed in the current environment.") try: diff --git a/backend/services/http_server.py b/backend/services/http_server.py index 595462b..a940221 100644 --- a/backend/services/http_server.py +++ b/backend/services/http_server.py @@ -32,6 +32,7 @@ def _initialize_connectors(self): R2_ACCOUNT_ID = get_env_var("R2_ACCOUNT_ID") R2_ACCESS_KEY_ID = get_env_var("R2_ACCESS_KEY_ID") R2_SECRET_ACCESS_KEY = get_env_var("R2_SECRET_ACCESS_KEY") + IS_FILE_CHANGE_ENABLED = get_env_var("IS_FILE_CHANGE_ENABLED").lower() == "true" pinecone_index = get_pinecone_index() logger.info(f"[{self.__class__.__name__}] Using Pinecone index: {pinecone_index}") @@ -52,7 +53,7 @@ def _initialize_connectors(self): # Store config for router self.env = env - self.is_internal = env in ["dev", "staging"] + self.is_file_change_enabled = IS_FILE_CHANGE_ENABLED logger.info(f"[{self.__class__.__name__}] Initialized and ready!") @@ -76,7 +77,7 @@ def create_fastapi_app(self, processing_service_cls=None): self.fastapi_app = FastAPI(title="Clipabit Server") api_router = ServerFastAPIRouter( server_instance=self, - is_internal_env=self.is_internal, + is_file_change_enabled=self.is_file_change_enabled, environment=self.env, processing_service_cls=processing_service_cls ) diff --git a/backend/shared/config.py b/backend/shared/config.py index 06fc008..3e83537 100644 --- a/backend/shared/config.py +++ b/backend/shared/config.py @@ -83,17 +83,6 @@ def get_secrets() -> modal.Secret: return modal.Secret.from_name(env) -def is_internal_env() -> bool: - """ - Check if running in an internal (non-production) environment. - - Returns: - bool: True if dev or staging, False if prod - """ - env = get_environment() - return env in ["dev", "staging"] - - def get_pinecone_index() -> str: """ Get the Pinecone index name for the current environment. diff --git a/backend/tests/integration/test_api_endpoints.py b/backend/tests/integration/test_api_endpoints.py index 8f7e208..8e03057 100644 --- a/backend/tests/integration/test_api_endpoints.py +++ b/backend/tests/integration/test_api_endpoints.py @@ -185,11 +185,11 @@ def lookup_side_effect(app_name: str, class_name: str, **kwargs): @pytest.fixture() def test_client_internal(mock_modal_lookup) -> Tuple[TestClient, ServerStub, dict]: """ - FastAPI TestClient with is_internal_env=True, so delete is allowed. + FastAPI TestClient with is_file_change_enabled=True, so delete is allowed. """ server = ServerStub() app = FastAPI() - router = ServerFastAPIRouter(server, is_internal_env=True, environment="dev") + router = ServerFastAPIRouter(server, is_file_change_enabled=True, environment="dev") app.include_router(router.router) return TestClient(app), server, mock_modal_lookup @@ -197,11 +197,11 @@ def test_client_internal(mock_modal_lookup) -> Tuple[TestClient, ServerStub, dic @pytest.fixture() def test_client_external(mock_modal_lookup) -> Tuple[TestClient, ServerStub, dict]: """ - FastAPI TestClient with is_internal_env=False, so delete is forbidden. + FastAPI TestClient with is_file_change_enabled=False, so delete is forbidden. """ server = ServerStub() app = FastAPI() - router = ServerFastAPIRouter(server, is_internal_env=False, environment="prod") + router = ServerFastAPIRouter(server, is_file_change_enabled=False, environment="prod") app.include_router(router.router) return TestClient(app), server, mock_modal_lookup