Source code for airflow.providers.google.cloud.example_dags.example_functions
## 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."""Example Airflow DAG that displays interactions with Google Cloud Functions.It creates a function and then deletes it.This DAG relies on the following OS environment variableshttps://airflow.apache.org/concepts.html#variables* GCP_PROJECT_ID - Google Cloud Project to use for the Cloud Function.* GCP_LOCATION - Google Cloud Functions region where the function should be created.* GCF_ENTRYPOINT - Name of the executable function in the source code.* and one of the below: * GCF_SOURCE_ARCHIVE_URL - Path to the zipped source in Google Cloud Storage * GCF_SOURCE_UPLOAD_URL - Generated upload URL for the zipped source and GCF_ZIP_PATH - Local path to the zipped source archive * GCF_SOURCE_REPOSITORY - The URL pointing to the hosted repository where the function is defined in a supported Cloud Source Repository URL format https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions#SourceRepository"""importosfromdatetimeimportdatetimefromtypingimportAny,Dictfromairflowimportmodelsfromairflow.providers.google.cloud.operators.functionsimport(CloudFunctionDeleteFunctionOperator,CloudFunctionDeployFunctionOperator,CloudFunctionInvokeFunctionOperator,)
# [END howto_operator_gcf_default_args]# [START howto_operator_gcf_deploy_variants]ifGCF_SOURCE_ARCHIVE_URL:body['sourceArchiveUrl']=GCF_SOURCE_ARCHIVE_URLelifGCF_SOURCE_REPOSITORY:body['sourceRepository']={'url':GCF_SOURCE_REPOSITORY}elifGCF_ZIP_PATH:body['sourceUploadUrl']=''default_args['zip_path']=GCF_ZIP_PATHelifGCF_SOURCE_UPLOAD_URL:body['sourceUploadUrl']=GCF_SOURCE_UPLOAD_URLelse:raiseException("Please provide one of the source_code parameters")# [END howto_operator_gcf_deploy_variants]withmodels.DAG('example_gcp_function',default_args=default_args,schedule_interval='@once',# Override to match your needsstart_date=datetime(2021,1,1),catchup=False,tags=['example'],)asdag:# [START howto_operator_gcf_deploy]