应用

用法

application: application_name {
  label: "Application Label" 
  url: "application_url" 
  file: "application_file_path" 
  sri_hash: "SRI_hash_value" 
  mount_points: {
    dashboard_vis: yes | no
    dashboard_tile: yes | no
    standalone: yes | no
  }
  entitlements: {
    local_storage: yes | no
    navigation: yes | no
    new_window: yes | no
    new_window_external_urls: ["url1", "url2", ...]
    use_form_submit: yes | no
    use_embeds: yes | no
    use_downloads: yes | no
    use_iframes: yes | no
    use_clipboard: yes | no
    core_api_methods: ["api_method1", "api_method2", ...]
    external_api_urls: ["api_url1", "api_url2", ...]
    oauth2_urls: ["oauth2_url1", "oauth2_url2", ...]
    global_user_attributes: ["user_attribute1", "user_attribute2", ...]
    scoped_user_attributes: ["user_attribute1", "user_attribute2", ...]
  }
}
层次结构
application
默认值

接受
应用及其子参数的名称

特殊规则
application 必须具有 urlfile 参数,但不能同时具有这两个参数

定义

application 参数用于为 Looker 的扩展框架定义应用。将扩展程序添加到项目后,具有相应权限的 Looker 用户可以在 mount_points 参数定义的位置看到该扩展程序。如果未指定 mount_points 参数,则扩展程序会列在 Looker 菜单的应用部分中。

application 参数具有以下子参数:

应用必须具有 url 参数或 file 参数,但不能同时具有这两个参数。

label

指定在主菜单的应用部分中向用户显示的应用的名称。如果您要本地化 LookML 模型,则可以本地化 label

url

url 参数仅用于开发目的,应指向开发者机器上运行的开发服务器。例如:

url: "http://localhost:8080/bundle.js"

开发完成后,您可以将文件拖动到 Looker IDE 中,然后使用 file 参数指向该文件。

file

指定定义应用的 JavaScript 文件(扩展名为 .js)的路径。该路径相对于项目根目录。例如,此 file 参数指向 LookML 项目的 apps 目录中的 bundle.js 文件:

file: "apps/bundle.js"

sri_hash

指定用于 JavaScript 验证的子资源完整性 (SRI) 哈希值。它可以与 fileurl 参数搭配使用。sri_hash 值应包含 sha384- 前缀。

如果 url 指定的是开发服务器,则系统会忽略 sri_hash

mount_points

mount_points 参数用于确定扩展程序在 Looker 界面中的列出位置以及向用户提供的可用性,并确定扩展程序是否会提供自己的数据。旨在在信息中心图块中运行的扩展程序需要指定 mount_points。如果未指定 mount_points,扩展程序将列在 Looker 菜单的应用部分中。允许使用多个 mount_points

参数 说明 示例
dashboard_vis 启用后,该扩展程序将显示在探索的可视化列表中,您可以在其中选择该扩展程序并将其另存为信息中心功能块。当信息中心运行时,信息中心将执行与相应图块关联的查询,并向扩展程序提供数据。这与自定义可视化图表的工作方式类似。自定义可视化图表与在启用了 dashboard_vis 的信息中心图块中运行的扩展程序之间的主要区别在于,扩展程序可以进行 Looker API 调用。 dashboard_vis: yes
dashboard_tile 启用后,当用户修改信息中心并点击添加按钮后选择扩展程序选项时,该扩展程序将显示在扩展程序面板中。此类扩展程序负责检索自己的数据。 dashboard_tile: yes
standalone 指定扩展程序是否会列在 Looker 菜单的应用部分中。如果未指定 mount_points 参数,则扩展程序的默认设置为 standalone: yes standalone: yes

entitlements

entitlements 参数用于指定扩展程序可以访问的资源。除非扩展程序在 entitlements 中列出,否则将无法访问资源。

扩展应用必须指定授权,否则无法运行。

entitlements 参数包含以下子参数。如果未包含某个子形参,则默认情况下,相应扩展程序无权访问该授权。

参数 说明 示例
local_storage 指定扩展程序是否可以访问本地存储空间。 local_storage: yes
navigation 指定扩展程序是否可以在 Looker 中前往其他页面。 navigation: yes
new_window 指定扩展程序是否可以打开新的浏览器窗口或标签页。 new_window: yes
new_window_external_urls 以英文逗号分隔的网址或部分网址列表,扩展程序可以针对这些网址打开新窗口。此授权需要 new_window 授权。您可以添加通配符(例如 *)来表示子网域和路径。 new_window_external_urls: ["https://www.gmail.com"]
use_form_submit 指定扩展程序是否可以提交表单。使用 HTML 表单的 Looker 组件需要 use_form_submit: yes 才能正常运行。 use_form_submit: yes
use_embeds 指定扩展程序是否可以使用 Looker Embed SDK use_embeds: yes
use_downloads 添加于 21.6 指定是否允许扩展程序下载文件。 use_downloads: yes
use_iframes 添加了 21.6 指定扩展程序是否可以创建 iframe。 use_iframes: yes
use_clipboard 添加于 21.8 指定扩展程序是否可以写入系统剪贴板。出于安全考虑,扩展程序不得从系统剪贴板读取内容。 use_clipboard: yes
core_api_methods 扩展程序使用的 Looker API 方法的列表(以英文逗号分隔)。 core_api_methods: ["run_inline_query", "lookml_model_explore", "all_lookml_models"]
external_api_urls 扩展程序使用的外部 API 的网址列表(以英文逗号分隔)。如示例所示,您可以添加通配符,例如 *

从 Looker 21.6 开始,直接使用 fetchXHR.open JavaScript 调用(而不是使用 extensionSDK.fetchProxyextensionSDK.serverProxy API 调用)的扩展程序必须在列表中包含相应网址。
external_api_urls: ["http://example.com:3000", "https://*.googleapis.com"]
oauth2_urls 扩展程序用于 OAuth 2.0 身份验证和代码交换的网址列表(以英文逗号分隔)。 oauth2_urls: ["https://accounts.google.com/o/oauth2/v2/auth"]
global_user_attributes 扩展程序使用的以英文逗号分隔的系统级用户属性列表。 global_user_attributes: ["company", "department"]
scoped_user_attributes 扩展程序使用的以英文逗号分隔的扩展程序专用用户属性列表。 scoped_user_attributes: ["first_name", "last_name"]

示例

以下是 Looker 的厨房水槽扩展程序示例的项目清单文件中的 application 参数:

application: kitchensink {
  label: "Kitchen sink"
  url: "http://localhost:8080/bundle.js"
  entitlements: {
    local_storage: yes
    navigation: yes
    new_window: yes
    use_form_submit: yes
    use_embeds: yes
    core_api_methods: ["all_connections","search_folders", "run_inline_query", "me", "all_looks", "run_look"]
    external_api_urls: ["http://127.0.0.1:3000", "http://localhost:3000", "https://∗.googleapis.com", "https://∗.github.com", "https://REPLACE_ME.auth0.com"]
    oauth2_urls: ["https://accounts.google.com/o/oauth2/v2/auth", "https://github.com/login/oauth/authorize", "https://dev-5eqts7im.auth0.com/authorize", "https://dev-5eqts7im.auth0.com/login/oauth/token", "https://github.com/login/oauth/access_token"]
    scoped_user_attributes: ["user_value"]
    global_user_attributes: ["locale"]
  }
}

如需查看其他示例,请参阅 Looker 的扩展程序示例代码库