Skip to content
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
34 changes: 34 additions & 0 deletions airflow/api_fastapi/core_api/datamodels/ui/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from __future__ import annotations

from airflow.api_fastapi.core_api.base import BaseModel


class MenuItem(BaseModel):
"""Menu Item for responses."""

text: str
href: str


class MenuItemCollectionResponse(BaseModel):
"""Menu Item Collection serializer for responses."""

menu_items: list[MenuItem]
total_entries: int
45 changes: 45 additions & 0 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ info:
Users should not rely on those but use the public ones instead.
version: 0.1.0
paths:
/ui/auth/links:
get:
tags:
- Auth Links
summary: Get Auth Links
operationId: get_auth_links
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/MenuItemCollectionResponse'
security:
- OAuth2PasswordBearer: []
/ui/next_run_assets/{dag_id}:
get:
tags:
Expand Down Expand Up @@ -10008,6 +10023,36 @@ components:
- unixname
title: JobResponse
description: Job serializer for responses.
MenuItem:
properties:
text:
type: string
title: Text
href:
type: string
title: Href
type: object
required:
- text
- href
title: MenuItem
description: Menu Item for responses.
MenuItemCollectionResponse:
properties:
menu_items:
items:
$ref: '#/components/schemas/MenuItem'
type: array
title: Menu Items
total_entries:
type: integer
title: Total Entries
type: object
required:
- menu_items
- total_entries
title: MenuItemCollectionResponse
description: Menu Item Collection serializer for responses.
NodeResponse:
properties:
id:
Expand Down
2 changes: 2 additions & 0 deletions airflow/api_fastapi/core_api/routes/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from airflow.api_fastapi.common.router import AirflowRouter
from airflow.api_fastapi.core_api.routes.ui.assets import assets_router
from airflow.api_fastapi.core_api.routes.ui.auth import auth_router
from airflow.api_fastapi.core_api.routes.ui.backfills import backfills_router
from airflow.api_fastapi.core_api.routes.ui.config import config_router
from airflow.api_fastapi.core_api.routes.ui.connections import connections_router
Expand All @@ -29,6 +30,7 @@

ui_router = AirflowRouter(prefix="/ui", include_in_schema=False)

ui_router.include_router(auth_router)
ui_router.include_router(assets_router)
ui_router.include_router(config_router)
ui_router.include_router(connections_router)
Expand Down
39 changes: 39 additions & 0 deletions airflow/api_fastapi/core_api/routes/ui/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from __future__ import annotations

from typing import cast

from airflow.api_fastapi.app import get_auth_manager
from airflow.api_fastapi.common.router import AirflowRouter
from airflow.api_fastapi.core_api.datamodels.ui.auth import MenuItem, MenuItemCollectionResponse
from airflow.api_fastapi.core_api.security import GetUserDep

auth_router = AirflowRouter(tags=["Auth Links"])


@auth_router.get("/auth/links")
def get_auth_links(
user: GetUserDep,
) -> MenuItemCollectionResponse:
menu_items = get_auth_manager().get_menu_items(user=user)

return MenuItemCollectionResponse(
menu_items=cast(list[MenuItem], menu_items),
total_entries=len(menu_items),
)
2 changes: 1 addition & 1 deletion airflow/assets/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.
from __future__ import annotations

from collections.abc import Collection, Iterable
from collections.abc import Collection
from typing import TYPE_CHECKING

from sqlalchemy import exc, or_, select
Expand Down
13 changes: 13 additions & 0 deletions airflow/ui/openapi-gen/queries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UseQueryResult } from "@tanstack/react-query";

import {
AssetService,
AuthLinksService,
BackfillService,
ConfigService,
ConnectionService,
Expand Down Expand Up @@ -36,6 +37,18 @@ import {
} from "../requests/services.gen";
import { DagRunState, DagWarningType } from "../requests/types.gen";

export type AuthLinksServiceGetAuthLinksDefaultResponse = Awaited<
ReturnType<typeof AuthLinksService.getAuthLinks>
>;
export type AuthLinksServiceGetAuthLinksQueryResult<
TData = AuthLinksServiceGetAuthLinksDefaultResponse,
TError = unknown,
> = UseQueryResult<TData, TError>;
export const useAuthLinksServiceGetAuthLinksKey = "AuthLinksServiceGetAuthLinks";
export const UseAuthLinksServiceGetAuthLinksKeyFn = (queryKey?: Array<unknown>) => [
useAuthLinksServiceGetAuthLinksKey,
...(queryKey ?? []),
];
export type AssetServiceNextRunAssetsDefaultResponse = Awaited<ReturnType<typeof AssetService.nextRunAssets>>;
export type AssetServiceNextRunAssetsQueryResult<
TData = AssetServiceNextRunAssetsDefaultResponse,
Expand Down
11 changes: 11 additions & 0 deletions airflow/ui/openapi-gen/queries/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type QueryClient } from "@tanstack/react-query";

import {
AssetService,
AuthLinksService,
BackfillService,
ConfigService,
ConnectionService,
Expand Down Expand Up @@ -36,6 +37,16 @@ import {
import { DagRunState, DagWarningType } from "../requests/types.gen";
import * as Common from "./common";

/**
* Get Auth Links
* @returns MenuItemCollectionResponse Successful Response
* @throws ApiError
*/
export const prefetchUseAuthLinksServiceGetAuthLinks = (queryClient: QueryClient) =>
queryClient.prefetchQuery({
queryKey: Common.UseAuthLinksServiceGetAuthLinksKeyFn(),
queryFn: () => AuthLinksService.getAuthLinks(),
});
/**
* Next Run Assets
* @param data The data for the request.
Expand Down
19 changes: 19 additions & 0 deletions airflow/ui/openapi-gen/queries/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UseMutationOptions, UseQueryOptions, useMutation, useQuery } from "@tan

import {
AssetService,
AuthLinksService,
BackfillService,
ConfigService,
ConnectionService,
Expand Down Expand Up @@ -59,6 +60,24 @@ import {
} from "../requests/types.gen";
import * as Common from "./common";

/**
* Get Auth Links
* @returns MenuItemCollectionResponse Successful Response
* @throws ApiError
*/
export const useAuthLinksServiceGetAuthLinks = <
TData = Common.AuthLinksServiceGetAuthLinksDefaultResponse,
TError = unknown,
TQueryKey extends Array<unknown> = unknown[],
>(
queryKey?: TQueryKey,
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
) =>
useQuery<TData, TError>({
queryKey: Common.UseAuthLinksServiceGetAuthLinksKeyFn(queryKey),
queryFn: () => AuthLinksService.getAuthLinks() as TData,
...options,
});
/**
* Next Run Assets
* @param data The data for the request.
Expand Down
19 changes: 19 additions & 0 deletions airflow/ui/openapi-gen/queries/suspense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UseQueryOptions, useSuspenseQuery } from "@tanstack/react-query";

import {
AssetService,
AuthLinksService,
BackfillService,
ConfigService,
ConnectionService,
Expand Down Expand Up @@ -36,6 +37,24 @@ import {
import { DagRunState, DagWarningType } from "../requests/types.gen";
import * as Common from "./common";

/**
* Get Auth Links
* @returns MenuItemCollectionResponse Successful Response
* @throws ApiError
*/
export const useAuthLinksServiceGetAuthLinksSuspense = <
TData = Common.AuthLinksServiceGetAuthLinksDefaultResponse,
TError = unknown,
TQueryKey extends Array<unknown> = unknown[],
>(
queryKey?: TQueryKey,
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
) =>
useSuspenseQuery<TData, TError>({
queryKey: Common.UseAuthLinksServiceGetAuthLinksKeyFn(queryKey),
queryFn: () => AuthLinksService.getAuthLinks() as TData,
...options,
});
/**
* Next Run Assets
* @param data The data for the request.
Expand Down
37 changes: 37 additions & 0 deletions airflow/ui/openapi-gen/requests/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4150,6 +4150,43 @@ export const $JobResponse = {
description: "Job serializer for responses.",
} as const;

export const $MenuItem = {
properties: {
text: {
type: "string",
title: "Text",
},
href: {
type: "string",
title: "Href",
},
},
type: "object",
required: ["text", "href"],
title: "MenuItem",
description: "Menu Item for responses.",
} as const;

export const $MenuItemCollectionResponse = {
properties: {
menu_items: {
items: {
$ref: "#/components/schemas/MenuItem",
},
type: "array",
title: "Menu Items",
},
total_entries: {
type: "integer",
title: "Total Entries",
},
},
type: "object",
required: ["menu_items", "total_entries"],
title: "MenuItemCollectionResponse",
description: "Menu Item Collection serializer for responses.",
} as const;

export const $NodeResponse = {
properties: {
id: {
Expand Down
15 changes: 15 additions & 0 deletions airflow/ui/openapi-gen/requests/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { CancelablePromise } from "./core/CancelablePromise";
import { OpenAPI } from "./core/OpenAPI";
import { request as __request } from "./core/request";
import type {
GetAuthLinksResponse,
NextRunAssetsData,
NextRunAssetsResponse,
GetAssetsData,
Expand Down Expand Up @@ -214,6 +215,20 @@ import type {
LoginResponse,
} from "./types.gen";

export class AuthLinksService {
/**
* Get Auth Links
* @returns MenuItemCollectionResponse Successful Response
* @throws ApiError
*/
public static getAuthLinks(): CancelablePromise<GetAuthLinksResponse> {
return __request(OpenAPI, {
method: "GET",
url: "/ui/auth/links",
});
}
}

export class AssetService {
/**
* Next Run Assets
Expand Down
28 changes: 28 additions & 0 deletions airflow/ui/openapi-gen/requests/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,22 @@ export type JobResponse = {
unixname: string | null;
};

/**
* Menu Item for responses.
*/
export type MenuItem = {
text: string;
href: string;
};

/**
* Menu Item Collection serializer for responses.
*/
export type MenuItemCollectionResponse = {
menu_items: Array<MenuItem>;
total_entries: number;
};

/**
* Node serializer for responses.
*/
Expand Down Expand Up @@ -1653,6 +1669,8 @@ export type XComUpdateBody = {
map_index?: number;
};

export type GetAuthLinksResponse = MenuItemCollectionResponse;

export type NextRunAssetsData = {
dagId: string;
};
Expand Down Expand Up @@ -2576,6 +2594,16 @@ export type LoginData = {
export type LoginResponse = unknown;

export type $OpenApiTs = {
"/ui/auth/links": {
get: {
res: {
/**
* Successful Response
*/
200: MenuItemCollectionResponse;
};
};
};
"/ui/next_run_assets/{dag_id}": {
get: {
req: NextRunAssetsData;
Expand Down
Loading