(
request: Request,
host: str,
db: AsyncSession = Depends(get_db),
settings: Settings = Depends(get_settings),
)
| 94 | |
| 95 | @app.get("/deployment-not-found/{host}") |
| 96 | async def catch_all_missing_container( |
| 97 | request: Request, |
| 98 | host: str, |
| 99 | db: AsyncSession = Depends(get_db), |
| 100 | settings: Settings = Depends(get_settings), |
| 101 | ): |
| 102 | current_user = await get_current_user( |
| 103 | request=request, |
| 104 | db=db, |
| 105 | settings=settings, |
| 106 | redirect_on_fail=False, |
| 107 | ) |
| 108 | |
| 109 | if current_user and host.endswith(settings.deploy_domain): |
| 110 | import re |
| 111 | |
| 112 | subdomain = host.removesuffix(f".{settings.deploy_domain}") |
| 113 | |
| 114 | match = re.match( |
| 115 | r"^(?P<project_slug>.+)-id-(?P<short_id>[a-f0-9]{7})$", subdomain |
| 116 | ) |
| 117 | if match: |
| 118 | project_slug = match.group("project_slug") |
| 119 | short_id = match.group("short_id") |
| 120 | async with AsyncSessionLocal() as db: |
| 121 | result = await db.execute( |
| 122 | select(Deployment, Project, Team) |
| 123 | .join(Project, Deployment.project_id == Project.id) |
| 124 | .join(Team, Project.team_id == Team.id) |
| 125 | .where( |
| 126 | Project.slug == project_slug, |
| 127 | Deployment.id.startswith(short_id), |
| 128 | ) |
| 129 | ) |
| 130 | deployment, project, team = result.first() or (None, None, None) |
| 131 | if deployment: |
| 132 | return TemplateResponse( |
| 133 | request=request, |
| 134 | name="error/deployment-not-found.html", |
| 135 | status_code=404, |
| 136 | context={ |
| 137 | "current_user": current_user, |
| 138 | "deployment_url": request.url_for( |
| 139 | "project_deployment", |
| 140 | team_slug=team.slug, |
| 141 | project_name=project.name, |
| 142 | deployment_id=deployment.id, |
| 143 | ).include_query_params(action="redeploy"), |
| 144 | "deployment_id": deployment.id, |
| 145 | }, |
| 146 | ) |
| 147 | |
| 148 | return TemplateResponse( |
| 149 | request=request, |
| 150 | name="error/deployment-not-found.html", |
| 151 | status_code=404, |
| 152 | context={"current_user": current_user}, |
| 153 | ) |
nothing calls this directly
no test coverage detected