Multi-line config variables in Heroku

前端 未结 6 1059
别那么骄傲
别那么骄傲 2020-12-08 00:29

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

相关标签:
6条回答
  • 2020-12-08 00:35

    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"
    
    0 讨论(0)
  • 2020-12-08 00:43

    My answer comes a bit late but I had the same issue recently with multi-line env. variables on Heroku. My solution was to use strict_encode64:

    encoded_secret = Base64.strict_encode64("my_multi_line_secret")
    

    add the key:

    $ heroku config:set SECRET_KEY='the encoded_secret string here'
    

    In the code, you then decode it using Base64.strict_decode64(ENV['SECRET_KEY'])

    0 讨论(0)
  • 2020-12-08 00:49

    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
    
    0 讨论(0)
  • 2020-12-08 00:54

    Or you can just go to the Settings tab of the Heroku dashboard, open Config Vars and paste it in.

    Easy peasy.

    0 讨论(0)
  • 2020-12-08 00:57

    We needed to do the same thing.

    You can wrap the variable value in double quotes:

    bobvila@bobuntu:~/svnroot/app/myapp$ heroku config:add woodchuck="How much wood
    > could a woodchuck chuck
    > if a woodchuck could chuck wood"
    Adding config vars and restarting myapp... done, v25
    woodchuck: How much wood
    could a woodchuck chuck
    if a woodchuck could chuck wood
    bobvila@bobuntu:~/svnroot/app/myapp$ heroku config
    === Config Vars for myapp
    woodchuck:                       How much wood
    could a woodchuck chuck
    if a woodchuck could chuck wood
    bobvila@bobuntu:~/svnroot/app/myapp$ 
    

    If you're using Foreman for localhost development, the .env file doesn't support multi-line variables so you'll need to export it to the shell before launching Foreman

    0 讨论(0)
  • 2020-12-08 01:00

    An example of how to deal with this problem using NodeJS. Sanitize the value by replacing \\n characters with \n:

    process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n')
    

    Taken from: Escaping issue with firebase privateKey as a Heroku config variable

    0 讨论(0)
提交回复
热议问题