From d646c789860986bcefc2701a17c9c1736845b124 Mon Sep 17 00:00:00 2001 From: vincbeck Date: Wed, 10 Jul 2024 10:54:08 -0400 Subject: [PATCH 1/3] Make `AwsAuthManager` compatible with only Airflow >= 2.9 --- .../amazon/aws/auth_manager/aws_auth_manager.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/airflow/providers/amazon/aws/auth_manager/aws_auth_manager.py b/airflow/providers/amazon/aws/auth_manager/aws_auth_manager.py index f94e4de691d97..fd25b7080c439 100644 --- a/airflow/providers/amazon/aws/auth_manager/aws_auth_manager.py +++ b/airflow/providers/amazon/aws/auth_manager/aws_auth_manager.py @@ -81,6 +81,15 @@ class AwsAuthManager(BaseAuthManager): """ def __init__(self, appbuilder: AirflowAppBuilder) -> None: + from packaging.version import Version + + from airflow.version import version + + if Version(version) < Version("2.9"): + raise AirflowOptionalProviderFeatureException( + "``AwsAuthManager`` is compatible with Airflow versions >= 2.9." + ) + super().__init__(appbuilder) self._check_avp_schema_version() @@ -197,8 +206,14 @@ def is_authorized_view( ) def is_authorized_custom_view( - self, *, method: ResourceMethod | str, resource_name: str, user: BaseUser | None = None + self, + *, + method: ResourceMethod | str, + resource_name: str, + user: BaseUser | None = None, + **kwargs, ): + # TODO: remove this if block when min_airflow_version is set to higher than 2.9.0 return self.avp_facade.is_authorized( method=method, entity_type=AvpEntities.CUSTOM, From b3e32fb7cbbaa99ca6d4ef9baf1b903747742622 Mon Sep 17 00:00:00 2001 From: vincbeck Date: Wed, 10 Jul 2024 11:21:21 -0400 Subject: [PATCH 2/3] Clean up --- .../amazon/aws/auth_manager/aws_auth_manager.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/airflow/providers/amazon/aws/auth_manager/aws_auth_manager.py b/airflow/providers/amazon/aws/auth_manager/aws_auth_manager.py index fd25b7080c439..5660ec5d87c02 100644 --- a/airflow/providers/amazon/aws/auth_manager/aws_auth_manager.py +++ b/airflow/providers/amazon/aws/auth_manager/aws_auth_manager.py @@ -85,6 +85,7 @@ def __init__(self, appbuilder: AirflowAppBuilder) -> None: from airflow.version import version + # TODO: remove this if block when min_airflow_version is set to higher than 2.9.0 if Version(version) < Version("2.9"): raise AirflowOptionalProviderFeatureException( "``AwsAuthManager`` is compatible with Airflow versions >= 2.9." @@ -206,14 +207,8 @@ def is_authorized_view( ) def is_authorized_custom_view( - self, - *, - method: ResourceMethod | str, - resource_name: str, - user: BaseUser | None = None, - **kwargs, + self, *, method: ResourceMethod | str, resource_name: str, user: BaseUser | None = None ): - # TODO: remove this if block when min_airflow_version is set to higher than 2.9.0 return self.avp_facade.is_authorized( method=method, entity_type=AvpEntities.CUSTOM, From a5ab65957ae1676ad7d62be4b2cc85f073f13afe Mon Sep 17 00:00:00 2001 From: vincbeck Date: Wed, 10 Jul 2024 11:43:10 -0400 Subject: [PATCH 3/3] Skip tests if airflow is < 2.9 --- .../amazon/aws/auth_manager/test_aws_auth_manager.py | 4 +++- tests/providers/amazon/aws/auth_manager/views/test_auth.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/providers/amazon/aws/auth_manager/test_aws_auth_manager.py b/tests/providers/amazon/aws/auth_manager/test_aws_auth_manager.py index 03684e6336384..a4a9472000708 100644 --- a/tests/providers/amazon/aws/auth_manager/test_aws_auth_manager.py +++ b/tests/providers/amazon/aws/auth_manager/test_aws_auth_manager.py @@ -23,7 +23,7 @@ from flask import Flask, session from flask_appbuilder.menu import MenuItem -from tests.test_utils.compat import AIRFLOW_V_2_8_PLUS +from tests.test_utils.compat import AIRFLOW_V_2_8_PLUS, AIRFLOW_V_2_9_PLUS try: from airflow.auth.managers.models.resource_details import ( @@ -66,6 +66,8 @@ if TYPE_CHECKING: from airflow.auth.managers.base_auth_manager import ResourceMethod +pytestmark = pytest.mark.skipif(not AIRFLOW_V_2_9_PLUS, reason="Test requires Airflow 2.9+") + mock = Mock() SAML_METADATA_PARSED = { diff --git a/tests/providers/amazon/aws/auth_manager/views/test_auth.py b/tests/providers/amazon/aws/auth_manager/views/test_auth.py index 7474d74727fd7..7db5ad7910db1 100644 --- a/tests/providers/amazon/aws/auth_manager/views/test_auth.py +++ b/tests/providers/amazon/aws/auth_manager/views/test_auth.py @@ -23,12 +23,12 @@ from airflow.exceptions import AirflowException from airflow.www import app as application -from tests.test_utils.compat import AIRFLOW_V_2_8_PLUS +from tests.test_utils.compat import AIRFLOW_V_2_9_PLUS from tests.test_utils.config import conf_vars pytest.importorskip("onelogin") -pytestmark = pytest.mark.skipif(not AIRFLOW_V_2_8_PLUS, reason="Test requires Airflow 2.8+") +pytestmark = pytest.mark.skipif(not AIRFLOW_V_2_9_PLUS, reason="Test requires Airflow 2.9+") SAML_METADATA_URL = "/saml/metadata"