예제 #1
0
    def execute(self, context):

        self.gcs_hook = GCSHook(google_cloud_storage_conn_id=self.gcp_conn_id,
                                delegate_to=self.delegate_to)
        self.gdrive_hook = GoogleDriveHook(gcp_conn_id=self.gcp_conn_id,
                                           delegate_to=self.delegate_to)

        if WILDCARD in self.source_object:
            total_wildcards = self.source_object.count(WILDCARD)
            if total_wildcards > 1:
                error_msg = (
                    "Only one wildcard '*' is allowed in source_object parameter. "
                    "Found {} in {}.".format(total_wildcards,
                                             self.source_object))

                raise AirflowException(error_msg)

            prefix, delimiter = self.source_object.split(WILDCARD, 1)
            objects = self.gcs_hook.list(self.source_bucket,
                                         prefix=prefix,
                                         delimiter=delimiter)

            for source_object in objects:
                if self.destination_object is None:
                    destination_object = source_object
                else:
                    destination_object = source_object.replace(
                        prefix, self.destination_object, 1)

                self._copy_single_object(source_object=source_object,
                                         destination_object=destination_object)
        else:
            self._copy_single_object(
                source_object=self.source_object,
                destination_object=self.destination_object)
예제 #2
0
    def execute(self, context: "Context") -> List[str]:
        hook = GoogleDriveHook(
            gcp_conn_id=self.gcp_conn_id,
            delegate_to=self.delegate_to,
            impersonation_chain=self.impersonation_chain,
        )

        remote_file_ids = []

        for local_path in self.local_paths:
            self.log.info("Uploading file to Google Drive: %s", local_path)

            try:
                remote_file_id = hook.upload_file(
                    local_location=str(local_path),
                    remote_location=str(Path(self.drive_folder) / Path(local_path).name),
                    chunk_size=self.chunk_size,
                    resumable=self.resumable,
                )

                remote_file_ids.append(remote_file_id)

                if self.delete:
                    os.remove(local_path)
                    self.log.info("Deleted local file: %s", local_path)
            except FileNotFoundError:
                self.log.warning("File can't be found: %s", local_path)
            except OSError:
                self.log.warning("An OSError occurred for file: %s", local_path)

        if not self.ignore_if_missing and len(remote_file_ids) < len(self.local_paths):
            raise AirflowFailException("Some files couldn't be uploaded")
        return remote_file_ids
예제 #3
0
파일: drive.py 프로젝트: ysktir/airflow-1
 def poke(self, context: dict) -> bool:
     self.log.info('Sensor is checking for the file %s in the folder %s',
                   self.file_name, self.folder_id)
     hook = GoogleDriveHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         impersonation_chain=self.impersonation_chain,
     )
     return hook.exists(folder_id=self.folder_id,
                        file_name=self.file_name,
                        drive_id=self.drive_id)
예제 #4
0
    def execute(self, context: 'Context'):
        self.log.info('Executing download: %s into %s', self.file_name,
                      self.output_file)
        gdrive_hook = GoogleDriveHook(
            delegate_to=self.delegate_to,
            impersonation_chain=self.impersonation_chain,
        )
        file_metadata = gdrive_hook.get_file_id(folder_id=self.folder_id,
                                                file_name=self.file_name,
                                                drive_id=self.drive_id)

        with open(self.output_file, "wb") as file:
            gdrive_hook.download_file(file_id=file_metadata["id"],
                                      file_handle=file)
예제 #5
0
 def _upload_data(self, gcs_hook: GCSHook,
                  gdrive_hook: GoogleDriveHook) -> str:
     file_handle = BytesIO()
     self._set_file_metadata(gdrive_hook=gdrive_hook)
     file_id = self.file_metadata["id"]
     mime_type = self.file_metadata["mime_type"]
     request = gdrive_hook.get_media_request(file_id=file_id)
     gdrive_hook.download_content_from_request(file_handle=file_handle,
                                               request=request,
                                               chunk_size=104857600)
     gcs_hook.upload(
         bucket_name=self.destination_bucket,
         object_name=self.destination_object,
         data=file_handle.getvalue(),
         mime_type=mime_type,
     )
예제 #6
0
 def execute(self, context: 'Context'):
     gdrive_hook = GoogleDriveHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         impersonation_chain=self.impersonation_chain,
     )
     gcs_hook = GCSHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         impersonation_chain=self.impersonation_chain,
     )
     file_metadata = gdrive_hook.get_file_id(
         folder_id=self.folder_id, file_name=self.file_name, drive_id=self.drive_id
     )
     with gcs_hook.provide_file_and_upload(
         bucket_name=self.bucket_name, object_name=self.object_name
     ) as file:
         gdrive_hook.download_file(file_id=file_metadata["id"], file_handle=file)
예제 #7
0
 def execute(self, context):
     gdrive_hook = GoogleDriveHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         impersonation_chain=self.impersonation_chain,
     )
     gcs_hook = GCSHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         impersonation_chain=self.impersonation_chain,
     )
     self._upload_data(gdrive_hook=gdrive_hook, gcs_hook=gcs_hook)
예제 #8
0
 def setUp(self):
     self.patcher_get_connection = mock.patch(
         "airflow.hooks.base.BaseHook.get_connection",
         return_value=GCP_CONNECTION_WITH_PROJECT_ID)
     self.patcher_get_connection.start()
     self.gdrive_hook = GoogleDriveHook(gcp_conn_id="test")
예제 #9
0
class TestGoogleDriveHook(unittest.TestCase):
    def setUp(self):
        self.patcher_get_connection = mock.patch(
            "airflow.hooks.base.BaseHook.get_connection",
            return_value=GCP_CONNECTION_WITH_PROJECT_ID)
        self.patcher_get_connection.start()
        self.gdrive_hook = GoogleDriveHook(gcp_conn_id="test")

    def tearDown(self) -> None:
        self.patcher_get_connection.stop()

    @mock.patch(
        "airflow.providers.google.common.hooks.base_google.GoogleBaseHook._authorize",
        return_value="AUTHORIZE",
    )
    @mock.patch("airflow.providers.google.suite.hooks.drive.build")
    def test_get_conn(self, mock_discovery_build, mock_authorize):
        self.gdrive_hook.get_conn()
        mock_discovery_build.assert_called_once_with("drive",
                                                     "v3",
                                                     cache_discovery=False,
                                                     http="AUTHORIZE")

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_ensure_folders_exists_when_no_folder_exists(self, mock_get_conn):
        mock_get_conn.return_value.files.return_value.list.return_value.execute.return_value = {
            "files": []
        }
        mock_get_conn.return_value.files.return_value.create.return_value.execute.side_effect = [
            {
                "id": "ID_1"
            },
            {
                "id": "ID_2"
            },
            {
                "id": "ID_3"
            },
            {
                "id": "ID_4"
            },
        ]

        result_value = self.gdrive_hook._ensure_folders_exists(
            "AAA/BBB/CCC/DDD")

        mock_get_conn.assert_has_calls(
            [
                mock.call().files().create(
                    body={
                        "name": "AAA",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["root"],
                    },
                    fields="id",
                ),
                mock.call().files().create(
                    body={
                        "name": "BBB",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["ID_1"],
                    },
                    fields="id",
                ),
                mock.call().files().create(
                    body={
                        "name": "CCC",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["ID_2"],
                    },
                    fields="id",
                ),
                mock.call().files().create(
                    body={
                        "name": "DDD",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["ID_3"],
                    },
                    fields="id",
                ),
            ],
            any_order=True,
        )

        assert "ID_4" == result_value

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_ensure_folders_exists_when_some_folders_exists(
            self, mock_get_conn):
        mock_get_conn.return_value.files.return_value.list.return_value.execute.side_effect = [
            {
                "files": [{
                    "id": "ID_1"
                }]
            },
            {
                "files": [{
                    "id": "ID_2"
                }]
            },
            {
                "files": []
            },
        ]
        mock_get_conn.return_value.files.return_value.create.return_value.execute.side_effect = [
            {
                "id": "ID_3"
            },
            {
                "id": "ID_4"
            },
        ]

        result_value = self.gdrive_hook._ensure_folders_exists(
            "AAA/BBB/CCC/DDD")

        mock_get_conn.assert_has_calls(
            [
                mock.call().files().create(
                    body={
                        "name": "CCC",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["ID_2"],
                    },
                    fields="id",
                ),
                mock.call().files().create(
                    body={
                        "name": "DDD",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["ID_3"],
                    },
                    fields="id",
                ),
            ],
            any_order=True,
        )

        assert "ID_4" == result_value

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_ensure_folders_exists_when_all_folders_exists(
            self, mock_get_conn):
        mock_get_conn.return_value.files.return_value.list.return_value.execute.side_effect = [
            {
                "files": [{
                    "id": "ID_1"
                }]
            },
            {
                "files": [{
                    "id": "ID_2"
                }]
            },
            {
                "files": [{
                    "id": "ID_3"
                }]
            },
            {
                "files": [{
                    "id": "ID_4"
                }]
            },
        ]

        result_value = self.gdrive_hook._ensure_folders_exists(
            "AAA/BBB/CCC/DDD")

        mock_get_conn.return_value.files.return_value.create.assert_not_called(
        )
        assert "ID_4" == result_value

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_file_id"
    )
    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_exists_when_file_exists(self, mock_get_conn, mock_method):
        folder_id = "abxy1z"
        drive_id = "abc123"
        file_name = "abc123.csv"

        result_value = self.gdrive_hook.exists(folder_id=folder_id,
                                               file_name=file_name,
                                               drive_id=drive_id)
        mock_method.assert_called_once_with(folder_id=folder_id,
                                            file_name=file_name,
                                            drive_id=drive_id)
        self.assertEqual(True, result_value)

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_file_id"
    )
    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_exists_when_file_not_exists(self, mock_get_conn, mock_method):
        folder_id = "abxy1z"
        drive_id = "abc123"
        file_name = "abc123.csv"

        self.gdrive_hook.exists(folder_id=folder_id,
                                file_name=file_name,
                                drive_id=drive_id)
        mock_method.assert_called_once_with(folder_id=folder_id,
                                            file_name=file_name,
                                            drive_id=drive_id)

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_get_media_request(self, mock_get_conn):
        file_id = "1eC-Ahi4t57pHcLbW3C_xHB3-YrTQLQBa"

        self.gdrive_hook.get_media_request(file_id)
        mock_get_conn.return_value.files.return_value.get_media.assert_called_once_with(
            fileId=file_id)

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_get_file_id_when_one_file_exists(self, mock_get_conn):
        folder_id = "abxy1z"
        drive_id = "abc123"
        file_name = "abc123.csv"

        mock_get_conn.return_value.files.return_value.list.return_value.execute.side_effect = [
            {
                "files": [{
                    "id": "ID_1",
                    "mimeType": "text/plain"
                }]
            }
        ]

        result_value = self.gdrive_hook.get_file_id(folder_id, file_name,
                                                    drive_id)
        self.assertEqual({
            "id": "ID_1",
            "mime_type": "text/plain"
        }, result_value)

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_get_file_id_when_multiple_files_exists(self, mock_get_conn):
        folder_id = "abxy1z"
        drive_id = "abc123"
        file_name = "abc123.csv"

        mock_get_conn.return_value.files.return_value.list.return_value.execute.side_effect = [
            {
                "files": [{
                    "id": "ID_1",
                    "mimeType": "text/plain"
                }, {
                    "id": "ID_2",
                    "mimeType": "text/plain"
                }]
            }
        ]

        result_value = self.gdrive_hook.get_file_id(folder_id, file_name,
                                                    drive_id)
        self.assertEqual({
            "id": "ID_1",
            "mime_type": "text/plain"
        }, result_value)

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_get_file_id_when_no_file_exists(self, mock_get_conn):
        folder_id = "abxy1z"
        drive_id = "abc123"
        file_name = "abc123.csv"

        mock_get_conn.return_value.files.return_value.list.return_value.execute.side_effect = [
            {
                "files": []
            }
        ]

        result_value = self.gdrive_hook.get_file_id(folder_id, file_name,
                                                    drive_id)
        self.assertEqual({}, result_value)

    @mock.patch("airflow.providers.google.suite.hooks.drive.MediaFileUpload")
    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook._ensure_folders_exists"
    )
    def test_upload_file_to_root_directory(self, mock_ensure_folders_exists,
                                           mock_get_conn,
                                           mock_media_file_upload):
        mock_get_conn.return_value.files.return_value.create.return_value.execute.return_value = {
            "id": "FILE_ID"
        }

        return_value = self.gdrive_hook.upload_file("local_path",
                                                    "remote_path")

        mock_ensure_folders_exists.assert_not_called()
        mock_get_conn.assert_has_calls([
            mock.call().files().create(
                body={
                    "name": "remote_path",
                    "parents": ["root"]
                },
                fields="id",
                media_body=mock_media_file_upload.return_value,
            )
        ])
        assert return_value == "FILE_ID"

    @mock.patch("airflow.providers.google.suite.hooks.drive.MediaFileUpload")
    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook._ensure_folders_exists",
        return_value="PARENT_ID",
    )
    def test_upload_file_to_subdirectory(self, mock_ensure_folders_exists,
                                         mock_get_conn,
                                         mock_media_file_upload):
        mock_get_conn.return_value.files.return_value.create.return_value.execute.return_value = {
            "id": "FILE_ID"
        }

        return_value = self.gdrive_hook.upload_file("local_path",
                                                    "AA/BB/CC/remote_path")

        mock_ensure_folders_exists.assert_called_once_with("AA/BB/CC")
        mock_get_conn.assert_has_calls([
            mock.call().files().create(
                body={
                    "name": "remote_path",
                    "parents": ["PARENT_ID"]
                },
                fields="id",
                media_body=mock_media_file_upload.return_value,
            )
        ])
        assert return_value == "FILE_ID"
예제 #10
0
class TestGoogleDriveHook(unittest.TestCase):
    def setUp(self):
        self.patcher_get_connections = mock.patch(
            "airflow.hooks.base_hook.BaseHook.get_connections",
            return_value=[GCP_CONNECTION_WITH_PROJECT_ID])
        self.patcher_get_connections.start()
        self.gdrive_hook = GoogleDriveHook(gcp_conn_id="test")

    def tearDown(self) -> None:
        self.patcher_get_connections.stop()

    @mock.patch(
        "airflow.providers.google.common.hooks.base_google.GoogleBaseHook._authorize",
        return_value="AUTHORIZE",
    )
    @mock.patch("airflow.providers.google.suite.hooks.drive.build")
    def test_get_conn(self, mock_discovery_build, mock_authorize):
        self.gdrive_hook.get_conn()
        mock_discovery_build.assert_called_once_with("drive",
                                                     "v3",
                                                     cache_discovery=False,
                                                     http="AUTHORIZE")

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_ensure_folders_exists_when_no_folder_exists(self, mock_get_conn):
        mock_get_conn.return_value.files.return_value.list.return_value.execute.return_value = {
            "files": []
        }
        mock_get_conn.return_value.files.return_value.create.return_value.execute.side_effect = [
            {
                "id": "ID_1"
            },
            {
                "id": "ID_2"
            },
            {
                "id": "ID_3"
            },
            {
                "id": "ID_4"
            },
        ]

        result_value = self.gdrive_hook._ensure_folders_exists(
            "AAA/BBB/CCC/DDD")

        mock_get_conn.assert_has_calls(
            [
                mock.call().files().create(
                    body={
                        "name": "AAA",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["root"],
                    },
                    fields="id",
                ),
                mock.call().files().create(
                    body={
                        "name": "BBB",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["ID_1"],
                    },
                    fields="id",
                ),
                mock.call().files().create(
                    body={
                        "name": "CCC",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["ID_2"],
                    },
                    fields="id",
                ),
                mock.call().files().create(
                    body={
                        "name": "DDD",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["ID_3"],
                    },
                    fields="id",
                ),
            ],
            any_order=True,
        )

        self.assertEqual("ID_4", result_value)

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_ensure_folders_exists_when_some_folders_exists(
            self, mock_get_conn):
        mock_get_conn.return_value.files.return_value.list.return_value.execute.side_effect = [
            {
                "files": [{
                    "id": "ID_1"
                }]
            },
            {
                "files": [{
                    "id": "ID_2"
                }]
            },
            {
                "files": []
            },
        ]
        mock_get_conn.return_value.files.return_value.create.return_value.execute.side_effect = [
            {
                "id": "ID_3"
            },
            {
                "id": "ID_4"
            },
        ]

        result_value = self.gdrive_hook._ensure_folders_exists(
            "AAA/BBB/CCC/DDD")

        mock_get_conn.assert_has_calls(
            [
                mock.call().files().create(
                    body={
                        "name": "CCC",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["ID_2"],
                    },
                    fields="id",
                ),
                mock.call().files().create(
                    body={
                        "name": "DDD",
                        "mimeType": "application/vnd.google-apps.folder",
                        "parents": ["ID_3"],
                    },
                    fields="id",
                ),
            ],
            any_order=True,
        )

        self.assertEqual("ID_4", result_value)

    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    def test_ensure_folders_exists_when_all_folders_exists(
            self, mock_get_conn):
        mock_get_conn.return_value.files.return_value.list.return_value.execute.side_effect = [
            {
                "files": [{
                    "id": "ID_1"
                }]
            },
            {
                "files": [{
                    "id": "ID_2"
                }]
            },
            {
                "files": [{
                    "id": "ID_3"
                }]
            },
            {
                "files": [{
                    "id": "ID_4"
                }]
            },
        ]

        result_value = self.gdrive_hook._ensure_folders_exists(
            "AAA/BBB/CCC/DDD")

        mock_get_conn.return_value.files.return_value.create.assert_not_called(
        )
        self.assertEqual("ID_4", result_value)

    @mock.patch("airflow.providers.google.suite.hooks.drive.MediaFileUpload")
    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook._ensure_folders_exists"
    )
    def test_upload_file_to_root_directory(self, mock_ensure_folders_exists,
                                           mock_get_conn,
                                           mock_media_file_upload):
        mock_get_conn.return_value.files.return_value.create.return_value.execute.return_value = {
            "id": "FILE_ID"
        }

        return_value = self.gdrive_hook.upload_file("local_path",
                                                    "remote_path")

        mock_ensure_folders_exists.assert_not_called()
        mock_get_conn.assert_has_calls([
            mock.call().files().create(
                body={
                    "name": "remote_path",
                    "parents": ["root"]
                },
                fields="id",
                media_body=mock_media_file_upload.return_value,
            )
        ])
        self.assertEqual(return_value, "FILE_ID")

    @mock.patch("airflow.providers.google.suite.hooks.drive.MediaFileUpload")
    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook.get_conn")
    @mock.patch(
        "airflow.providers.google.suite.hooks.drive.GoogleDriveHook._ensure_folders_exists",
        return_value="PARENT_ID",
    )
    def test_upload_file_to_subdirectory(self, mock_ensure_folders_exists,
                                         mock_get_conn,
                                         mock_media_file_upload):
        mock_get_conn.return_value.files.return_value.create.return_value.execute.return_value = {
            "id": "FILE_ID"
        }

        return_value = self.gdrive_hook.upload_file("local_path",
                                                    "AA/BB/CC/remote_path")

        mock_ensure_folders_exists.assert_called_once_with("AA/BB/CC")
        mock_get_conn.assert_has_calls([
            mock.call().files().create(
                body={
                    "name": "remote_path",
                    "parents": ["PARENT_ID"]
                },
                fields="id",
                media_body=mock_media_file_upload.return_value,
            )
        ])
        self.assertEqual(return_value, "FILE_ID")
예제 #11
0
class GCSToGoogleDriveOperator(BaseOperator):
    """
    Copies objects from a Google Cloud Storage service service to Google Drive service, with renaming
    if requested.

    Using this operator requires the following OAuth 2.0 scope:

    .. code-block:: none

        https://www.googleapis.com/auth/drive

    .. seealso::
        For more information on how to use this operator, take a look at the guide:
        :ref:`howto/operator:GCSToGoogleDriveOperator`

    :param source_bucket: The source Google Cloud Storage bucket where the object is. (templated)
    :type source_bucket: str
    :param source_object: The source name of the object to copy in the Google cloud
        storage bucket. (templated)
        You can use only one wildcard for objects (filenames) within your bucket. The wildcard can appear
        inside the object name or at the end of the object name. Appending a wildcard to the bucket name
        is unsupported.
    :type source_object: str
    :param destination_object: The destination name of the object in the destination Google Drive
        service. (templated)
        If a wildcard is supplied in the source_object argument, this is the prefix that will be prepended
        to the final destination objects' paths.
        Note that the source path's part before the wildcard will be removed;
        if it needs to be retained it should be appended to destination_object.
        For example, with prefix ``foo/*`` and destination_object ``blah/``, the file ``foo/baz`` will be
        copied to ``blah/baz``; to retain the prefix write the destination_object as e.g. ``blah/foo``, in
        which case the copied file will be named ``blah/foo/baz``.
    :type destination_object: str
    :param move_object: When move object is True, the object is moved instead of copied to the new location.
        This is the equivalent of a mv command as opposed to a cp command.
    :type move_object: bool
    :param gcp_conn_id: (Optional) The connection ID used to connect to Google Cloud Platform.
    :type gcp_conn_id: str
    :param delegate_to: The account to impersonate, if any.
        For this to work, the service account making the request must have domain-wide delegation enabled.
    :type delegate_to: str
    """

    template_fields = ("source_bucket", "source_object", "destination_object")
    ui_color = "#f0eee4"

    @apply_defaults
    def __init__(self,
                 source_bucket: str,
                 source_object: str,
                 destination_object: Optional[str] = None,
                 move_object: bool = False,
                 gcp_conn_id: str = "google_cloud_default",
                 delegate_to: Optional[str] = None,
                 *args,
                 **kwargs):
        super().__init__(*args, **kwargs)

        self.source_bucket = source_bucket
        self.source_object = source_object
        self.destination_object = destination_object
        self.move_object = move_object
        self.gcp_conn_id = gcp_conn_id
        self.delegate_to = delegate_to
        self.gcs_hook = None  # type: Optional[GCSHook]
        self.gdrive_hook = None  # type: Optional[GoogleDriveHook]

    def execute(self, context):

        self.gcs_hook = GCSHook(google_cloud_storage_conn_id=self.gcp_conn_id,
                                delegate_to=self.delegate_to)
        self.gdrive_hook = GoogleDriveHook(gcp_conn_id=self.gcp_conn_id,
                                           delegate_to=self.delegate_to)

        if WILDCARD in self.source_object:
            total_wildcards = self.source_object.count(WILDCARD)
            if total_wildcards > 1:
                error_msg = (
                    "Only one wildcard '*' is allowed in source_object parameter. "
                    "Found {} in {}.".format(total_wildcards,
                                             self.source_object))

                raise AirflowException(error_msg)

            prefix, delimiter = self.source_object.split(WILDCARD, 1)
            objects = self.gcs_hook.list(self.source_bucket,
                                         prefix=prefix,
                                         delimiter=delimiter)

            for source_object in objects:
                if self.destination_object is None:
                    destination_object = source_object
                else:
                    destination_object = source_object.replace(
                        prefix, self.destination_object, 1)

                self._copy_single_object(source_object=source_object,
                                         destination_object=destination_object)
        else:
            self._copy_single_object(
                source_object=self.source_object,
                destination_object=self.destination_object)

    def _copy_single_object(self, source_object, destination_object):
        self.log.info(
            "Executing copy of gs://%s/%s to gdrive://%s",
            self.source_bucket,
            source_object,
            destination_object,
        )

        with tempfile.NamedTemporaryFile() as file:
            filename = file.name
            self.gcs_hook.download(bucket_name=self.source_bucket,
                                   object_name=source_object,
                                   filename=filename)
            self.gdrive_hook.upload_file(local_location=filename,
                                         remote_location=destination_object)

        if self.move_object:
            self.gcs_hook.delete(self.source_bucket, source_object)