def test_object_create_acl(self, mock_hook):
     operator = GoogleCloudStorageObjectCreateAclEntryOperator(
         bucket="test-bucket",
         object_name="test-object",
         entity="test-entity",
         generation=42,
         role="test-role",
         user_project="test-user-project",
         task_id="id")
     operator.execute(None)
     mock_hook.return_value.insert_object_acl.assert_called_once_with(
         bucket_name="test-bucket",
         object_name="test-object",
         entity="test-entity",
         generation=42,
         role="test-role",
         user_project="test-user-project")
    )
    # [END howto_operator_cloudsql_export]

    # ############################################## #
    # ### IMPORTING SQL TO INSTANCE 2 ############## #
    # ############################################## #
    import_url_split = urlsplit(IMPORT_URI)

    # For import to work we need to add the Cloud SQL instance's Service Account
    # read access to the target GCS object.
    # [START howto_operator_cloudsql_import_gcs_permissions]
    sql_gcp_add_object_permission_task = GoogleCloudStorageObjectCreateAclEntryOperator(
        entity="user-{{ task_instance.xcom_pull("
               "'sql_instance_create_task2', key='service_account_email')"
               " }}",
        role="READER",
        bucket=import_url_split[1],  # netloc (bucket)
        object_name=import_url_split[2][1:],  # path (strip first '/')
        task_id='sql_gcp_add_object_permission_task',
    )

    # For import to work we also need to add the Cloud SQL instance's Service Account
    # write access to the whole bucket!.
    sql_gcp_add_bucket_permission_2_task = GoogleCloudStorageBucketCreateAclEntryOperator(
        entity="user-{{ task_instance.xcom_pull("
               "'sql_instance_create_task2', key='service_account_email') "
               "}}",
        role="WRITER",
        bucket=import_url_split[1],  # netloc
        task_id='sql_gcp_add_bucket_permission_2_task',
    )
Exemple #3
0
        source_object=BUCKET_FILE_LOCATION,
        transform_script=["python", PATH_TO_TRANSFORM_SCRIPT])
    # [START howto_operator_gcs_bucket_create_acl_entry_task]
    gcs_bucket_create_acl_entry_task = GoogleCloudStorageBucketCreateAclEntryOperator(
        bucket=BUCKET_1,
        entity=GCS_ACL_ENTITY,
        role=GCS_ACL_BUCKET_ROLE,
        task_id="gcs_bucket_create_acl_entry_task",
    )
    # [END howto_operator_gcs_bucket_create_acl_entry_task]

    # [START howto_operator_gcs_object_create_acl_entry_task]
    gcs_object_create_acl_entry_task = GoogleCloudStorageObjectCreateAclEntryOperator(
        bucket=BUCKET_1,
        object_name=BUCKET_FILE_LOCATION,
        entity=GCS_ACL_ENTITY,
        role=GCS_ACL_OBJECT_ROLE,
        task_id="gcs_object_create_acl_entry_task",
    )
    # [END howto_operator_gcs_object_create_acl_entry_task]

    download_file = GoogleCloudStorageDownloadOperator(
        task_id="download_file",
        object_name=BUCKET_FILE_LOCATION,
        bucket=BUCKET_1,
        filename=PATH_TO_SAVED_FILE,
    )

    copy_file = GoogleCloudStorageToGoogleCloudStorageOperator(
        task_id="copy_file",
        source_bucket=BUCKET_1,