(database_url: str)
| 26 | |
| 27 | |
| 28 | def parse_database_endpoint(database_url: str) -> tuple[str, int] | None: |
| 29 | normalized = str(database_url or "").strip() |
| 30 | if not normalized.startswith(("postgres://", "postgresql://", "postgresql+psycopg://")): |
| 31 | return None |
| 32 | |
| 33 | parsed = urlparse(normalized) |
| 34 | host = parsed.hostname |
| 35 | if not host: |
| 36 | return None |
| 37 | |
| 38 | port = parsed.port or 5432 |
| 39 | return host, port |
| 40 | |
| 41 | |
| 42 | def can_connect_tcp(host: str, port: int, timeout_seconds: float = 1.5) -> bool: |