Load JSON file's content to Heroku's environment variable Load JSON file's content to Heroku's environment variable heroku heroku

Load JSON file's content to Heroku's environment variable


Depending on which library you are using for communicating with Speach API you may use several approaches:

  1. You may serialize your JSON data using base64 or something similar and set resulting string as one environment variable. Than during you app boot you may decode this data and configure your client library appropriately.

  2. You may set each pair from credentials file as separate env variables and use them accordingly. Maybe library that you're using support authentication using GOOGLE_ACCOUNT_TYPE, GOOGLE_CLIENT_EMAIL and GOOGLE_PRIVATE_KEY similar to the ruby client that you're linking to.

EDIT: Assuming that you are using google official client library, you have several options for authenticating your requests, including that you are using (service account): https://googlecloudplatform.github.io/google-cloud-python/latest/core/auth.html You may save your credentials to the temp file and pass it's path to the Client object https://google-auth.readthedocs.io/en/latest/user-guide.html#service-account-private-key-files (but it seems to me that this is very hacky workaround). There is a couple of other auth options that you may use.

EDIT2:I've found one more link with the more robust approach http://codrspace.com/gargath/using-google-auth-apis-on-heroku/. There is ruby code, but you may do something similar in Python for sure.


Let's say the filename is key.jsonFirst, copy the content of the key.json file and add it to the environment variable, let's say KEY_DATA.

Solution 1:

If my command to start the server is node app.js, I'll do echo $KEY_DATA > key.json && node app.js

This will create a key.json file with the data from KEY_DATA and then start the server.

Solution 2:

Save the data from KEY_DATA env variable in the some variable and then parse it to JSON, so you have the object which you can pass for authentication purposes.

Example in Node.js:

const data = process.env.KEY_DATA;const dataObj = JSON.parse(data);