I am hoping to achieve to update firebase functions config (env variables) programatically other than manually typing firebase functions:config:set
I want to automate this process depending on the returned value from a post call inside the function and possibly invoke cloud run to achieve this.
I've tried below but only worked in local env.
const { exec } = require("child_process");
exports = module.exports = functions.https.onRequest(async (req, res) => {
try {
exec(`firebase functions:config:set hello.world="hhh"`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
res.status(200).send({ message: 'success' });
}
catch (e) {
console.log('e :>> ', e);
res.status(400).send({ status: res.statusCode, message: 'aborted' });
}
})
If there's a way to achieve this, I'd like to know.
Also wondering if there's way to achieve this with cloud run.
Thank you.
There's no way to update the environment while a function is running. It requires a full redeploy from the CLI.
As of June 2022, this is actually possible, using the firebase-functions-test
package.
For more information: https://firebase.google.com/docs/functions/unit-testing#mocking_config_values
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.