您的扩展程序的规范文件 (extension.yaml) 包含扩展程序的元数据,声明了扩展程序创建的资源以及扩展程序所需的 API 和访问权限,并且定义了扩展程序提供的可由用户配置的所有参数。
本页中的各表描述了 extension.yaml 文件的可用字段。
基本信息和标识信息
name: your-extension-name
version: 1.0.0         # Semantic versioning (semver)
specVersion: v1beta    # Always "v1beta"
license: Apache-2.0    # Always "Apache-2.0" (required to publish on extensions.dev)
billingRequired: true  # Always "true"
displayName: Your extension name
description: >-
  Description of the extension. (One or two
  sentences.)
icon: icon.png
tags: [tag, anothertag]
sourceUrl: https://github.com/your-org/your-repo   # GitHub repo URL
releaseNotesUrl: https://github.com/your-org/your-repo/blob/main/CHANGELOG.md
author:
  authorName: Your Company
  email: extensions@example.com
  url: https://example.com/
contributors:
  - authorName: Your Name
  - authorName: Another Contributor
    email: colleague@example.net
    url: https://github.com/their-org/
| 基本字段 | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| name字符串 (必填) | 扩展程序的标识符。 只能包含小写字母、数字和短划线;不能超过 40 个字符。 注意:此值用于生成扩展程序的实例 ID(该 ID 稍后用于生成扩展程序的服务账号及特定于扩展程序的资源的名称)。 | ||||||||
| version字符串 (必填) | 扩展程序的版本。 必须遵循 semver 版本控制(例如 1.2.0)。 | ||||||||
| specVersion字符串 (必填) | Firebase Extensions 扩展程序规范的版本。 当前值: | ||||||||
| license字符串 (选填) | 扩展程序的许可。 您的扩展程序必须遵循  | ||||||||
| billingRequired布尔值 (选填) | 扩展程序使用的服务是否需要付费层级 Firebase 结算账号。 一律设置为  | ||||||||
| displayName字符串 (选填) | 扩展程序的易记显示名(3-5 个字词)。 不能超过 40 个字符。 | ||||||||
| description字符串 (选填) | 扩展程序执行的任务的简要说明(约 1 个句子)。 | ||||||||
| icon字符串 (选填) | 用作  必须是大小介于 512x512 与 1024x1024 像素之间的方形 PNG 文件。请将该文件放在  为扩展程序设计图标时,请遵循以下准则: 
 | ||||||||
| tags字符串列表 (选填) | 可帮助用户发现您的扩展程序的标签。以下标签与 Extensions Hub 上的类别相对应: marketing、messaging、payments、search、shipping、social、utilities、ai | ||||||||
| sourceUrl字符串 (选填) | 可访问扩展程序目录的公开网址。 | ||||||||
| releaseNotesUrl字符串 (选填) | 可访问扩展程序版本说明的公开网址。 | ||||||||
| author一个 author 对象 (选填) | 扩展程序的主要作者和联系人。 author: authorName: Your Company email: extensions@example.com url: https://example.com/ 
 | ||||||||
| contributorsauthor 对象的列表 (选填) | 扩展程序的任何其他创作贡献作者。 contributors: - authorName: Your Name - authorName: Another Contributor email: colleague@example.net url: https://github.com/their-org/ 
 | ||||||||
Firebase 和 Google Cloud API
这些字段指定扩展程序使用的 Firebase 和 Google API。用户安装扩展程序时,可以选择在项目中自动启用这些 API。
apis:
  - apiName: apiname.googleapis.com
    reason: Explanation of why the extension uses this API
  - apiName: anotherapiname.googleapis.com
    reason: Explanation of why the extension uses this API
| API 相关字段 | |
|---|---|
| apiName字符串 (必填) | Google API 的名称 必须与 Google Cloud API 库中每个 API 的概览页面(示例)中列出的“服务名称”字段相对应 | 
| reason字符串 (必填) | 有关扩展程序为何需要使用此 API 的简要说明 | 
IAM 角色
这些字段指定扩展程序所需的 Cloud IAM 角色。为扩展程序预配的服务账号将被授予这些角色。
您只能指定某个受支持的角色。
roles:
  - role: product.role
    reason: Explanation of why the extension needs this level of access
  - role: anotherproduct.role
    resource: projects/${project_id}/resource_type/*
    reason: Explanation of why the extension needs this level of access
| 角色相关字段 | |
|---|---|
| role字符串 (必填) | 运行扩展程序所需的 IAM 角色的名称 必须是某个受支持的角色 | 
| reason字符串 (必填) | 有关扩展程序为何需要此角色授予的访问权限的简要说明 | 
| resource字符串 (选填) | 将角色权限范围限定在此资源。 如果省略,则默认为  | 
外部服务
这些字段指定扩展程序使用的非 Firebase 及非 Google 服务(通常是 REST API)。Firebase Extensions 平台不会提供任何自动启用这些服务或是为它们执行授权的方法。
externalServices:
  - name: Example API
    pricingUri: https://developers.example.com/pricing
  - name: Another Example API
    pricingUri: https://developers.example.com/pricing
| 外部服务相关字段 | |
|---|---|
| name字符串 (必填) | 运行扩展程序所需的外部服务的名称 | 
| pricingUri字符串 (必填) | 可访问服务价格信息的 URI | 
用户可配置的参数
这些字段定义了扩展程序可供用户配置的参数。
params:
  - param: PARAM_ID
    label: Short description of the parameter
    description: >-
      What do you want to set PARAM_ID to?
      This is a longer description of the parameter, often phrased as a prompt
      to the user.
  - param: ANOTHER_PARAM_ID
    label: Short description of the parameter
    description: >
      What do you want to set ANOTHER_PARAM_ID to?
      This is a longer description of the parameter.
    example: example-input
    validationRegex: "^[a-zA-Z][a-zA-Z-]*[a-zA-Z]?$"
    validationErrorMessage:
      Must be a hyphen-delimited string of alphabetic characters
    default: default-value
    required: false
    immutable: true
| 参数相关字段 | |
|---|---|
| param字符串 (必填) | 参数的名称。您可以在代码中使用此名称来引用参数值。 | 
| label字符串 (必填) | 参数的简短说明。当系统提示用户输入参数值时向用户显示。 | 
| description字符串 (选填) | 参数的详细说明。当系统提示用户输入参数值时向用户显示。 支持 Markdown。 | 
| example字符串 (选填) | 参数的示例值。 | 
| default字符串 (选填) | 用户将参数的值留空时该参数的默认值。 | 
| validationRegex字符串 (选填) | 用于验证参数的用户配置值的正则表达式。Google RE2 语法。 | 
| validationErrorMessage字符串 (选填) | 正则表达式验证失败时显示的错误消息。 | 
| required布尔值 (选填) | 定义当系统提示用户输入参数值时,用户是否可以提交空字符串。默认为 true。 | 
| immutable布尔值 (选填) | 定义用户能否在安装后更改参数值(例如,如果用户重新配置扩展程序)。默认为  注意:如果您要为已部署的扩展程序函数定义“location”参数,请将此字段设为  | 
| type字符串 (选填) | 参数类型。特殊参数类型可能有额外的要求或是有不同的界面呈现方式。详情请参阅以下各部分。 | 
可选择的参数和可多选的参数
可选择的参数和可多选的参数会提示用户从预定义的选项列表中进行选择。
params:
  - param: PARAM_ID
    label: Short description of the parameter
    description: >-
      Do you want to enable the option?
    type: select
    options:
      - label: Yes
        value: true
      - label: No
        value: false
  - param: ANOTHER_PARAM_ID
    label: Short description of the parameter
    description: >-
      Which options do you want to enable?
    type: multiSelect
    options:
      - value: red
      - value: green
      - value: blue
| 参数选择相关字段 | |||||||
|---|---|---|---|---|---|---|---|
| type字符串 | 
 指定该参数可以是从一组预定义的选项中选择的一个值 ( | ||||||
| options选项列表 (必填) | 可供用户选择的选项 
 | ||||||
可选择的资源参数
可选择的资源参数会提示用户从其项目中选择资源(数据库实例、存储桶等)。
params:
  - param: PARAM_ID
    label: Short description of the parameter
    description: >-
      Which resource do you want to use?
    type: selectresource
    resourceType: product.googleapis.com/ResourceType
| 资源参数相关字段 | |
|---|---|
| type字符串 | 
 指定参数代表项目资源 | 
| resourceType字符串 (必填) | 提示用户选择的资源类型。 有效值: 
 不过,目前只有 Cloud Storage 存储桶有专用选择界面(其他资源类型显示为自由格式文本输入字段)。 | 
Secret 参数
用户提供的 Secret 值(例如 API 密钥)的处理方式有所不同:
- Secret 值使用 Cloud Secret Manager 进行存储。只有已获授权的客户端(例如已安装的扩展程序实例)才能访问这些值。
- 当系统提示用户提供这些值时,他们的输入不会显示出来。
params:
  - param: PARAM_ID
    label: Short description of the parameter
    description: >-
      What is the secret value?
    type: secret
| Secret 参数相关字段 | |
|---|---|
| type字符串 | 
 指定参数是 Secret 值 | 
Cloud Functions 函数资源
这些字段声明扩展程序中包含的 Cloud Functions 函数。第 1 代和第 2 代函数的资源声明语法看起来略有不同,但它们可以在一个扩展程序中共存。
第 1 代 Cloud Functions 函数
resources:
  - name: functionName
    type: firebaseextensions.v1beta.function
    description: >-
      Description of what the function does. (One or two
      sentences.)
    properties:
      runtime: runtime-version
      eventTrigger:
        eventType: google.product.event
        resource: projects/_/resource/specifier
| 资源相关字段 | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| name字符串 (必填) | 导出的函数的易记名称。 如果您未指定  已部署函数的最终名称将采用以下格式: | ||||||||||||||||
| type字符串 (必填) | 对于第 1 代函数资源: firebaseextensions.v1beta.function | ||||||||||||||||
| description字符串 (必填) | 简要说明函数对扩展程序执行的任务。 | ||||||||||||||||
| properties(必填) | 第 1 代 Cloud Functions 函数的属性。下面列出了一些最重要的属性,不过,您也可以在 Cloud Functions 参考文档中找到完整列表。 
 | ||||||||||||||||
第 2 代 Cloud Functions 函数
resources:
  - name: functionName
    type: firebaseextensions.v1beta.v2function
    description: >-
      Description of what the function does. (One or two
      sentences.)
    properties:
      buildConfig:
        runtime: nodejs16
      serviceConfig:
        availableMemory: 512M
      eventTrigger:
        eventType: google.firebase.firebasealerts.alerts.v1.published
        triggerRegion: global
        eventFilters:
          - attribute: alerttype
            value: crashlytics.newFatalIssue
| 资源相关字段 | |||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| name字符串 (必填) | 导出的函数的易记名称。 如果您未指定  已部署函数的最终名称将采用以下格式: | ||||||||||||||||||||||||||||
| type字符串 (必填) | 对于第 2 代函数资源: firebaseextensions.v1beta.v2function | ||||||||||||||||||||||||||||
| description字符串 (必填) | 简要说明函数对扩展程序执行的任务。 | ||||||||||||||||||||||||||||
| properties(必填) | 第 2 代 Cloud Functions 函数的属性。下面列出了一些最重要的属性,不过,您也可以在 Cloud Functions 参考文档中找到完整列表。 
 此外,还有三个对象类型字段有自己专用的属性: 
 
 
 | ||||||||||||||||||||||||||||
生命周期事件
借助生命周期事件,您可以指定在用户安装、更新或配置扩展程序实例时运行的函数。 请参阅处理扩展程序的生命周期事件。
lifecycleEvents:
  onInstall:
    function: myTaskFunction
    processingMessage: Describes the task being completed
  onUpdate:
    function: myOtherTaskFunction
    processingMessage: Describes the task being completed
  onConfigure:
    function: myOtherTaskFunction
    processingMessage: Describes the task being completed
| 生命周期事件相关字段 | |||||||
|---|---|---|---|---|---|---|---|
| onInstall(选填) | 指定在用户安装扩展程序时运行的函数。 
 | ||||||
| onUpdate(选填) | 指定在用户更新扩展程序时运行的函数。 
 | ||||||
| onConfigure(选填) | 指定在用户重新配置扩展程序时运行的函数。 
 | ||||||
自定义事件 (Eventarc)
自定义事件是您的扩展程序发出的事件,让用户可以将自己的逻辑插入到您的扩展程序中。请参阅向扩展程序添加用户钩子中的 Eventarc 部分。
events:
  - type: publisher-id.extension-name.version.event-name
    description: Description of the event
  - type: publisher-id.extension-name.version.another-event-name
    description: Description of the other event
| 自定义事件相关字段 | |
|---|---|
| type字符串 (必填) | 事件的类型标识符。使用 3-4 个由英文句点分隔的字段来构建标识符:发布商 ID、扩展程序名称和事件名称字段是必选项;另外建议选用版本字段。为您发布的每种事件类型选择一个唯一的描述性事件名称。 | 
| description字符串 (必填) | 事件说明。 |