Created
May 12, 2019 01:23
-
-
Save patmigliaccio/ebba7d96fec82f595855e1c0b4415320 to your computer and use it in GitHub Desktop.
Adds secret keys from local JSON files as Base64 to `now` secrets.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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