Skip to content

Instantly share code, notes, and snippets.

@patmigliaccio
Created May 12, 2019 01:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patmigliaccio/ebba7d96fec82f595855e1c0b4415320 to your computer and use it in GitHub Desktop.
Save patmigliaccio/ebba7d96fec82f595855e1c0b4415320 to your computer and use it in GitHub Desktop.
Adds secret keys from local JSON files as Base64 to `now` secrets.
const fs = require('fs');
const GOOGLE_APPLICATION_CREDENTIALS = 'keys/google_application_credentials.json';
/**
* Adds secret keys from local JSON files as Base64 to `now` secrets.
*
* e.g. `node now-secrets-json.js'
*/
function main() {
const encodedKey = btoa(fs.readFileSync(GOOGLE_APPLICATION_CREDENTIALS));
const exec = require('child_process').exec;
exec(`now secret add google_application_credentials_data ${encodedKey}`, function callback(error, stdout, stderr){
if (error) {
throw error;
}
console.log(stdout);
});
}
main();
/**
* Converts a string into Base64.
*
* @param {string} str
* @returns {string}
*/
function btoa(str) {
if (Buffer.byteLength(str) !== str.length)
throw new Error('bad string!');
return Buffer(str, 'binary').toString('base64');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment