This is an automated email from the ASF dual-hosted git repository.
weilee pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 45d040e01c9 AIP-84 Add Auth to providers (#47505)
45d040e01c9 is described below
commit 45d040e01c9bc5fec66db6bca56a7a1019a6d0da
Author: Pierre Jeambrun <[email protected]>
AuthorDate: Tue Mar 11 10:14:27 2025 +0100
AIP-84 Add Auth to providers (#47505)
---
airflow/api_fastapi/core_api/openapi/v1-generated.yaml | 2 ++
airflow/api_fastapi/core_api/routes/public/providers.py | 9 ++++++++-
tests/api_fastapi/core_api/routes/public/test_providers.py | 10 +++++++++-
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/airflow/api_fastapi/core_api/openapi/v1-generated.yaml
b/airflow/api_fastapi/core_api/openapi/v1-generated.yaml
index b4a26654ef9..7555e3e4788 100644
--- a/airflow/api_fastapi/core_api/openapi/v1-generated.yaml
+++ b/airflow/api_fastapi/core_api/openapi/v1-generated.yaml
@@ -4448,6 +4448,8 @@ paths:
summary: Get Providers
description: Get providers.
operationId: get_providers
+ security:
+ - OAuth2PasswordBearer: []
parameters:
- name: limit
in: query
diff --git a/airflow/api_fastapi/core_api/routes/public/providers.py
b/airflow/api_fastapi/core_api/routes/public/providers.py
index d0505212c81..abd7a1943fc 100644
--- a/airflow/api_fastapi/core_api/routes/public/providers.py
+++ b/airflow/api_fastapi/core_api/routes/public/providers.py
@@ -19,9 +19,13 @@ from __future__ import annotations
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")
@@ -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,
diff --git a/tests/api_fastapi/core_api/routes/public/test_providers.py
b/tests/api_fastapi/core_api/routes/public/test_providers.py
index 8ad36e2a5ef..4a91d093420 100644
--- a/tests/api_fastapi/core_api/routes/public/test_providers.py
+++ b/tests/api_fastapi/core_api/routes/public/test_providers.py
@@ -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)
@@ -71,3 +71,11 @@ class TestGetProviders:
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