sta*_*af1 5 javascript node.js google-cloud-platform google-cloud-functions google-secret-manager
我正在使用 Cloud Storage 触发器编写 Firebase 函数。像这样
const functions = require('firebase-functions')
const doSomethingWithSecrets = require('./doSomethingWithSecrets')
const doSomethingWhenUploaded = functions.runWith({
secrets: ["MY_SECRET_1", "MY_SECRET_2", "MY_SECRET_3"]
}).storage.object().onFinalize(o => {
functions.logger.debug([
process.env.MY_SECRET_1 // undefined
process.env.MY_SECRET_2 // undefined
process.env.MY_SECRET_3 // undefined
])
doSomethingWithSecrets(process.env.MY_SECRET_1, process.env.MY_SECRET_2, process.env.MY_SECRET_3)
// Error: Invalid secret.
})
Run Code Online (Sandbox Code Playgroud)
它们三个都返回未定义。我已经确保它们设置正确。它们在使用 Google Cloud Console 时和在 Google Cloud Console 中都会显示firebase functions:secret:accesss MY_SECRET_1。
怎么了?
我以前只用过一个秘密,而且效果很好。我不知道发生了什么,我正在使用 nvm,并且不知道它工作时使用的是哪个 Node 版本,所以这可能是一个线索。
process.env像平常一样返回所有环境,并且我的秘密都没有显示出来。
小智 4
更新您的 firebase-tools,问题就会自行解决。我今天一整天都在处理这个问题,发现了一个 git hub 问题,在最新版本的 10.9.2 中解决了这个问题。
npm install -g firebase-tools
Run Code Online (Sandbox Code Playgroud)
https://github.com/firebase/firebase-tools/issues/4540 https://github.com/firebase/firebase-tools/issues/4459