RNHTTR commented on a change in pull request #13982:
URL: https://github.com/apache/airflow/pull/13982#discussion_r567499142



##########
File path: airflow/providers/google/cloud/transfers/gdrive_to_gcs.py
##########
@@ -0,0 +1,134 @@
+# 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.
+
+from io import BytesIO
+from typing import Optional, Sequence, Union
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.google.cloud.hooks.gcs import GCSHook
+from airflow.providers.google.suite.hooks.drive import GoogleDriveHook
+from airflow.utils.decorators import apply_defaults
+
+
+class GoogleDriveToGCSOperator(BaseOperator):
+    """
+    Writes a Google Drive file into Google Cloud Storage.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:GoogleDriveToGCSOperator` FIXME
+
+    :param destination_bucket: The destination Google cloud storage bucket 
where the
+        report should be written to. (templated)
+    :param destination_bucket: str
+    :param destination_object: The Google Cloud Storage object name for the 
object created by the operator.
+        For example: ``path/to/my/file/file.txt``.
+    :type destination_object: str
+    :param folder_id: The folder id of the folder in whhich the Google Drive 
file resides
+    :type folder_id: str
+    :param file_name: The name of the file residing in Google Drive
+    :type file_name: str
+    :param gcp_conn_id: The GCP connection ID to use when fetching connection 
info.
+    :type gcp_conn_id: str
+    :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.
+    :type delegate_to: str
+    :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 
(templated).
+    :type impersonation_chain: Union[str, Sequence[str]]
+    """
+
+    template_fields = [
+        "destination_bucket",
+        "destination_object",
+        "folder_id",
+        "file_name",
+        "impersonation_chain",
+    ]
+
+    @apply_defaults
+    def __init__(
+        self,
+        *,
+        destination_bucket: str,
+        destination_object: str,
+        folder_id: Optional[str] = None,
+        file_name: Optional[str] = None,
+        gcp_conn_id: str = "google_cloud_default",
+        delegate_to: Optional[str] = None,
+        impersonation_chain: Optional[Union[str, Sequence[str]]] = None,
+        **kwargs,
+    ) -> None:
+        if folder_id and not file_name:
+            raise AirflowException("Both folder_id and file_name must be set. 
Received only folder_id")

Review comment:
       I overlooked the `driveId` param in the files.list method for searching 
shared Drives. I don't have a Google Workspace account, so I can't test this 
without access to a shared Drive. Do you know how I can get access to one?
   
   I think this would only slightly change the implementation -- ~`folder_id` 
would be optional, the files.list `query` param would be dynamic based on the 
presence or absence of `folder_id`, and~ `drive_id` would be added as an 
optional init param. 
   
   `folder_id` should remain required. Imagine a scenario where a user has an 
arbitrary number of folders, and each folder contains a file `abc.csv`. If 
`folder_id` is optional, the file that gets returned would be ambiguous (or at 
least confusing -- the documentation doesn't make clear how the list of files 
is ordered in the response to `files.list()`)




----------------------------------------------------------------
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:
[email protected]


Reply via email to