gpt4 book ai didi

javascript - 安排 Firebase 身份验证 :export to bucket using pubsub

转载 作者:行者123 更新时间:2023-12-04 14:59:01 25 4
gpt4 key购买 nike

我正在尝试安排 firebase auth:export使用 pubsub 放入存储桶。我的目的是每天备份 auth(firebase auth:export 的输出非常适合我的目的)。
这是我试过的pubsub:

const functions = require('firebase-functions')
const exec = require("child_process").exec

const datetime = new Date();
const formattedDate = datetime.toISOString().slice(0,10)

const commandString = `firebase auth:export auth_export_${formattedDate}.json --format=JSON && \
gsutil -m cp -r auth_export_${formattedDate}.json gs://backup_firebase_auth_daily && \
rm auth_export_${formattedDate}.json`

exports.scheduledFirebaseAuthExport = functions.pubsub
.schedule('every 24 hours')
.onRun(() => {
return exec(commandString, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
process.exit();
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
process.exit();
return;
}
console.log(stdout);
process.exit();
});
});
但我收到以下错误: /bin/sh: 1: firebase: not found我假设这是因为我无法在运行 pubsub 的任何环境中运行命令行脚本。
欢迎使用任何其他使用 Google Cloud API 或 firebase 备份 firebase auth 的方法。

最佳答案

I'm assuming this is because I cannot run command line scripts inwhatever environment the pubsub is run.


实际上,您无法在 Cloud Function 中执行命令行脚本(Firebase CLI 命令或 gsutil 命令),这是运行代码的“环境”(此处的 Pub/Sub 是 mechanism that triggers Cloud Function)。

另一方面,由于“Firebase CLI 也可以以编程方式用作标准节点模块”,如 here 所述。 ,
您可以执行 一些 通过 Cloud Functions 执行 CLI 命令。
请注意,上面的“一些”这个词是粗体的,因为,正如在同一个 Github 页面中所解释的:

Note: when used in a limited environment like Cloud Functions, not allfirebase-tools commands will work programmatically because they requireaccess to a local filesystem.

auth:export 正是这种情况。命令“将事件项目的用户帐户 导出到 JSON 或 CSV 文件 ”。
因此,不幸的是,无法通过 Cloud Function 自动执行此命令。

Any other ways to get backup of firebase auth using Google Cloud API’sor firebase would be welcome.


一种方法是使用 Admin SDK:您可以 retrieve the entire list of users in batches并将其存储在 protected Firestore 集合(或任何其他存储解决方案)中。这可以从云函数(例如 scheduled Cloud Function)或从您拥有的运行 Node.js、Java、Python 等的服务器触发。

关于javascript - 安排 Firebase 身份验证 :export to bucket using pubsub,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67330899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com