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 2021/05/04 03:47:38 UTC

[GitHub] [airflow] jhtimmins commented on a change in pull request #15385: [WIP] Added table to view providers in airflow ui under admin tab

jhtimmins commented on a change in pull request #15385:
URL: https://github.com/apache/airflow/pull/15385#discussion_r625488542



##########
File path: airflow/security/permissions.py
##########
@@ -32,6 +32,7 @@
 RESOURCE_JOB = "Jobs"
 RESOURCE_POOL = "Pools"
 RESOURCE_PLUGIN = "Plugins"
+RESOURCE_PROVIDERS = "Providers"

Review comment:
       ```suggestion
   RESOURCE_PROVIDER = "Providers"
   ```
   Just for consistency (I know some of the naming conventions are annoying. It's a work in progress :)). 

##########
File path: airflow/www/templates/airflow/providers.html
##########
@@ -0,0 +1,49 @@
+{#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+#}
+
+{% extends base_template %}
+
+{% block title %}
+  {{ title }}
+{% endblock %}
+
+{% block content %}
+  <h2>{{ title }}</h2>
+  {% if providers|length == 0 %}
+    <p>No providers loaded. Learn more in the
+      <a href="{{ doc_url }}" target="_blank">provider packages documentation</a>.
+    </p>
+  {% endif %}
+
+  <table class="table table-striped table-bordered">
+    <tr>
+      <th>Package Name</th>
+      <th>Version</th>
+      <th>Description</th>
+    </tr>
+
+    {% for provider in providers %}
+      <tr>
+          <td>{{ provider["package_name"] }}</td>
+          <td>{{ provider["version"] }}</td>
+          <td>{{ provider["description"] | safe}}</td>

Review comment:
       ```suggestion
             <td>{{ provider["description"]|safe}}</td>
   ```
   Doesn't _really_ matter, but this makes it consistent with line 28.

##########
File path: tests/www/test_views.py
##########
@@ -368,6 +369,19 @@ def test_endpoint_should_not_be_unauthenticated(self):
         self.check_content_in_response("Sign In - Airflow", resp)
 
 
+class TestProvidersView(TestBase):
+    def test_should_list_providers_on_page_with_details(self):
+        resp = self.client.get('/providers')
+        self.check_content_in_response("Providers", resp)

Review comment:
       Can you validate that the necessary permissions are included?

##########
File path: airflow/www/views.py
##########
@@ -3017,6 +3018,57 @@ def list(self):
         )
 
 
+class ProvidersView(AirflowBaseView):
+    """View to show Airflow Providers"""
+
+    default_view = 'list'
+
+    class_permission_name = permissions.RESOURCE_PROVIDERS
+
+    method_permission_name = {
+        'list': 'read',
+    }
+
+    base_permissions = [
+        permissions.ACTION_CAN_READ,
+        permissions.ACTION_CAN_ACCESS_MENU,
+    ]
+
+    @expose('/providers')
+    @auth.has_access(
+        [
+            (permissions.ACTION_CAN_READ, permissions.RESOURCE_PLUGIN),
+        ]
+    )
+    def list(self):
+        """List providers."""
+        providers_manager = ProvidersManager()
+
+        providers = []
+        for pi in providers_manager.providers.values():
+            provider_data = {
+                "package_name": pi[1]["package-name"],

Review comment:
       It may help to assign `pi[1]` to a variable to indicate what it is.

##########
File path: tests/www/test_views.py
##########
@@ -53,6 +53,7 @@
 from airflow.operators.bash import BashOperator
 from airflow.operators.dummy import DummyOperator
 from airflow.plugins_manager import AirflowPlugin, EntryPointSource
+from airflow.providers_manager import ProvidersManager

Review comment:
       Is this method in use?

##########
File path: airflow/www/views.py
##########
@@ -3017,6 +3018,57 @@ def list(self):
         )
 
 
+class ProvidersView(AirflowBaseView):
+    """View to show Airflow Providers"""
+
+    default_view = 'list'
+
+    class_permission_name = permissions.RESOURCE_PROVIDERS
+
+    method_permission_name = {
+        'list': 'read',
+    }
+
+    base_permissions = [
+        permissions.ACTION_CAN_READ,
+        permissions.ACTION_CAN_ACCESS_MENU,
+    ]
+
+    @expose('/providers')
+    @auth.has_access(
+        [
+            (permissions.ACTION_CAN_READ, permissions.RESOURCE_PLUGIN),

Review comment:
       ```suggestion
               (permissions.ACTION_CAN_READ, permissions.RESOURCE_PROVIDER),
   ```

##########
File path: airflow/www/views.py
##########
@@ -3017,6 +3018,57 @@ def list(self):
         )
 
 
+class ProvidersView(AirflowBaseView):
+    """View to show Airflow Providers"""
+
+    default_view = 'list'
+
+    class_permission_name = permissions.RESOURCE_PROVIDERS
+
+    method_permission_name = {
+        'list': 'read',
+    }
+
+    base_permissions = [
+        permissions.ACTION_CAN_READ,
+        permissions.ACTION_CAN_ACCESS_MENU,
+    ]
+
+    @expose('/providers')
+    @auth.has_access(
+        [
+            (permissions.ACTION_CAN_READ, permissions.RESOURCE_PLUGIN),
+        ]
+    )
+    def list(self):
+        """List providers."""
+        providers_manager = ProvidersManager()
+
+        providers = []
+        for pi in providers_manager.providers.values():
+            provider_data = {
+                "package_name": pi[1]["package-name"],
+                "description": self.clean_description(pi[1]["description"]),
+                "version": pi[0],
+            }
+            providers.append(provider_data)
+
+        title = "Providers"
+        doc_url = get_docs_url("apache-airflow-providers/index.html")
+        return self.render_template(
+            'airflow/providers.html',
+            providers=providers,
+            title=title,
+            doc_url=doc_url,
+        )
+
+    def clean_description(self, description):

Review comment:
       ```suggestion
       def _clean_description(self, description):
   ```
   This can probably be an internal method.




-- 
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