I've have a Rails app that loads a number of RSA certificates before a transaction is made with Paypal. On my development machine, these certificates are read from files in the file system but because Heroku (which I'm using for delpoyment) is largely read-only, I can't upload these files so I'm guessing I'll have to read the certificates from config variables (see Heroku Config Vars).
Because the certificates consist of multiple lines of data, I'm not sure how to set them as variables or even if this is possible. Does anyone know how I could do this or be able to suggest an alternative approach?
Many thanks, Eddie
All heroku config vars will be environment variables, which, in linux environments, can only be strings. So all your variables will be strings once in your app.
You need to set the environment variables for your application on Heroku. There are two ways to do it, and in this article, you can see both! The environment variables are called config variables (config vars) on Heroku. As a result, the terms will be used interchangeably in the article.
env file on Heroku isn't a good approach. Instead, you can use its built-in support for environment variables, using heroku config:set <var> <value> or its web UI. Either way, you'll get a regular environment variable. But for testing these config vars in local, we need to set up a .
I found that a easy way to add multi-line configs is to double quote them and then echo them from my local environment
heroku config:add EC2_PRIVATE_KEY="$EC2_PRIVATE_KEY"
If you want to set Heroku config values from your file contents, you can use the following shell trick:
$ heroku config:set SECRET_KEY="$(cat path/to/secret.key)"
Multi-line values can be set directly by putting quotes around the value:
$ heroku config:set SECRET_KEY='first line > second line'
If you're using Foreman to run locally (now heroku local
), it doesn't support multi-line variables. You must use something to inject them into the environment first, such as envdir:
$ envdir my-env-dir heroku local
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With