You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/12/03 07:34:00 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #12472: Allow registering extra links for providers

mik-laj commented on a change in pull request #12472:
URL: https://github.com/apache/airflow/pull/12472#discussion_r534815915



##########
File path: airflow/providers_manager.py
##########
@@ -224,6 +226,43 @@ def _add_hook(self, hook_class_name, provider_package) -> None:
 
         self._hooks_dict[conn_type] = (hook_class_name, connection_id_attribute_name)
 
+    def _discover_extra_links(self) -> None:
+        """Retrieves all extra links defined in the providers"""
+        for provider_package, (_, provider) in self._provider_dict.items():
+            if provider.get("extra-links"):
+                for extra_link in provider["extra-links"]:
+                    self.__add_extra_link(extra_link, provider_package)
+
+    def __add_extra_link(self, extra_link_class_name, provider_package) -> None:
+        """
+        Adds extra link class name to the list of classes
+        :param extra_link_class_name: name of the class to add
+        :param provider_package: provider package adding the link
+        :return:
+        """
+        if provider_package.startswith("apache-airflow"):
+            provider_path = provider_package[len("apache-") :].replace("-", ".")
+            if not extra_link_class_name.startswith(provider_path):
+                log.warning(
+                    "Sanity check failed when importing '%s' from '%s' package. It should start with '%s'",
+                    extra_link_class_name,
+                    provider_package,
+                    provider_path,
+                )
+                return
+        try:
+            module, class_name = extra_link_class_name.rsplit('.', maxsplit=1)
+            getattr(importlib.import_module(module), class_name)

Review comment:
       In the past, we loaded all extra links during Airflow startup. See: https://github.com/apache/airflow/pull/7327




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org