Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions backend/api/server_fastapi_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand All @@ -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()
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions backend/services/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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!")

Expand All @@ -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
)
Expand Down
11 changes: 0 additions & 11 deletions backend/shared/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/integration/test_api_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,23 @@ 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


@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

Expand Down
Loading