英文:
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
}
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论