Google Secrets in Firebase Function V2 Document Trigger

huangapple go评论71阅读模式
英文:

Google Secrets in Firebase Function V2 Document Trigger

问题

关于如何在文档触发函数中包含Google Secrets Manager,我有一个关于Firebase Functions V2的问题。

我知道如何在OnRequest中做到这一点,下面的代码可以正常工作:

exports.myWebhook = onRequest({secrets: [MY_WEBHOOK_SECRET, MY_TEST_SECRET_KEY]}, async (req, res) => {
    const safe = STRIPE_TEST_SECRET_KEY.value();
}

然而,我似乎无法在onDocumentCreated中使其工作...

exports.myUpdate = onDocumentCreated("/orders/{documentId}", async (event ) => {
    const myAPIKey = MY_OTHER_API.value()
}

无论我在此函数的任何位置放置{secrets: [MY_OTHER_API]},都会创建一个错误。如果我排除它,那么API密钥的值就为空。

如果有帮助,将{secrets: [MY_OTHER_API_KEY]}放入函数中以允许它访问Google Secret值。

英文:

I have a question about Firebase Functions V2, with regards to how to include Google Secrets Manager into the document trigger function.

I know how to do it with OnRequest, the below works fine.

exports.myWebhook = onRequest({secrets: [MY_WEBHOOK_SECRET, MY_TEST_SECRET_KEY]}, async (req, res) => {
    const safe = STRIPE_TEST_SECRET_KEY.value();
}

However I can't seem to get it to work with onDocumentCreated...

exports.myUpdate = onDocumentCreated("/orders/{documentId}", async (event ) => {
 const myAPIKey = MY_OTHER_API.value()
}

Any time I place {secrets: [MY_OTHER_API]} anywhere in this function, it creates an error. If I exclude it then the API key value is just blank.

Any help would be appreciated. Thanks.

Tried placing {secrets: [MY_OTHER_API_KEY]} into the function to allow it access to the Google Secret value.

答案1

得分: 9

根据API参考,第一个参数可以是文档路径或firestore.DocumentOptions对象(它扩展了GlobalOptions,其中定义了secrets):

exports.myUpdate = onDocumentCreated(
  {
    document: "/orders/{documentId}",
    secrets: [MY_OTHER_API]
  },
  async (event) => {
    const myAPIKey = MY_OTHER_API.value()
    // 其他步骤
  }
)
英文:

Per the API reference, the first parameter is either a document path or a firestore.DocumentOptions object (which extends GlobalOptions where secrets is defined):

exports.myUpdate = onDocumentCreated(
  {
    document: "/orders/{documentId}",
    secrets: [MY_OTHER_API]
  },
  async (event) => {
    const myAPIKey = MY_OTHER_API.value()
    // other steps
  }
)

huangapple
  • 本文由 发表于 2023年5月30日 07:50:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76360867.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定