Skip to content

Commit

Permalink
AIP-84 Add Auth to providers (#47505)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrejeambrun authored Mar 11, 2025
1 parent 2b1c275 commit 45d040e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4448,6 +4448,8 @@ paths:
summary: Get Providers
description: Get providers.
operationId: get_providers
security:
- OAuth2PasswordBearer: []
parameters:
- name: limit
in: query
Expand Down
9 changes: 8 additions & 1 deletion airflow/api_fastapi/core_api/routes/public/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@

import re

from fastapi import Depends

from airflow.api_fastapi.auth.managers.models.resource_details import AccessView
from airflow.api_fastapi.common.parameters import QueryLimit, QueryOffset
from airflow.api_fastapi.common.router import AirflowRouter
from airflow.api_fastapi.core_api.datamodels.providers import ProviderCollectionResponse, ProviderResponse
from airflow.api_fastapi.core_api.security import requires_access_view
from airflow.providers_manager import ProviderInfo, ProvidersManager

providers_router = AirflowRouter(tags=["Provider"], prefix="/providers")
Expand All @@ -39,7 +43,10 @@ def _provider_mapper(provider: ProviderInfo) -> ProviderResponse:
)


@providers_router.get("")
@providers_router.get(
"",
dependencies=[Depends(requires_access_view(AccessView.PROVIDERS))],
)
def get_providers(
limit: QueryLimit,
offset: QueryOffset,
Expand Down
10 changes: 9 additions & 1 deletion tests/api_fastapi/core_api/routes/public/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TestGetProviders:
new_callable=mock.PropertyMock,
return_value=MOCK_PROVIDERS,
)
def test_get_dags(
def test_should_respond_200(
self, mock_provider, test_client, query_params, expected_total_entries, expected_package_name
):
response = test_client.get("/public/providers", params=query_params)
Expand All @@ -71,3 +71,11 @@ def test_get_dags(

assert body["total_entries"] == expected_total_entries
assert [provider["package_name"] for provider in body["providers"]] == expected_package_name

def test_should_response_401(self, unauthenticated_test_client):
response = unauthenticated_test_client.get("/public/providers")
assert response.status_code == 401

def test_should_response_403(self, unauthorized_test_client):
response = unauthorized_test_client.get("/public/providers")
assert response.status_code == 403

0 comments on commit 45d040e

Please sign in to comment.