Skip to content

Commit

Permalink
Migrate public endpoint Get DAG Source to FastAPI, with main resynced
Browse files Browse the repository at this point in the history
  • Loading branch information
omkar-foss committed Oct 22, 2024
1 parent fcfc6f9 commit 99ae809
Show file tree
Hide file tree
Showing 13 changed files with 1,077 additions and 844 deletions.
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")
265 changes: 164 additions & 101 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,151 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/connections/{connection_id}:
delete:
tags:
- Connection
summary: Delete Connection
description: Delete a connection entry.
operationId: delete_connection
parameters:
- name: connection_id
in: path
required: true
schema:
type: string
title: Connection Id
responses:
'204':
description: Successful Response
'401':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Unauthorized
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Forbidden
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Not Found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
get:
tags:
- Connection
summary: Get Connection
description: Get a connection entry.
operationId: get_connection
parameters:
- name: connection_id
in: path
required: true
schema:
type: string
title: Connection Id
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/ConnectionResponse'
'401':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Unauthorized
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Forbidden
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Not Found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/connections/:
get:
tags:
- Connection
summary: Get Connections
description: Get all connection entries.
operationId: get_connections
parameters:
- name: limit
in: query
required: false
schema:
type: integer
default: 100
title: Limit
- name: offset
in: query
required: false
schema:
type: integer
default: 0
title: Offset
- name: order_by
in: query
required: false
schema:
type: string
default: id
title: Order By
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/ConnectionCollectionResponse'
'401':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Unauthorized
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Forbidden
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Not Found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/dags/:
get:
tags:
Expand Down Expand Up @@ -570,67 +715,32 @@ paths:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Unprocessable Entity
/public/connections/{connection_id}:
delete:
/public/dagSources/{file_token}:
get:
tags:
- Connection
summary: Delete Connection
description: Delete a connection entry.
operationId: delete_connection
- DagSource
summary: Get Dag Source
description: Get source code using file token.
operationId: get_dag_source
parameters:
- name: connection_id
- name: file_token
in: path
required: true
schema:
type: string
title: Connection Id
title: File Token
responses:
'204':
'200':
description: Successful Response
'401':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Unauthorized
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Forbidden
'404':
schema: {}
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Not Found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
get:
tags:
- Connection
summary: Get Connection
description: Get a connection entry.
operationId: get_connection
parameters:
- name: connection_id
in: path
required: true
schema:
type: string
title: Connection Id
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/ConnectionResponse'
description: Bad Request
'401':
content:
application/json:
Expand All @@ -650,71 +760,24 @@ paths:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Not Found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/connections/:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Unprocessable Entity
/public/monitor/health:
get:
tags:
- Connection
summary: Get Connections
description: Get all connection entries.
operationId: get_connections
parameters:
- name: limit
in: query
required: false
schema:
type: integer
default: 100
title: Limit
- name: offset
in: query
required: false
schema:
type: integer
default: 0
title: Offset
- name: order_by
in: query
required: false
schema:
type: string
default: id
title: Order By
- Monitor
summary: Get Health
operationId: get_health
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/ConnectionCollectionResponse'
'401':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Unauthorized
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Forbidden
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Not Found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
$ref: '#/components/schemas/HealthInfoSchema'
/public/variables/{variable_key}:
delete:
tags:
Expand Down
Loading

0 comments on commit 99ae809

Please sign in to comment.