Skip to content

Commit

Permalink
Re-run static checks
Browse files Browse the repository at this point in the history
  • Loading branch information
omkar-foss committed Oct 22, 2024
1 parent 99ae809 commit fd004ac
Show file tree
Hide file tree
Showing 8 changed files with 588 additions and 402 deletions.
421 changes: 204 additions & 217 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml

Large diffs are not rendered by default.

29 changes: 9 additions & 20 deletions airflow/api_fastapi/core_api/routes/public/dag_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@
dag_sources_router = AirflowRouter(tags=["DagSource"], prefix="/dagSources")
mime_type_text = "text/plain"
mime_type_json = "application/json"
supported_mime_types = [mime_type_text, mime_type_json]


def _get_matching_mime_type(request: Request) -> str | None:
"""Return the matching MIME type in the request's ACCEPT header."""
accept_header = request.headers.get("Accept", "").lower()
for mime_type in supported_mime_types:
if mime_type in accept_header:
return mime_type
return None


@dag_sources_router.get(
Expand All @@ -50,22 +40,21 @@ async def get_dag_source(
file_token: str,
session: Annotated[Session, Depends(get_session)],
request: Request,
) -> Response:
):
"""Get source code using file token."""
auth_s = URLSafeSerializer(request.app.state.secret_key)

try:
path = auth_s.loads(file_token)
dag_source = DagCode.code(path, session=session)
dag_source_model = DAGSourceModel(
content=DagCode.code(path, session=session),
)
except (BadSignature, FileNotFoundError):
raise HTTPException(404, "DAG source not found")

return_type = _get_matching_mime_type(request)

if return_type == mime_type_text:
return Response(dag_source, media_type=return_type)

if return_type == mime_type_json:
return Response(DAGSourceModel(content=dag_source), media_type=return_type)

accept_header = request.headers.get("Accept", "").lower()
if accept_header.startswith(mime_type_text):
return Response(dag_source_model.content, media_type=mime_type_text)
if accept_header.startswith(mime_type_json):
return dag_source_model
raise HTTPException(406, "Content not available for Accept header")
71 changes: 37 additions & 34 deletions airflow/ui/openapi-gen/queries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,40 @@ export const UseMonitorServiceGetHealthKeyFn = (queryKey?: Array<unknown>) => [
useMonitorServiceGetHealthKey,
...(queryKey ?? []),
];
export type PoolServiceGetPoolDefaultResponse = Awaited<
ReturnType<typeof PoolService.getPool>
>;
export type PoolServiceGetPoolQueryResult<
TData = PoolServiceGetPoolDefaultResponse,
TError = unknown,
> = UseQueryResult<TData, TError>;
export const usePoolServiceGetPoolKey = "PoolServiceGetPool";
export const UsePoolServiceGetPoolKeyFn = (
{
poolName,
}: {
poolName: string;
},
queryKey?: Array<unknown>,
) => [usePoolServiceGetPoolKey, ...(queryKey ?? [{ poolName }])];
export type ProviderServiceGetProvidersDefaultResponse = Awaited<
ReturnType<typeof ProviderService.getProviders>
>;
export type ProviderServiceGetProvidersQueryResult<
TData = ProviderServiceGetProvidersDefaultResponse,
TError = unknown,
> = UseQueryResult<TData, TError>;
export const useProviderServiceGetProvidersKey = "ProviderServiceGetProviders";
export const UseProviderServiceGetProvidersKeyFn = (
{
limit,
offset,
}: {
limit?: number;
offset?: number;
} = {},
queryKey?: Array<unknown>,
) => [useProviderServiceGetProvidersKey, ...(queryKey ?? [{ limit, offset }])];
export type VariableServiceGetVariableDefaultResponse = Awaited<
ReturnType<typeof VariableService.getVariable>
>;
Expand Down Expand Up @@ -290,40 +324,6 @@ export const UseVariableServiceGetVariablesKeyFn = (
useVariableServiceGetVariablesKey,
...(queryKey ?? [{ limit, offset, orderBy }]),
];
export type PoolServiceGetPoolDefaultResponse = Awaited<
ReturnType<typeof PoolService.getPool>
>;
export type PoolServiceGetPoolQueryResult<
TData = PoolServiceGetPoolDefaultResponse,
TError = unknown,
> = UseQueryResult<TData, TError>;
export const usePoolServiceGetPoolKey = "PoolServiceGetPool";
export const UsePoolServiceGetPoolKeyFn = (
{
poolName,
}: {
poolName: string;
},
queryKey?: Array<unknown>,
) => [usePoolServiceGetPoolKey, ...(queryKey ?? [{ poolName }])];
export type ProviderServiceGetProvidersDefaultResponse = Awaited<
ReturnType<typeof ProviderService.getProviders>
>;
export type ProviderServiceGetProvidersQueryResult<
TData = ProviderServiceGetProvidersDefaultResponse,
TError = unknown,
> = UseQueryResult<TData, TError>;
export const useProviderServiceGetProvidersKey = "ProviderServiceGetProviders";
export const UseProviderServiceGetProvidersKeyFn = (
{
limit,
offset,
}: {
limit?: number;
offset?: number;
} = {},
queryKey?: Array<unknown>,
) => [useProviderServiceGetProvidersKey, ...(queryKey ?? [{ limit, offset }])];
export type VariableServicePostVariableMutationResult = Awaited<
ReturnType<typeof VariableService.postVariable>
>;
Expand All @@ -348,3 +348,6 @@ export type DagRunServiceDeleteDagRunMutationResult = Awaited<
export type PoolServiceDeletePoolMutationResult = Awaited<
ReturnType<typeof PoolService.deletePool>
>;
export type VariableServiceDeleteVariableMutationResult = Awaited<
ReturnType<typeof VariableService.deleteVariable>
>;
74 changes: 37 additions & 37 deletions airflow/ui/openapi-gen/queries/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,95 +309,95 @@ export const prefetchUseMonitorServiceGetHealth = (queryClient: QueryClient) =>
queryFn: () => MonitorService.getHealth(),
});
/**
* Get Variable
* Get a variable entry.
* Get Pool
* Get a pool.
* @param data The data for the request.
* @param data.variableKey
* @returns VariableResponse Successful Response
* @param data.poolName
* @returns PoolResponse Successful Response
* @throws ApiError
*/
export const prefetchUseVariableServiceGetVariable = (
export const prefetchUsePoolServiceGetPool = (
queryClient: QueryClient,
{
variableKey,
poolName,
}: {
variableKey: string;
poolName: string;
},
) =>
queryClient.prefetchQuery({
queryKey: Common.UseVariableServiceGetVariableKeyFn({ variableKey }),
queryFn: () => VariableService.getVariable({ variableKey }),
queryKey: Common.UsePoolServiceGetPoolKeyFn({ poolName }),
queryFn: () => PoolService.getPool({ poolName }),
});
/**
* Get Variables
* Get all Variables entries.
* Get Providers
* Get providers.
* @param data The data for the request.
* @param data.limit
* @param data.offset
* @param data.orderBy
* @returns VariableCollectionResponse Successful Response
* @returns ProviderCollectionResponse Successful Response
* @throws ApiError
*/
export const prefetchUseVariableServiceGetVariables = (
export const prefetchUseProviderServiceGetProviders = (
queryClient: QueryClient,
{
limit,
offset,
orderBy,
}: {
limit?: number;
offset?: number;
orderBy?: string;
} = {},
) =>
queryClient.prefetchQuery({
queryKey: Common.UseVariableServiceGetVariablesKeyFn({
limit,
offset,
orderBy,
}),
queryFn: () => VariableService.getVariables({ limit, offset, orderBy }),
queryKey: Common.UseProviderServiceGetProvidersKeyFn({ limit, offset }),
queryFn: () => ProviderService.getProviders({ limit, offset }),
});
/**
* Get Pool
* Get a pool.
* Get Variable
* Get a variable entry.
* @param data The data for the request.
* @param data.poolName
* @returns PoolResponse Successful Response
* @param data.variableKey
* @returns VariableResponse Successful Response
* @throws ApiError
*/
export const prefetchUsePoolServiceGetPool = (
export const prefetchUseVariableServiceGetVariable = (
queryClient: QueryClient,
{
poolName,
variableKey,
}: {
poolName: string;
variableKey: string;
},
) =>
queryClient.prefetchQuery({
queryKey: Common.UsePoolServiceGetPoolKeyFn({ poolName }),
queryFn: () => PoolService.getPool({ poolName }),
queryKey: Common.UseVariableServiceGetVariableKeyFn({ variableKey }),
queryFn: () => VariableService.getVariable({ variableKey }),
});
/**
* Get Providers
* Get providers.
* Get Variables
* Get all Variables entries.
* @param data The data for the request.
* @param data.limit
* @param data.offset
* @returns ProviderCollectionResponse Successful Response
* @param data.orderBy
* @returns VariableCollectionResponse Successful Response
* @throws ApiError
*/
export const prefetchUseProviderServiceGetProviders = (
export const prefetchUseVariableServiceGetVariables = (
queryClient: QueryClient,
{
limit,
offset,
orderBy,
}: {
limit?: number;
offset?: number;
orderBy?: string;
} = {},
) =>
queryClient.prefetchQuery({
queryKey: Common.UseProviderServiceGetProvidersKeyFn({ limit, offset }),
queryFn: () => ProviderService.getProviders({ limit, offset }),
queryKey: Common.UseVariableServiceGetVariablesKeyFn({
limit,
offset,
orderBy,
}),
queryFn: () => VariableService.getVariables({ limit, offset, orderBy }),
});
Loading

0 comments on commit fd004ac

Please sign in to comment.