Source code for airflow.providers.google.cloud.transfers.azure_blob_to_gcs
# 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
# 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 __future__ import annotations
from typing import TYPE_CHECKING, Sequence
from airflow.models import BaseOperator
from airflow.providers.google.cloud.hooks.gcs import GCSHook
from airflow.providers.microsoft.azure.hooks.wasb import WasbHook
from airflow.utils.context import Context
Operator transfers data from Azure Blob Storage to specified bucket in Google Cloud Storage.
For more information on how to use this operator, take a look at the guide:
:param wasb_conn_id: Reference to the wasb connection.
:param gcp_conn_id: The connection ID to use when fetching connection info.
:param blob_name: Name of the blob
:param container_name: Name of the container
:param bucket_name: The bucket to upload to
:param object_name: The object name to set when uploading the file
:param filename: The local file path to the file to be uploaded
:param gzip: Option to compress local file or file data for upload
: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.
gcp_conn_id: str = "google_cloud_default",
impersonation_chain: str | Sequence[str] | None = None,
) -> None:
self.wasb_conn_id = wasb_conn_id
self.gcp_conn_id = gcp_conn_id
self.blob_name = blob_name
self.container_name = container_name
self.bucket_name = bucket_name
self.object_name = object_name
self.filename = filename
self.gzip = gzip
self.impersonation_chain = impersonation_chain
[docs] template_fields: Sequence[str] = (
[docs] def execute(self, context: Context) -> str:
azure_hook = WasbHook(wasb_conn_id=self.wasb_conn_id)
gcs_hook = GCSHook(
with tempfile.NamedTemporaryFile() as temp_file:
self.log.info("Downloading data from blob: %s", self.blob_name)
"Uploading data from blob's: %s into GCP bucket: %s", self.object_name, self.bucket_name
"Resources have been uploaded from blob: %s to GCS bucket:%s",