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 2022/03/13 15:07:49 UTC

[GitHub] [airflow] ulsc commented on a change in pull request #22219: Gdrive upload operator

ulsc commented on a change in pull request #22219:
URL: https://github.com/apache/airflow/pull/22219#discussion_r825462049



##########
File path: airflow/providers/google/suite/operators/drive.py
##########
@@ -0,0 +1,116 @@
+# 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.
+"""This file contains Google Drive operators"""
+
+import os
+from typing import Any, Optional, Sequence, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.google.suite.hooks.drive import GoogleDriveHook
+
+
+class GoogleDriveUploadOperator(BaseOperator):
+    """
+    Upload a list of files to a Google Drive folder.
+    This operator uploads a list of local files to a Google Drive folder.
+    The local files can be deleted after upload (optional)
+
+    :param local_paths: Python list of local file path strings
+    :param drive_folder: path of the Drive folder
+    :param gcp_conn_id: Airflow Connection ID for GCP
+    :param delete: should the local files be deleted after upload?
+    :param chunk_size: File will be uploaded in chunks of this many bytes. Only
+        used if resumable=True. Pass in a value of -1 if the file is to be
+        uploaded as a single chunk. Note that Google App Engine has a 5MB limit
+        on request size, so you should never set your chunk size larger than 5MB,
+        or to -1.
+    :param resumable: True if this is a resumable upload. False means upload
+        in a single request.
+    :param api_version: version of the Google Drive API
+    :param delegate_to: The account to impersonate using domain-wide delegation of authority,
+        if any. For this to work, the service account making the request must have
+        domain-wide delegation enabled.
+    :param impersonation_chain: Optional service account to impersonate using short-term
+        credentials, or chained list of accounts required to get the access_token
+        of the last account in the list, which will be impersonated in the request.
+        If set as a string, the account must grant the originating account
+        the Service Account Token Creator IAM role.
+        If set as a sequence, the identities from the list must grant
+        Service Account Token Creator IAM role to the directly preceding identity, with first
+        account from the list granting this role to the originating account
+    :return: Remote file ids after upload
+    :rtype: Sequence[str]
+    """
+
+    template_fields = ('local_paths', 'drive_folder',)
+
+    def __init__(
+        self,
+        local_paths,
+        drive_folder: str,
+        gcp_conn_id: str,
+        delete: bool = False,
+        chunk_size: int = 100 * 1024 * 1024,
+        resumable: bool = False,
+        api_version: str = 'v3',

Review comment:
       actually, we can get rid of it altogether, because it's passed to the hook and the hook already has the version default. But, 

##########
File path: airflow/providers/google/suite/operators/drive.py
##########
@@ -0,0 +1,116 @@
+# 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.
+"""This file contains Google Drive operators"""
+
+import os
+from typing import Any, Optional, Sequence, Union
+
+from airflow.models import BaseOperator
+from airflow.providers.google.suite.hooks.drive import GoogleDriveHook
+
+
+class GoogleDriveUploadOperator(BaseOperator):
+    """
+    Upload a list of files to a Google Drive folder.
+    This operator uploads a list of local files to a Google Drive folder.
+    The local files can be deleted after upload (optional)
+
+    :param local_paths: Python list of local file path strings
+    :param drive_folder: path of the Drive folder
+    :param gcp_conn_id: Airflow Connection ID for GCP
+    :param delete: should the local files be deleted after upload?
+    :param chunk_size: File will be uploaded in chunks of this many bytes. Only
+        used if resumable=True. Pass in a value of -1 if the file is to be
+        uploaded as a single chunk. Note that Google App Engine has a 5MB limit
+        on request size, so you should never set your chunk size larger than 5MB,
+        or to -1.
+    :param resumable: True if this is a resumable upload. False means upload
+        in a single request.
+    :param api_version: version of the Google Drive API
+    :param delegate_to: The account to impersonate using domain-wide delegation of authority,
+        if any. For this to work, the service account making the request must have
+        domain-wide delegation enabled.
+    :param impersonation_chain: Optional service account to impersonate using short-term
+        credentials, or chained list of accounts required to get the access_token
+        of the last account in the list, which will be impersonated in the request.
+        If set as a string, the account must grant the originating account
+        the Service Account Token Creator IAM role.
+        If set as a sequence, the identities from the list must grant
+        Service Account Token Creator IAM role to the directly preceding identity, with first
+        account from the list granting this role to the originating account
+    :return: Remote file ids after upload
+    :rtype: Sequence[str]
+    """
+
+    template_fields = ('local_paths', 'drive_folder',)
+
+    def __init__(
+        self,
+        local_paths,
+        drive_folder: str,
+        gcp_conn_id: str,
+        delete: bool = False,
+        chunk_size: int = 100 * 1024 * 1024,
+        resumable: bool = False,
+        api_version: str = 'v3',

Review comment:
       actually, we can get rid of it altogether, because it's passed to the hook and the hook already has the version default.




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

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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