Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Bypass auth for health check #1409

Merged
merged 3 commits into from
Dec 10, 2024
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
3 changes: 2 additions & 1 deletion backend/lcfs/web/api/monitoring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@


@router.get("/health")
def health_check() -> None:
def health_check() -> str:
"""
Checks the health of a project.

It returns 200 if the project is healthy.
"""
return "healthy"
19 changes: 9 additions & 10 deletions backend/lcfs/web/application.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
from importlib import metadata
import structlog
import logging
import uuid

import os
import debugpy
import structlog
from fastapi import FastAPI, HTTPException
from fastapi.exceptions import RequestValidationError
from fastapi.responses import UJSONResponse
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import UJSONResponse
from prometheus_fastapi_instrumentator import Instrumentator
from starlette.middleware.authentication import AuthenticationMiddleware
from starlette.authentication import (
AuthenticationBackend,
AuthCredentials,
UnauthenticatedUser,
)
from starlette.middleware.authentication import AuthenticationMiddleware
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.requests import Request
from starlette.responses import JSONResponse
import uuid
import contextvars

from lcfs.settings import settings
from lcfs.logging_config import setup_logging, correlation_id_var
from lcfs.web.api.router import api_router
from lcfs.services.keycloak.authentication import UserAuthentication
from lcfs.settings import settings
from lcfs.web.api.router import api_router
from lcfs.web.exception.exception_handler import validation_exception_handler
from lcfs.web.lifetime import register_shutdown_event, register_startup_event

Expand Down Expand Up @@ -67,6 +63,9 @@ async def authenticate(self, request):
if request.scope["method"] == "OPTIONS":
return AuthCredentials([]), UnauthenticatedUser()

if request.url.path == "/api/health": # Skip for health check
return AuthCredentials([]), UnauthenticatedUser()

# Lazily retrieve Redis, session, and settings from app state
redis_client = self.app.state.redis_client
session_factory = self.app.state.db_session_factory
Expand Down