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/04/24 08:24:13 UTC

[GitHub] [airflow] turbaszek commented on a change in pull request #14521: Add Asana Provider

turbaszek commented on a change in pull request #14521:
URL: https://github.com/apache/airflow/pull/14521#discussion_r619614212



##########
File path: airflow/providers/asana/hooks/asana.py
##########
@@ -0,0 +1,209 @@
+#
+# 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.
+
+"""Connect to Asana."""
+
+from typing import Any, Dict
+
+from asana import Client
+from cached_property import cached_property
+
+from airflow.hooks.base import BaseHook
+
+
+class AsanaHook(BaseHook):
+    """Wrapper around Asana Python client library."""
+
+    conn_name_attr = "asana_conn_id"
+    default_conn_name = "asana_default"
+    conn_type = "asana"
+    hook_name = "Asana"
+
+    def __init__(self, conn_id: str = default_conn_name, *args, **kwargs) -> None:
+        super().__init__(*args, **kwargs)
+        self.connection = self.get_connection(conn_id)
+        extras = self.connection.extra_dejson
+        self.workspace = extras.get("extra__asana__workspace") or None
+        self.project = extras.get("extra__asana__project") or None
+
+    def get_conn(self) -> Client:
+        return self.client
+
+    @staticmethod
+    def get_connection_form_widgets() -> Dict[str, Any]:
+        """Returns connection widgets to add to connection form"""
+        from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
+        from flask_babel import lazy_gettext
+        from wtforms import StringField
+
+        return {
+            "extra__asana__workspace": StringField(lazy_gettext("Workspace"), widget=BS3TextFieldWidget()),
+            "extra__asana__project": StringField(lazy_gettext("Project"), widget=BS3TextFieldWidget()),
+        }
+
+    @staticmethod
+    def get_ui_field_behaviour() -> Dict:
+        """Returns custom field behaviour"""
+        return {
+            "hidden_fields": ["port", "host", "login", "schema"],
+            "relabeling": {},
+            "placeholders": {
+                "password": "Asana personal access token",
+                "extra__asana__workspace": "Asana workspace gid",
+                "extra__asana__project": "Asana project gid",
+            },
+        }
+
+    @cached_property
+    def client(self) -> Client:
+        """Instantiates python-asana Client"""
+        if not self.connection.password:
+            raise ValueError(
+                "Asana connection password must contain a personal access token: "
+                "https://developers.asana.com/docs/personal-access-token"
+            )
+
+        return Client.access_token(self.connection.password)
+
+    def create_task(self, task_name: str, params: dict) -> dict:
+        """
+        Creates an Asana task. For a complete list of possible parameters, see
+        https://developers.asana.com/docs/create-a-task

Review comment:
       Could you please describe the arguments
   ```
   :param task_name: lorem ipsu...
   ```




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