airflow.providers.google.cloud.operators.functions

此模块包含 Google Cloud Functions 的操作算子(operators)。

属性

CLOUD_FUNCTION_VALIDATION

GCF_SOURCE_ARCHIVE_URL

GCF_SOURCE_UPLOAD_URL

SOURCE_REPOSITORY

GCF_ZIP_PATH

FUNCTION_NAME_PATTERN

FUNCTION_NAME_COMPILED_PATTERN

CloudFunctionDeployFunctionOperator

在 Google Cloud Functions 中创建或更新函数。

ZipPathPreprocessor

预处理 zip 路径参数。

CloudFunctionDeleteFunctionOperator

从 Google Cloud Functions 中删除指定的函数。

CloudFunctionInvokeFunctionOperator

调用已部署的 Cloud Function。由于允许的流量非常有限,仅用于测试目的。

模块内容

airflow.providers.google.cloud.operators.functions.CLOUD_FUNCTION_VALIDATION: list[dict[str, Any]][source]
class airflow.providers.google.cloud.operators.functions.CloudFunctionDeployFunctionOperator(*, location, body, project_id=PROVIDE_PROJECT_ID, gcp_conn_id='google_cloud_default', api_version='v1', zip_path=None, validate_body=True, impersonation_chain=None, **kwargs)[source]

基类:airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

在 Google Cloud Functions 中创建或更新函数。

另请参阅

有关如何使用此操作算子的更多信息,请查看指南: CloudFunctionDeployFunctionOperator

参数:
  • location (str) – 应该创建函数的 Google Cloud 区域。

  • body (dict) – Cloud Functions 定义的主体。主体必须是 Cloud Functions 字典,详见: https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions 。不同的 API 版本需要 Cloud Functions 字典的不同变体。

  • project_id (str) – (可选) 应该创建函数的 Google Cloud 项目 ID。

  • gcp_conn_id (str) – (可选) 用于连接到 Google Cloud 的连接 ID。默认为 ‘google_cloud_default’。

  • api_version (str) – (可选) 使用的 API 版本(例如 v1 - 默认 - 或 v1beta1)。

  • zip_path (str | None) – 包含函数源代码的 zip 文件路径。如果设置了此路径,则不应在 body 中指定 sourceUploadUrl,或者该字段应为空。然后,zip 文件将使用通过 Cloud Functions API 的 generateUploadUrl 生成的上传 URL 进行上传。

  • validate_body (bool) – 如果设置为 False,则不执行主体验证。

  • impersonation_chain (str | collections.abc.Sequence[str] | None) – 可选:使用短期凭据进行模拟的服务账号,或者获取列表中最后一个账号的 access_token 所需的链式账号列表,该账号将在请求中被模拟。如果设置为字符串,该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,列表中的标识必须授予其紧随其后的标识 Service Account Token Creator IAM 角色,列表中第一个账号授予发起账号此角色(可模板化)。

template_fields: collections.abc.Sequence[str] = ('body', 'project_id', 'location', 'gcp_conn_id', 'api_version', 'impersonation_chain')[source]
project_id = None[source]
location[source]
body[source]
gcp_conn_id = 'google_cloud_default'[source]
api_version = 'v1'[source]
zip_path = None[source]
zip_path_preprocessor[source]
impersonation_chain = None[source]

重写此方法以在额外链接(extra links)中包含链接格式化所需的参数。

例如;Google 提供者的大多数链接在链接中都需要 project_idlocation。为了不重复,你可以重写此函数并返回如下内容:

{
    "project_id": self.project_id,
    "location": self.location,
}
execute(context)[source]

在创建算子时派生。

执行任务的主要方法。Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参考 get_template_context。

airflow.providers.google.cloud.operators.functions.GCF_SOURCE_ARCHIVE_URL = 'sourceArchiveUrl'[source]
airflow.providers.google.cloud.operators.functions.GCF_SOURCE_UPLOAD_URL = 'sourceUploadUrl'[source]
airflow.providers.google.cloud.operators.functions.SOURCE_REPOSITORY = 'sourceRepository'[source]
airflow.providers.google.cloud.operators.functions.GCF_ZIP_PATH = 'zip_path'[source]
class airflow.providers.google.cloud.operators.functions.ZipPathPreprocessor(body, zip_path=None)[source]

预处理 zip 路径参数。

负责检查 zip 路径参数相对于 source_code 主体字段是否正确指定。非空的 zip 路径参数很特殊,因为它与 sourceArchiveUrl 和 sourceRepository 主体字段互斥。它也与非空的 sourceUploadUrl 互斥。当 zip_path 不为空时,预处理会以特殊方式修改 sourceUploadUrl 主体字段。当调用 execute 方法时,会运行一个额外的步骤,并将 sourceUploadUrl 字段值设置为通过 Cloud Function API 的 generateUploadUrl 方法返回的值。

参数:
  • body (dict) – 传递给创建/更新方法调用的主体。

  • zip_path (str | None) – (可选) 包含函数源代码的 zip 文件路径。如果设置了路径,则不应在主体中指定 sourceUploadUrl,或者该字段应为空。然后,zip 文件将使用通过 Cloud Functions API 的 generateUploadUrl 生成的上传 URL 进行上传。

upload_function: bool | None = None[source]
body[source]
zip_path = None[source]
should_upload_function()[source]

检查是否应上传函数源代码。

preprocess_body()[source]

当 zip_path 不为空时,以特殊方式修改 sourceUploadUrl 主体字段。

airflow.providers.google.cloud.operators.functions.FUNCTION_NAME_PATTERN = '^projects/[^/]+/locations/[^/]+/functions/[^/]+$'[source]
airflow.providers.google.cloud.operators.functions.FUNCTION_NAME_COMPILED_PATTERN[source]
class airflow.providers.google.cloud.operators.functions.CloudFunctionDeleteFunctionOperator(*, name, gcp_conn_id='google_cloud_default', api_version='v1', impersonation_chain=None, project_id=PROVIDE_PROJECT_ID, **kwargs)[source]

基类:airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

从 Google Cloud Functions 中删除指定的函数。

另请参阅

有关如何使用此操作算子的更多信息,请查看指南: CloudFunctionDeleteFunctionOperator

参数:
  • name (str) – 完全限定的函数名称,匹配模式: ^projects/[^/]+/locations/[^/]+/functions/[^/]+$

  • gcp_conn_id (str) – 用于连接 Google Cloud 的连接 ID。

  • api_version (str) – 使用的 API 版本(例如 v1 或 v1beta1)。

  • impersonation_chain (str | collections.abc.Sequence[str] | None) – 可选:使用短期凭据进行模拟的服务账号,或者获取列表中最后一个账号的 access_token 所需的链式账号列表,该账号将在请求中被模拟。如果设置为字符串,该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,列表中的标识必须授予其紧随其后的标识 Service Account Token Creator IAM 角色,列表中第一个账号授予发起账号此角色(可模板化)。

template_fields: collections.abc.Sequence[str] = ('name', 'gcp_conn_id', 'api_version', 'impersonation_chain')[source]
name[source]
project_id = None[source]
gcp_conn_id = 'google_cloud_default'[source]
api_version = 'v1'[source]
impersonation_chain = None[source]
execute(context)[source]

在创建算子时派生。

执行任务的主要方法。Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参考 get_template_context。

class airflow.providers.google.cloud.operators.functions.CloudFunctionInvokeFunctionOperator(*, function_id, input_data, location, project_id=PROVIDE_PROJECT_ID, gcp_conn_id='google_cloud_default', api_version='v1', impersonation_chain=None, **kwargs)[source]

基类:airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator

调用已部署的 Cloud Function。由于允许的流量非常有限,仅用于测试目的。

另请参阅

有关如何使用此操作算子的更多信息,请查看指南: CloudFunctionDeployFunctionOperator

参数:
  • function_id (str) – 要调用的函数 ID

  • input_data (dict) – 传递给函数的输入

  • location (str) – 函数所在的地点。

  • project_id (str) – 可选,函数所属的 Google Cloud Project project_id。如果设置为 None 或缺失,则使用 Google Cloud 连接中的默认 project_id。

  • impersonation_chain (str | collections.abc.Sequence[str] | None) – 可选:使用短期凭据进行模拟的服务账号,或者获取列表中最后一个账号的 access_token 所需的链式账号列表,该账号将在请求中被模拟。如果设置为字符串,该账号必须授予发起账号 Service Account Token Creator IAM 角色。如果设置为序列,列表中的标识必须授予其紧随其后的标识 Service Account Token Creator IAM 角色,列表中第一个账号授予发起账号此角色(可模板化)。

返回:

template_fields: collections.abc.Sequence[str] = ('function_id', 'input_data', 'location', 'project_id', 'impersonation_chain')[source]
function_id[source]
input_data[source]
location[source]
project_id = None[source]
gcp_conn_id = 'google_cloud_default'[source]
api_version = 'v1'[source]
impersonation_chain = None[source]

重写此方法以在额外链接(extra links)中包含链接格式化所需的参数。

例如;Google 提供者的大多数链接在链接中都需要 project_idlocation。为了不重复,你可以重写此函数并返回如下内容:

{
    "project_id": self.project_id,
    "location": self.location,
}
execute(context)[source]

在创建算子时派生。

执行任务的主要方法。Context 是与渲染 jinja 模板时使用的相同字典。

有关更多上下文,请参考 get_template_context。

此条目是否有帮助?