Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-line config variables in Heroku

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

like image 727
Eddie Johnston Avatar asked Aug 04 '11 13:08

Eddie Johnston


People also ask

Are Heroku config vars strings?

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.

Can Heroku access environment variables?

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.

Should I push .env to Heroku?

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 .


2 Answers

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" 
like image 163
danmayer Avatar answered Oct 01 '22 14:10

danmayer


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 
like image 21
Judy2K Avatar answered Oct 01 '22 14:10

Judy2K