設定和安全性參考資料

Firebase CLI 可讓您在可控管版本的本機專案目錄中管理 Firebase 專案。包括專案中的服務、這些服務的連接器,以及每個連接器的結構定義、查詢和變動來源等資源。Data Connect您也可以使用 CLI 安裝及操作 Firebase Data Connect 模擬器。與 Firebase 控制台相比,CLI 是更有效率的替代方案。

如要瞭解如何安裝 Private Preview 計畫的 Firebase CLI 實驗,以及 Data Connect 相關的 CLI 指令,請參閱 CLI 參考資料

本參考指南記錄了下列事項:

  • firebase.json 專案設定檔中的 Data Connect 專用項目。
  • dataconnect.yamlconnector.yaml 中的 Data Connect 設定。
  • 您需要為使用 Data Connect 的專案設定 IAM 角色。

Firebase 專案設定檔

firebase.json 設定參考資料

使用 dataconnect 鍵在專案中設定一或多個 Data Connect 服務。

dataconnect: {
   source: string // Path to the directory containing the dataconnect.yaml service file.
}

dataconnect.yaml 設定參考資料

dataconnect.yaml 檔案會儲存應用程式結構定義來源、連接器來源和資料來源連線資訊的位置相關設定資訊。這個檔案也會做為 Firebase CLI 的專案目錄標示符。

schemaValidation 鍵可控制在部署期間遷移結構定義時執行的結構定義驗證層級。如果未設定任何值,dataconect:sql:migrate 指令的行為是套用相容的變更,並在執行任何嚴格變更前提示您。設定後,系統會出現以下行為:

  • STRICT 模式。資料庫結構定義必須與應用程式結構定義完全相符,才能部署應用程式結構定義。資料庫會刪除 Data Connect 結構定義中未使用的任何表格或資料欄。
  • COMPATIBLE 模式。資料庫結構定義必須與應用程式結構定義相容,應用程式結構定義才能部署;任何額外變更都視為選用。相容表示結構定義遷移作業是根據您編寫的應用程式結構定義進行。應用程式結構定義未使用的資料庫元素不會修改。因此,部署後端時,可能會包含未使用的結構定義、資料表和資料欄。

這個檔案中其他鍵的值會在下方的註解中說明。

# The top-level Firebase Data Connect YAML file.

# The Firebase Data Connect API version to target.
# Optional. Defaults to the latest version.
specVersion: string

# The ID of the Firebase Data Connect service resource.
# Required.
serviceId: string

# The location of the Firebase Data Connect service.
# Required.
location: string

# Required.
schema:
  # Relative path to directory for schema definitions.
  # Recursively loads all .gql files in this directory.
  # Optional. If not present, defaults to ./schema.
  source: string
  # Datasource connection information.
  # Required.
  datasource:
    # Required.
    postgresql:
      # The name of the PostgreSQL database.
      # Required.
      database: string
      cloudSql:
        # The ID of the CloudSQL instance resource.
        # Required.
        instanceId: string
        # Schema validation mode for schema migrations.
        # Defaults to unspecified/commented out, meaning you are prompted to
        # review all changes during migration.
        # If desired, uncomment and indicate one of "STRICT" or "COMPATIBLE".
        schemaValidation: string

# Required.
# Relative paths to directories for connector definitions.
# Recursively loads all .gql files in the listed directories.
# All directories specified MUST contain a connector.yaml file.
connectorDirs: [string]

YAML 檔案會採用預設 (但可設定) 的目錄結構:

./(project root)
   /dataconnect
      dataconnect.yaml
      /schema
        *.gql
      /connector
        connector.yaml
        *.gql

connector.yaml 設定參考資料

使用 connector.yaml 設定預設驗證模式和 SDK 產生選項。

# The connector-level YAML file.

# Required. The connector name of the Firebase Data Connect connector resource.
connectorId: string

# Optional. If not specified, no generated libraries (i.e. type-safe SDKs) will be generated.
generate:
    # Optional.
    javascriptSdk:
        # Path to the directory that will be updated with the latest generated
        # web SDK.
        # Required.
      - outputDir: string
        # Path to your package.json directory. If specified, the new generated sdk will be installed in this path.
        # Optional. If not provided, the package will not be auto-installed for you.
      - packageJsonDir: string
        # Name of the package to be created.
        # Optional. Defaults to @firebasegen/<connectorID>
      - package: string
        <option>: string
    # Optional.
    swiftSdk:
        # Path to the directory that will be updated with the latest generated
        # iOS Swift SDK.
        # Required.
      - outputDir: string
        # Name of the package to be created.
      - package: string
        <option>: string
    # Optional.
    kotlinSdk:
        # Path to the directory that will be updated with the latest generated
        # Android SDK.
        # Required.
      - outputDir: string
        # Name of the package to be created.
      - package: string
        <option>: string

資料連線專案的 IAM 設定

Data Connect 的精細 IAM 角色

Firebase 基本角色和預先定義角色會對應至較低層級的Data Connect角色。如需對應關係,請參閱下表。

如要以更精細的層級管理 Data Connect 的個別 IAM 角色指派,請使用 Google Cloud 控制台

IAM 角色 權限
firebasedataconnect.googleapis.com/admin

Firebase Data Connect API 管理員

這個角色包含 Firebase Data Connect API 檢視者。
這相當於 firebasedataconnect.*

Cloud 擁有者、Cloud 編輯者、
Firebase 管理員和 Firebase 開發管理員角色都具備此權限。
具備 Firebase Data Connect API 資源 (包括資料) 的完整存取權。

firebasedataconnect.googleapis.com/operations.delete
firebasedataconnect.googleapis.com/operations.cancel
firebasedataconnect.googleapis.com/services.create
firebasedataconnect.googleapis.com/services.update
firebasedataconnect.googleapis.com/services.delete
firebasedataconnect.googleapis.com/services.executeGraphql
firebasedataconnect.googleapis.com/services.executeGraphqlRead
firebasedataconnect.googleapis.com/schemas.create
firebasedataconnect.googleapis.com/schemas.update
firebasedataconnect.googleapis.com/schemas.delete
firebasedataconnect.googleapis.com/schemaRevisions.create
firebasedataconnect.googleapis.com/schemaRevisions.delete
firebasedataconnect.googleapis.com/connectors.create
firebasedataconnect.googleapis.com/connectors.update
firebasedataconnect.googleapis.com/connectors.delete
firebasedataconnect.googleapis.com/connectorRevisions.create
firebasedataconnect.googleapis.com/connectorRevisions.delete
firebasedataconnect.googleapis.com/viewer

Firebase Data Connect API 檢視者

這項角色由 Cloud Owner、Cloud Editor、
Cloud Viewer、Firebase 管理員、Firebase 檢視者、
Firebase 開發管理員和 Firebase 開發檢視者提供。
具備 Firebase Data Connect API 資源的唯讀存取權,不過無法存取資料。

cloudresourcemanager.googleapis.com/projects.list
cloudresourcemanager.googleapis.com/projects.get

firebasedataconnect.googleapis.com/operations.list
firebasedataconnect.googleapis.com/operations.get
firebasedataconnect.googleapis.com/locations.list
firebasedataconnect.googleapis.com/locations.get
firebasedataconnect.googleapis.com/services.list
firebasedataconnect.googleapis.com/services.get
firebasedataconnect.googleapis.com/schemas.list
firebasedataconnect.googleapis.com/schemas.get
firebasedataconnect.googleapis.com/schemaRevisions.list
firebasedataconnect.googleapis.com/schemaRevisions.get
firebasedataconnect.googleapis.com/connectors.list
firebasedataconnect.googleapis.com/connectors.get
firebasedataconnect.googleapis.com/connectorRevisions.list
firebasedataconnect.googleapis.com/connectorRevisions.get
firebasedataconnect.googleapis.com/dataAdmin

Firebase Data Connect API 資料管理員

由雲端擁有者、雲端編輯者、Firebase 管理員和 Firebase 開發管理員角色提供。
具備資料來源的完整讀寫權限。

firebasedataconnect.googleapis.com/services.executeGraphql
firebasedataconnect.googleapis.com/services.executeGraphqlRead
firebasedataconnect.googleapis.com/dataViewer

Firebase Data Connect API 資料檢視者

這項角色由雲端擁有者、雲端編輯者、
Firebase 管理員和 Firebase 開發管理員提供。
具備資料來源的唯讀存取權。

firebasedataconnect.googleapis.com/services.executeGraphqlRead