Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function deployConfig(configFile: string, project: string) {
console.log(`Deploying ${configFile} to ${project}.`);
// Read the local JSON file and then wrap it in { runtime: config: { ... } }
const configFileString = fs.readFileSync(configFile).toString();
const config = {
runtime: {
config: JSON.parse(configFileString)
}
};
// Encode the proposed config into a flat map of dot-separated values
const newConfig = encoding.flattenConfig(config, encoding.Direction.ENCODE);
// Get the current runtime config from Firebase as a giant object
const current = await firebase.functions.config.get("runtime", {
project: project
});
// Decode the config into a flat map of dot-separated values.
const currentConfig = encoding.flattenConfig(
{
runtime: current
},
encoding.Direction.NONE
);
const keysRemoved: string[] = [];
const keysAddedOrChanged: string[] = [];
const newKeys = Object.keys(newConfig);
const currentKeys = Object.keys(currentConfig);
const val = newConfig[key];
args.push(`${key}=${val}`);
}
}
// If no changes, we're done
if (args.length == 0) {
console.log("No config changes.");
return;
}
// Log out everything that is changing
console.log(args);
// Set the new config
await firebase.functions.config.set(args, {
project: project
});
}
return Promise.all(filteredPaths.map(path => {
return firebaseTools.functions.config.unset([path], this.firebaseToolsOptions);
})).then(() => pathsString);
}