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

Migrate the public endpoint Get DAG Source to FastAPI #43084

Merged
merged 2 commits into from
Oct 30, 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
2 changes: 2 additions & 0 deletions airflow/api_connexion/endpoints/dag_source_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from airflow.auth.managers.models.resource_details import DagAccessEntity, DagDetails
from airflow.models.dag import DagModel
from airflow.models.dagcode import DagCode
from airflow.utils.api_migration import mark_fastapi_migration_done
from airflow.utils.session import NEW_SESSION, provide_session
from airflow.www.extensions.init_auth_manager import get_auth_manager

Expand All @@ -37,6 +38,7 @@
from airflow.auth.managers.models.batch_apis import IsAuthorizedDagRequest


@mark_fastapi_migration_done
omkar-foss marked this conversation as resolved.
Show resolved Hide resolved
@security.requires_access_dag("GET", DagAccessEntity.CODE)
@provide_session
def get_dag_source(*, file_token: str, session: Session = NEW_SESSION) -> Response:
Expand Down
18 changes: 2 additions & 16 deletions airflow/api_fastapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import logging

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from airflow.api_fastapi.core_api.app import init_dag_bag, init_plugins, init_views
from airflow.api_fastapi.core_api.app import init_config, init_dag_bag, init_plugins, init_views
from airflow.api_fastapi.execution_api.app import create_task_execution_api_app

log = logging.getLogger(__name__)
Expand All @@ -30,8 +29,6 @@


def create_app(apps: str = "all") -> FastAPI:
from airflow.configuration import conf

apps_list = apps.split(",") if apps else ["all"]

app = FastAPI(
Expand All @@ -50,18 +47,7 @@ def create_app(apps: str = "all") -> FastAPI:
task_exec_api_app = create_task_execution_api_app(app)
app.mount("/execution", task_exec_api_app)

allow_origins = conf.getlist("api", "access_control_allow_origins")
allow_methods = conf.getlist("api", "access_control_allow_methods")
allow_headers = conf.getlist("api", "access_control_allow_headers")

if allow_origins or allow_methods or allow_headers:
app.add_middleware(
CORSMiddleware,
allow_origins=allow_origins,
allow_credentials=True,
allow_methods=allow_methods,
allow_headers=allow_headers,
)
init_config(app)

return app

Expand Down
20 changes: 20 additions & 0 deletions airflow/api_fastapi/core_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import cast

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.staticfiles import StaticFiles
Expand Down Expand Up @@ -94,3 +95,22 @@ def init_plugins(app: FastAPI) -> None:

log.debug("Adding subapplication %s under prefix %s", name, url_prefix)
app.mount(url_prefix, subapp)


def init_config(app: FastAPI) -> None:
from airflow.configuration import conf

allow_origins = conf.getlist("api", "access_control_allow_origins")
allow_methods = conf.getlist("api", "access_control_allow_methods")
allow_headers = conf.getlist("api", "access_control_allow_headers")

if allow_origins or allow_methods or allow_headers:
app.add_middleware(
CORSMiddleware,
allow_origins=allow_origins,
allow_credentials=True,
allow_methods=allow_methods,
allow_headers=allow_headers,
)

app.state.secret_key = conf.get("webserver", "secret_key")
Loading
Loading