当前代码正在运行,但在控制台中显示版本为 1... 我该如何使它成为最新
exports.onUserCreate = onDocumentCreated(
{
memory: "1GiB",
document: "users/{id}",
secrets: ["notification_email", "notification_password"],
},
async (event) => {
//...
}
“使用 Cloud Functions(第二代)扩展 Cloud Firestore”或“Cloud Functions 版本比较”中的任何内容都无法解释如何管理机密或如何使用最新版本的机密的行为。
云服务中的常见模式是,当提供不带版本号的资源标识符时,假定为最新版本。
这是为了确保系统使用最新的,因此可能是最安全和最新的配置。
“使用 Cloud Functions 扩展 Cloud Firestore(第二代)”页面没有明确提及如何管理机密或如何使用最新版本的机密的行为。然而,云服务中的常见模式是,当提供不带版本号的资源标识符时,假定为最新版本。这是为了确保系统使用最新的,因此可能是最安全和最新的配置。
在原始代码片段中,您确实通过名称指定秘密(不带版本):
"notification_email"
和"notification_password"
。
exports.onUserCreate = onDocumentCreated(
{
memory: "1GiB",
document: "users/{id}",
secrets: ["notification_email", "notification_password"],
},
async (event) => {
//...
}
)
在没有版本说明符的情况下,云提供商的部署过程将在部署时将最新版本的密钥绑定到函数。
如果您的 Firebase 函数引用的是过时的秘密版本,可能是由于:
在您的云函数中,您可以添加临时日志记录来检查环境变量并确认它们是否具有预期值。
exports.onUserCreate = onDocumentCreated(
{
memory: "1GiB",
document: "users/{id}",
secrets: ["notification_email", "notification_password"],
},
async (event) => {
console.log(process.env.NOTIFICATION_EMAIL);
console.log(process.env.NOTIFICATION_PASSWORD);
//...
}
);
如果您在本地开发环境中遇到此问题,请确保在更新密钥后重新启动本地模拟器或任何本地服务器。本地环境可能会缓存环境变量并需要重新启动才能生效。
如果您的函数在重新部署后仍然不使用最新版本的密钥,则可能是 Firebase Functions(第 2 代)中的错误或限制,正如之前报告的那样。