25 lines
931 B
Python
25 lines
931 B
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.dependencies import get_auth_db, get_current_auth_session
|
|
from app.schemas.public_ip import PublicIPCheckResponse
|
|
from app.services.auth import AuthenticatedSession
|
|
from app.services.public_ip import check_public_ipv4
|
|
|
|
router = APIRouter(tags=["public-ip"])
|
|
|
|
|
|
@router.get("/public-ip/check", response_model=PublicIPCheckResponse)
|
|
def run_public_ip_check(
|
|
session: Session = Depends(get_auth_db),
|
|
current_auth: AuthenticatedSession | None = Depends(get_current_auth_session),
|
|
) -> PublicIPCheckResponse:
|
|
if current_auth is None:
|
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="authentication required")
|
|
|
|
result = check_public_ipv4(session)
|
|
return PublicIPCheckResponse(
|
|
status=result.status,
|
|
checked_at=result.checked_at,
|
|
changed=result.changed,
|
|
) |