Skip to content

Commit 40b3389

Browse files
authored
Separate Public Router for Auth-Free Endpoints (apache#43990)
The PR splits the public_router by creating a common_router for routes that need 401/403 responses, separating them from routes without auth restrictions.
1 parent 61076f0 commit 40b3389

File tree

9 files changed

+278
-268
lines changed

9 files changed

+278
-268
lines changed

airflow/api_fastapi/core_api/openapi/v1-generated.yaml

+27-51
Original file line numberDiff line numberDiff line change
@@ -2155,31 +2155,6 @@ paths:
21552155
application/json:
21562156
schema:
21572157
$ref: '#/components/schemas/HTTPValidationError'
2158-
/public/monitor/health:
2159-
get:
2160-
tags:
2161-
- Monitor
2162-
summary: Get Health
2163-
operationId: get_health
2164-
responses:
2165-
'200':
2166-
description: Successful Response
2167-
content:
2168-
application/json:
2169-
schema:
2170-
$ref: '#/components/schemas/HealthInfoSchema'
2171-
'401':
2172-
description: Unauthorized
2173-
content:
2174-
application/json:
2175-
schema:
2176-
$ref: '#/components/schemas/HTTPExceptionResponse'
2177-
'403':
2178-
description: Forbidden
2179-
content:
2180-
application/json:
2181-
schema:
2182-
$ref: '#/components/schemas/HTTPExceptionResponse'
21832158
/public/plugins/:
21842159
get:
21852160
tags:
@@ -3468,32 +3443,6 @@ paths:
34683443
application/json:
34693444
schema:
34703445
$ref: '#/components/schemas/HTTPValidationError'
3471-
/public/version/:
3472-
get:
3473-
tags:
3474-
- Version
3475-
summary: Get Version
3476-
description: Get version information.
3477-
operationId: get_version
3478-
responses:
3479-
'200':
3480-
description: Successful Response
3481-
content:
3482-
application/json:
3483-
schema:
3484-
$ref: '#/components/schemas/VersionInfo'
3485-
'401':
3486-
description: Unauthorized
3487-
content:
3488-
application/json:
3489-
schema:
3490-
$ref: '#/components/schemas/HTTPExceptionResponse'
3491-
'403':
3492-
description: Forbidden
3493-
content:
3494-
application/json:
3495-
schema:
3496-
$ref: '#/components/schemas/HTTPExceptionResponse'
34973446
/public/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/xcomEntries/{xcom_key}:
34983447
get:
34993448
tags:
@@ -3588,6 +3537,33 @@ paths:
35883537
application/json:
35893538
schema:
35903539
$ref: '#/components/schemas/HTTPValidationError'
3540+
/public/monitor/health:
3541+
get:
3542+
tags:
3543+
- Monitor
3544+
summary: Get Health
3545+
operationId: get_health
3546+
responses:
3547+
'200':
3548+
description: Successful Response
3549+
content:
3550+
application/json:
3551+
schema:
3552+
$ref: '#/components/schemas/HealthInfoSchema'
3553+
/public/version/:
3554+
get:
3555+
tags:
3556+
- Version
3557+
summary: Get Version
3558+
description: Get version information.
3559+
operationId: get_version
3560+
responses:
3561+
'200':
3562+
description: Successful Response
3563+
content:
3564+
application/json:
3565+
schema:
3566+
$ref: '#/components/schemas/VersionInfo'
35913567
components:
35923568
schemas:
35933569
AppBuilderMenuItemResponse:

airflow/api_fastapi/core_api/routes/public/__init__.py

+25-19
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,34 @@
4141
from airflow.api_fastapi.core_api.routes.public.version import version_router
4242
from airflow.api_fastapi.core_api.routes.public.xcom import xcom_router
4343

44-
public_router = AirflowRouter(
45-
prefix="/public",
44+
public_router = AirflowRouter(prefix="/public")
45+
46+
# Router with common attributes for all routes
47+
authenticated_router = AirflowRouter(
4648
responses=create_openapi_http_exception_doc([status.HTTP_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN]),
4749
)
4850

51+
authenticated_router.include_router(assets_router)
52+
authenticated_router.include_router(backfills_router)
53+
authenticated_router.include_router(connections_router)
54+
authenticated_router.include_router(dag_run_router)
55+
authenticated_router.include_router(dag_sources_router)
56+
authenticated_router.include_router(dag_stats_router)
57+
authenticated_router.include_router(dag_warning_router)
58+
authenticated_router.include_router(dags_router)
59+
authenticated_router.include_router(event_logs_router)
60+
authenticated_router.include_router(import_error_router)
61+
authenticated_router.include_router(plugins_router)
62+
authenticated_router.include_router(pools_router)
63+
authenticated_router.include_router(providers_router)
64+
authenticated_router.include_router(task_instances_router)
65+
authenticated_router.include_router(tasks_router)
66+
authenticated_router.include_router(variables_router)
67+
authenticated_router.include_router(xcom_router)
68+
69+
# Include authenticated router in public router
70+
public_router.include_router(authenticated_router)
4971

50-
public_router.include_router(assets_router)
51-
public_router.include_router(backfills_router)
52-
public_router.include_router(connections_router)
53-
public_router.include_router(dag_run_router)
54-
public_router.include_router(dag_sources_router)
55-
public_router.include_router(dag_stats_router)
56-
public_router.include_router(dag_warning_router)
57-
public_router.include_router(dags_router)
58-
public_router.include_router(event_logs_router)
59-
public_router.include_router(import_error_router)
72+
# Following routers are not included in common router, for now we don't expect it to have authentication
6073
public_router.include_router(monitor_router)
61-
public_router.include_router(plugins_router)
62-
public_router.include_router(pools_router)
63-
public_router.include_router(providers_router)
64-
public_router.include_router(task_instances_router)
65-
public_router.include_router(tasks_router)
66-
public_router.include_router(variables_router)
6774
public_router.include_router(version_router)
68-
public_router.include_router(xcom_router)

airflow/ui/openapi-gen/queries/common.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -600,18 +600,6 @@ export const UseImportErrorServiceGetImportErrorsKeyFn = (
600600
useImportErrorServiceGetImportErrorsKey,
601601
...(queryKey ?? [{ limit, offset, orderBy }]),
602602
];
603-
export type MonitorServiceGetHealthDefaultResponse = Awaited<
604-
ReturnType<typeof MonitorService.getHealth>
605-
>;
606-
export type MonitorServiceGetHealthQueryResult<
607-
TData = MonitorServiceGetHealthDefaultResponse,
608-
TError = unknown,
609-
> = UseQueryResult<TData, TError>;
610-
export const useMonitorServiceGetHealthKey = "MonitorServiceGetHealth";
611-
export const UseMonitorServiceGetHealthKeyFn = (queryKey?: Array<unknown>) => [
612-
useMonitorServiceGetHealthKey,
613-
...(queryKey ?? []),
614-
];
615603
export type PluginServiceGetPluginsDefaultResponse = Awaited<
616604
ReturnType<typeof PluginService.getPlugins>
617605
>;
@@ -1000,18 +988,6 @@ export const UseVariableServiceGetVariablesKeyFn = (
1000988
useVariableServiceGetVariablesKey,
1001989
...(queryKey ?? [{ limit, offset, orderBy }]),
1002990
];
1003-
export type VersionServiceGetVersionDefaultResponse = Awaited<
1004-
ReturnType<typeof VersionService.getVersion>
1005-
>;
1006-
export type VersionServiceGetVersionQueryResult<
1007-
TData = VersionServiceGetVersionDefaultResponse,
1008-
TError = unknown,
1009-
> = UseQueryResult<TData, TError>;
1010-
export const useVersionServiceGetVersionKey = "VersionServiceGetVersion";
1011-
export const UseVersionServiceGetVersionKeyFn = (queryKey?: Array<unknown>) => [
1012-
useVersionServiceGetVersionKey,
1013-
...(queryKey ?? []),
1014-
];
1015991
export type XcomServiceGetXcomEntryDefaultResponse = Awaited<
1016992
ReturnType<typeof XcomService.getXcomEntry>
1017993
>;
@@ -1045,6 +1021,30 @@ export const UseXcomServiceGetXcomEntryKeyFn = (
10451021
{ dagId, dagRunId, deserialize, mapIndex, stringify, taskId, xcomKey },
10461022
]),
10471023
];
1024+
export type MonitorServiceGetHealthDefaultResponse = Awaited<
1025+
ReturnType<typeof MonitorService.getHealth>
1026+
>;
1027+
export type MonitorServiceGetHealthQueryResult<
1028+
TData = MonitorServiceGetHealthDefaultResponse,
1029+
TError = unknown,
1030+
> = UseQueryResult<TData, TError>;
1031+
export const useMonitorServiceGetHealthKey = "MonitorServiceGetHealth";
1032+
export const UseMonitorServiceGetHealthKeyFn = (queryKey?: Array<unknown>) => [
1033+
useMonitorServiceGetHealthKey,
1034+
...(queryKey ?? []),
1035+
];
1036+
export type VersionServiceGetVersionDefaultResponse = Awaited<
1037+
ReturnType<typeof VersionService.getVersion>
1038+
>;
1039+
export type VersionServiceGetVersionQueryResult<
1040+
TData = VersionServiceGetVersionDefaultResponse,
1041+
TError = unknown,
1042+
> = UseQueryResult<TData, TError>;
1043+
export const useVersionServiceGetVersionKey = "VersionServiceGetVersion";
1044+
export const UseVersionServiceGetVersionKeyFn = (queryKey?: Array<unknown>) => [
1045+
useVersionServiceGetVersionKey,
1046+
...(queryKey ?? []),
1047+
];
10481048
export type BackfillServiceCreateBackfillMutationResult = Awaited<
10491049
ReturnType<typeof BackfillService.createBackfill>
10501050
>;

airflow/ui/openapi-gen/queries/prefetch.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -784,16 +784,6 @@ export const prefetchUseImportErrorServiceGetImportErrors = (
784784
queryFn: () =>
785785
ImportErrorService.getImportErrors({ limit, offset, orderBy }),
786786
});
787-
/**
788-
* Get Health
789-
* @returns HealthInfoSchema Successful Response
790-
* @throws ApiError
791-
*/
792-
export const prefetchUseMonitorServiceGetHealth = (queryClient: QueryClient) =>
793-
queryClient.prefetchQuery({
794-
queryKey: Common.UseMonitorServiceGetHealthKeyFn(),
795-
queryFn: () => MonitorService.getHealth(),
796-
});
797787
/**
798788
* Get Plugins
799789
* @param data The data for the request.
@@ -1347,17 +1337,6 @@ export const prefetchUseVariableServiceGetVariables = (
13471337
}),
13481338
queryFn: () => VariableService.getVariables({ limit, offset, orderBy }),
13491339
});
1350-
/**
1351-
* Get Version
1352-
* Get version information.
1353-
* @returns VersionInfo Successful Response
1354-
* @throws ApiError
1355-
*/
1356-
export const prefetchUseVersionServiceGetVersion = (queryClient: QueryClient) =>
1357-
queryClient.prefetchQuery({
1358-
queryKey: Common.UseVersionServiceGetVersionKeyFn(),
1359-
queryFn: () => VersionService.getVersion(),
1360-
});
13611340
/**
13621341
* Get Xcom Entry
13631342
* Get an XCom entry.
@@ -1413,3 +1392,24 @@ export const prefetchUseXcomServiceGetXcomEntry = (
14131392
xcomKey,
14141393
}),
14151394
});
1395+
/**
1396+
* Get Health
1397+
* @returns HealthInfoSchema Successful Response
1398+
* @throws ApiError
1399+
*/
1400+
export const prefetchUseMonitorServiceGetHealth = (queryClient: QueryClient) =>
1401+
queryClient.prefetchQuery({
1402+
queryKey: Common.UseMonitorServiceGetHealthKeyFn(),
1403+
queryFn: () => MonitorService.getHealth(),
1404+
});
1405+
/**
1406+
* Get Version
1407+
* Get version information.
1408+
* @returns VersionInfo Successful Response
1409+
* @throws ApiError
1410+
*/
1411+
export const prefetchUseVersionServiceGetVersion = (queryClient: QueryClient) =>
1412+
queryClient.prefetchQuery({
1413+
queryKey: Common.UseVersionServiceGetVersionKeyFn(),
1414+
queryFn: () => VersionService.getVersion(),
1415+
});

airflow/ui/openapi-gen/queries/queries.ts

+37-37
Original file line numberDiff line numberDiff line change
@@ -959,24 +959,6 @@ export const useImportErrorServiceGetImportErrors = <
959959
ImportErrorService.getImportErrors({ limit, offset, orderBy }) as TData,
960960
...options,
961961
});
962-
/**
963-
* Get Health
964-
* @returns HealthInfoSchema Successful Response
965-
* @throws ApiError
966-
*/
967-
export const useMonitorServiceGetHealth = <
968-
TData = Common.MonitorServiceGetHealthDefaultResponse,
969-
TError = unknown,
970-
TQueryKey extends Array<unknown> = unknown[],
971-
>(
972-
queryKey?: TQueryKey,
973-
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
974-
) =>
975-
useQuery<TData, TError>({
976-
queryKey: Common.UseMonitorServiceGetHealthKeyFn(queryKey),
977-
queryFn: () => MonitorService.getHealth() as TData,
978-
...options,
979-
});
980962
/**
981963
* Get Plugins
982964
* @param data The data for the request.
@@ -1619,25 +1601,6 @@ export const useVariableServiceGetVariables = <
16191601
VariableService.getVariables({ limit, offset, orderBy }) as TData,
16201602
...options,
16211603
});
1622-
/**
1623-
* Get Version
1624-
* Get version information.
1625-
* @returns VersionInfo Successful Response
1626-
* @throws ApiError
1627-
*/
1628-
export const useVersionServiceGetVersion = <
1629-
TData = Common.VersionServiceGetVersionDefaultResponse,
1630-
TError = unknown,
1631-
TQueryKey extends Array<unknown> = unknown[],
1632-
>(
1633-
queryKey?: TQueryKey,
1634-
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
1635-
) =>
1636-
useQuery<TData, TError>({
1637-
queryKey: Common.UseVersionServiceGetVersionKeyFn(queryKey),
1638-
queryFn: () => VersionService.getVersion() as TData,
1639-
...options,
1640-
});
16411604
/**
16421605
* Get Xcom Entry
16431606
* Get an XCom entry.
@@ -1694,6 +1657,43 @@ export const useXcomServiceGetXcomEntry = <
16941657
}) as TData,
16951658
...options,
16961659
});
1660+
/**
1661+
* Get Health
1662+
* @returns HealthInfoSchema Successful Response
1663+
* @throws ApiError
1664+
*/
1665+
export const useMonitorServiceGetHealth = <
1666+
TData = Common.MonitorServiceGetHealthDefaultResponse,
1667+
TError = unknown,
1668+
TQueryKey extends Array<unknown> = unknown[],
1669+
>(
1670+
queryKey?: TQueryKey,
1671+
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
1672+
) =>
1673+
useQuery<TData, TError>({
1674+
queryKey: Common.UseMonitorServiceGetHealthKeyFn(queryKey),
1675+
queryFn: () => MonitorService.getHealth() as TData,
1676+
...options,
1677+
});
1678+
/**
1679+
* Get Version
1680+
* Get version information.
1681+
* @returns VersionInfo Successful Response
1682+
* @throws ApiError
1683+
*/
1684+
export const useVersionServiceGetVersion = <
1685+
TData = Common.VersionServiceGetVersionDefaultResponse,
1686+
TError = unknown,
1687+
TQueryKey extends Array<unknown> = unknown[],
1688+
>(
1689+
queryKey?: TQueryKey,
1690+
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
1691+
) =>
1692+
useQuery<TData, TError>({
1693+
queryKey: Common.UseVersionServiceGetVersionKeyFn(queryKey),
1694+
queryFn: () => VersionService.getVersion() as TData,
1695+
...options,
1696+
});
16971697
/**
16981698
* Create Backfill
16991699
* @param data The data for the request.

0 commit comments

Comments
 (0)