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/04/16 05:37:01 UTC

[GitHub] [airflow] turbaszek commented on a change in pull request #8313: Simplify handling of downloaded files in Dataflow

turbaszek commented on a change in pull request #8313: Simplify handling of downloaded files in Dataflow
URL: https://github.com/apache/airflow/pull/8313#discussion_r409290407
 
 

 ##########
 File path: airflow/providers/google/cloud/hooks/gcs.py
 ##########
 @@ -35,6 +38,72 @@
 from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
 from airflow.version import version
 
+RT = TypeVar('RT')  # pylint: disable=invalid-name
+
+
+def _fallback_object_url_to_object_name_and_bucket_name(
+    object_url_keyword_arg_name='object_url',
+    bucket_name_keyword_arg_name='bucket_name',
+    object_name_keyword_arg_name='object_name',
+):
+    """
+    Decorator factory that convert object URL parameter to object name and bucket name parameter.
+
+    :param object_url_keyword_arg_name: Name of the object URL parameter
+    :type object_url_keyword_arg_name: str
+    :param bucket_name_keyword_arg_name: Name of the bucket name parameter
+    :type bucket_name_keyword_arg_name: str
+    :param object_name_keyword_arg_name: Name of the object name parameter
+    :type object_name_keyword_arg_name: str
+    :return: Decorator
+    """
+    def _wrapper(func):
+
+        @functools.wraps(func)
+        def _inner_wrapper(self: "GCSHook", * args, **kwargs) -> RT:
+            if args:
+                raise AirflowException(
+                    "You must use keyword arguments in this methods rather than positional")
+
+            object_url = kwargs.get(object_url_keyword_arg_name)
+            bucket_name = kwargs.get(bucket_name_keyword_arg_name)
+            object_name = kwargs.get(object_name_keyword_arg_name)
+
+            if object_url and bucket_name and object_name:
+                raise AirflowException(
+                    "The mutually exclusive parameters. `object_url`, `bucket_name` together "
+                    "with `object_name` parameters are present. "
+                    "Please provide `object_url` or ``bucket_name` and `object_name`. "
 
 Review comment:
   ```suggestion
                       "Please provide `object_url` or `bucket_name` and `object_name`. "
   ```

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


With regards,
Apache Git Services