【问题标题】:How can I integrate a credential json file with GCP bigquery with nodejs?如何将凭证 json 文件与 GCP bigquery 与 nodejs 集成?
【发布时间】:2021-03-24 12:42:10
【问题描述】:

我有一个 json 文件类型。它是一个凭证文件。我想与GCP bigquery 集成并使用此凭据文件和Nodejs 访问GCP bigquery

我该怎么做? 如何在 nodejs 中使用凭证文件与GCP bigquery 集成? 如何测试集成结果以测试集成是否有效?

【问题讨论】:

标签: node.js google-cloud-platform google-bigquery


【解决方案1】:

你可能想要keyFilename 属性,除非我误解了你的问题。

This GCP doc 谈论使用服务帐户密钥文件进行身份验证。

因此,如果您的凭据文件位于 /var/my_credentials.json(无意义的路径)中,您的 Node.js 代码将如下所示:

const {BigQuery} = require('@google-cloud/bigquery');

const options = {
  keyFilename: '/var/my_credentials.json',
  projectId: 'my_project',
};

const bigquery = new BigQuery(options);

另外考虑:将该凭证文件的内容保存在 Google Secret Manager 中并使用 gcloud secrets versions access latest,将输出转储到脚本本地的临时 json 文件中,然后在脚本不再需要临时 json 文件后删除它.无需在服务器上浮动凭据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    • 2019-01-04
    • 2021-12-24
    • 2023-03-16
    • 2018-11-14
    • 1970-01-01
    相关资源
    最近更新 更多