This is an automated email from the ASF dual-hosted git repository.
potiuk 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 83bdc297ce added cli command to list auth managers under `airflow
providers` (#36445)
83bdc297ce is described below
commit 83bdc297cebafada88084e270aa3258d781a96be
Author: Bowrna <[email protected]>
AuthorDate: Sat Dec 30 16:47:17 2023 +0530
added cli command to list auth managers under `airflow providers` (#36445)
* added cli command to list auth managers
* Update tests/always/test_providers_manager.py
Co-authored-by: Pankaj Singh <[email protected]>
---------
Co-authored-by: Jarek Potiuk <[email protected]>
Co-authored-by: Pankaj Singh <[email protected]>
---
airflow/cli/cli_config.py | 6 ++++++
airflow/cli/commands/provider_command.py | 15 ++++++++++++++-
airflow/provider.yaml.schema.json | 7 +++++++
airflow/provider_info.schema.json | 7 +++++++
airflow/providers/fab/provider.yaml | 3 +++
airflow/providers_manager.py | 21 +++++++++++++++++++++
tests/always/test_providers_manager.py | 5 +++++
7 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/airflow/cli/cli_config.py b/airflow/cli/cli_config.py
index e5a57f4552..0880a94e07 100644
--- a/airflow/cli/cli_config.py
+++ b/airflow/cli/cli_config.py
@@ -1779,6 +1779,12 @@ PROVIDERS_COMMANDS = (
func=lazy_load_command("airflow.cli.commands.provider_command.lazy_loaded"),
args=(ARG_VERBOSE,),
),
+ ActionCommand(
+ name="auth-managers",
+ help="Get information about auth managers provided",
+
func=lazy_load_command("airflow.cli.commands.provider_command.auth_managers_list"),
+ args=(ARG_OUTPUT, ARG_VERBOSE),
+ ),
)
diff --git a/airflow/cli/commands/provider_command.py
b/airflow/cli/commands/provider_command.py
index 460c11bbbd..4eeb4bff39 100644
--- a/airflow/cli/commands/provider_command.py
+++ b/airflow/cli/commands/provider_command.py
@@ -189,7 +189,20 @@ def auth_backend_list(args):
data=list(ProvidersManager().auth_backend_module_names),
output=args.output,
mapper=lambda x: {
- "api_auth_backand_module": x,
+ "api_auth_backend_module": x,
+ },
+ )
+
+
+@suppress_logs_and_warning
+@providers_configuration_loaded
+def auth_managers_list(args):
+ """List all auth managers at the command line."""
+ AirflowConsole().print_as(
+ data=list(ProvidersManager().auth_managers),
+ output=args.output,
+ mapper=lambda x: {
+ "auth_managers_module": x,
},
)
diff --git a/airflow/provider.yaml.schema.json
b/airflow/provider.yaml.schema.json
index d811f7318d..1873efbee3 100644
--- a/airflow/provider.yaml.schema.json
+++ b/airflow/provider.yaml.schema.json
@@ -309,6 +309,13 @@
"type": "string"
}
},
+ "auth-managers": {
+ "type": "array",
+ "description": "Auth managers class names",
+ "items": {
+ "type": "string"
+ }
+ },
"logging": {
"type": "array",
"description": "Logging Task Handlers class names",
diff --git a/airflow/provider_info.schema.json
b/airflow/provider_info.schema.json
index e9a2571f06..9f8fa57367 100644
--- a/airflow/provider_info.schema.json
+++ b/airflow/provider_info.schema.json
@@ -135,6 +135,13 @@
"type": "string"
}
},
+ "auth-managers": {
+ "type": "array",
+ "description": "Auth managers module names",
+ "items": {
+ "type": "string"
+ }
+ },
"notifications": {
"type": "array",
"description": "Notification class names",
diff --git a/airflow/providers/fab/provider.yaml
b/airflow/providers/fab/provider.yaml
index 6ac75474dd..764c917d20 100644
--- a/airflow/providers/fab/provider.yaml
+++ b/airflow/providers/fab/provider.yaml
@@ -41,3 +41,6 @@ dependencies:
- flask-appbuilder==4.3.10
- flask-login>=0.6.2
- google-re2>=1.0
+
+auth-managers:
+ - airflow.providers.fab.auth_manager.fab_auth_manager.FabAuthManager
diff --git a/airflow/providers_manager.py b/airflow/providers_manager.py
index b510c47861..162f2d32af 100644
--- a/airflow/providers_manager.py
+++ b/airflow/providers_manager.py
@@ -429,6 +429,7 @@ class ProvidersManager(LoggingMixin, metaclass=Singleton):
self._field_behaviours: dict[str, dict] = {}
self._extra_link_class_name_set: set[str] = set()
self._logging_class_name_set: set[str] = set()
+ self._auth_manager_class_name_set: set[str] = set()
self._secrets_backend_class_name_set: set[str] = set()
self._executor_class_name_set: set[str] = set()
self._provider_configs: dict[str, dict[str, Any]] = {}
@@ -549,6 +550,12 @@ class ProvidersManager(LoggingMixin, metaclass=Singleton):
self.initialize_providers_list()
self._discover_notifications()
+ @provider_info_cache("auth_managers")
+ def initialize_providers_auth_managers(self):
+ """Lazy initialization of providers notifications information."""
+ self.initialize_providers_list()
+ self._discover_auth_managers()
+
@provider_info_cache("config")
def initialize_providers_configuration(self):
"""Lazy initialization of providers configuration information."""
@@ -1053,6 +1060,14 @@ class ProvidersManager(LoggingMixin,
metaclass=Singleton):
e,
)
+ def _discover_auth_managers(self) -> None:
+ """Retrieves all auth managers defined in the providers."""
+ for provider_package, provider in self._provider_dict.items():
+ if provider.data.get("auth-managers"):
+ for auth_manager_class_name in provider.data["auth-managers"]:
+ if _correctness_check(provider_package,
auth_manager_class_name, provider):
+
self._auth_manager_class_name_set.add(auth_manager_class_name)
+
def _discover_notifications(self) -> None:
"""Retrieves all notifications defined in the providers."""
for provider_package, provider in self._provider_dict.items():
@@ -1137,6 +1152,12 @@ class ProvidersManager(LoggingMixin,
metaclass=Singleton):
)
)
+ @property
+ def auth_managers(self) -> list[str]:
+ """Returns information about available providers notifications
class."""
+ self.initialize_providers_auth_managers()
+ return sorted(self._auth_manager_class_name_set)
+
@property
def notification(self) -> list[NotificationInfo]:
"""Returns information about available providers notifications
class."""
diff --git a/tests/always/test_providers_manager.py
b/tests/always/test_providers_manager.py
index afeab528e1..0687965571 100644
--- a/tests/always/test_providers_manager.py
+++ b/tests/always/test_providers_manager.py
@@ -384,6 +384,11 @@ class TestProviderManager:
notification_class_names = list(provider_manager.notification)
assert len(notification_class_names) > 5
+ def test_auth_managers(self):
+ provider_manager = ProvidersManager()
+ auth_manager_class_names = list(provider_manager.auth_managers)
+ assert len(auth_manager_class_names) > 0
+
@patch("airflow.providers_manager.import_string")
def test_optional_feature_no_warning(self, mock_importlib_import_string):
with self._caplog.at_level(logging.WARNING):