GithubHelp home page GithubHelp logo

xavdid / heroku-config Goto Github PK

View Code? Open in Web Editor NEW
241.0 4.0 21.0 303 KB

[Utility] Push and pull heroku environment variables to your local env

Home Page: https://www.npmjs.com/package/heroku-config

JavaScript 100.00%
heroku heroku-cli-plugin environment-variables npm

heroku-config's Introduction

heroku-config

npm

Push and pull your Heroku configs to your local environment.

Heavily inspired by ddollar's version, but using the new Heroku cli.

Project Status

This project is in maintenance mode. As Heroku no longer offers a free plan, I no longer use it and won't spend time enriching their ecosystem. That said, this project is mostly feature-complete. It's old and creaky, but has worked consistently for years.

I don't plan on adding any new features at this point, but will accept PRs for bugfixes if anything big comes up.

⚠️ Disclaimer ⚠️

Running this code has the potential to delete your configurations if misused.

Specifically, the -o flag will overwrite values at the destination. Only use that if the source has more up to date info and you're feeling brave. Otherwise, this merges configs and is fairly safe. Just thought you should know.

Also, the -c flag will delete values that didn't exist locally when you pushed. Only use it if you know that.

Usage

You can install the package by running

% heroku plugins:install heroku-config

This package includes two commands:

  • heroku config:pull: Writes the contents of heroku config into a local file
  • heroku config:push: Writes the contents of a local file into heroku config

As of version 1.6.0, the heroku-config supports modifying pipeline config variables with the --pipelie-name and --pipeline-stage flags.

Run heroku help config:pull and heroku help config:push to see a full list of flags.

File Format

There's a lot of flexibility when it comes to how you can format your file. Key capitalization can go either way and there can be spacing around the = on one, both, or neither side. There can also be a leading export if you want to use the same file to populate your local environment. Since Heroku runs on linux, variable names must conform to those valid in unix. If you want to use unsupported characters in your var names, run commands with the -e flag. There's also support both unix and windows-style newlines (though only one type per file).

Multiline variables are fine as long as they're surrounded by "

All of the following are valid lines:

#comment
NODE_ENV= test
source =local
job = programming

DB_STRING=mongo://[email protected]:4567
export THING=3
multiline="this can have
as many lines
# comments are still ignored
as it wants"

The following are all invalid lines:

 # comment with leading space
 bad_key=nono
key with-dash=andspace
multiline='bad because
it uses
single quotes'

Development

You'll need Node version >= 6.0. If you want to match exactly, check out the heroku cli's node version here. I like nvm for managing multiple node versions.

After cloning, follow these instructions to run locally! I welcome pull requests with fixes or new features.

heroku-config's People

Contributors

dependabot[bot] avatar icheko avatar jdx avatar safrmo avatar stereoscott avatar xavdid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

heroku-config's Issues

Test suite fails

I have some legacy apps which have many config variables that are no longer used. I thought a nice feature would be to add a flag to remove unused config variables (that is, config variables that exist on Heroku but that do not exist in the local .env file) when doing a push command.

I forked the repo to create a PR for this, but upon running the test suite, I get an error. Before moving forward, I wanted to check to see if the test suite is current and if this is indicating some config issue on my end.

The output of npm test is:

$ npm test

> [email protected] test /Users/aaron/Documents/projects/heroku-config
> mocha test.js && standard

/Users/aaron/Documents/projects/heroku-config/node_modules/heroku-cli-util/lib/action.js:16
  if (options.then) [options, promise] = [{}, options]
                    ^^^^^^^^^^^^^^^^^^

ReferenceError: Invalid left-hand side in assignment
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/aaron/Documents/projects/heroku-config/node_modules/heroku-cli-util/index.js:11:18)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/aaron/Documents/projects/heroku-config/test.js:20:13)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:20:19)
    at /Users/aaron/Documents/projects/heroku-config/node_modules/mocha/lib/mocha.js:222:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/aaron/Documents/projects/heroku-config/node_modules/mocha/lib/mocha.js:219:14)
    at Mocha.run (/Users/aaron/Documents/projects/heroku-config/node_modules/mocha/lib/mocha.js:487:10)
    at Object.<anonymous> (/Users/aaron/Documents/projects/heroku-config/node_modules/mocha/bin/_mocha:458:18)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:148:18)
    at node.js:405:3
npm ERR! Test failed.  See above for more details.

Plugin is invalid

Installing plugin heroku-config... failed
 ›   Error: plugin is invalid
  • OS: Ubuntu 22.10
  • Heroku CLI version: heroku/8.0.2 linux-x64 node-v16.19.0

Cannot find module 'lodash/array' error

hello, I tried to install heroku-config today, however, occurred this error. I suppose that is missing a dependency:

fabio@luzfcb:~$ heroku plugins:install heroku-config
Installing plugin heroku-config...module.js:442
    throw err;
    ^

Error: Cannot find module 'lodash/array'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/luzfcb/.local/share/heroku/plugins/node_modules/heroku-config/commands/push.js:7:15)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
 !
 ▸    Error installing plugin heroku-config
 !    error installing plugin heroku-config

Line format possibility

Hello and thank you for this useful tool you've built.

I'm using various Python libraries in an application I'm writing that need env vars and I'm using docker-compose env_file directive to pass them to my applications running inside the containers. Problem is, since the line formatting of the pull command is set in stone (https://github.com/xavdid/heroku-config/blob/master/util/file.js#L16), some libraries include the additional " into account when building URLs and therefore, their client initialization becomes invalid and it won't work. Is it possible that you add a flag or a mechanism, however you see fit, to write to the env file using this format instead:

heroku config:pull --unquoted ==> KEY=VALUE
heroku config:pull ==> KEY="VALUE"

Odd behavior when performing config:push relating to newlines

Something weird happens with newlines when I push these .env files.

DISCORDTOKEN=foo
LOGLEVEL=20
HSAPI=bar

When I push this, the DISCORDTOKEN and LOGLEVEL lines will not be parsed correctly, but HSAPI will.

DISCORDTOKEN=foo
HSAPI=bar
LOGLEVEL=20

When I push this, the DISCORDTOKEN and HSAPI lines will not be parsed correctly, but LOGLEVEL will.

DISCORDTOKEN=foo
LOGLEVEL=20
HSAPI=bar

If I add a trailing newline, HSAPI also does not get parsed.

Error Plugin: heroku-config: files attribute must be specified in ..../package.json

Whenever I try to run heroku in the CLI I get this error mesage first - and then the CLI appears to work correctly. I can't actually remember why I installed this plug-in in the first place (possibly to try and get wordpress running on heroku?)

The full error message (appears to be duplicated is):

(node:23569) Error Plugin: heroku-config: files attribute must be specified in /home/charles/.local/share/heroku/node_modules/heroku-config/package.json
module: @oclif/[email protected]
plugin: heroku-config
root: /home/charles/.local/share/heroku/node_modules/heroku-config
See more details with DEBUG=*
(node:23569) Error Plugin: heroku-config: files attribute must be specified in /home/charles/.local/share/heroku/node_modules/heroku-config/package.json
module: @oclif/[email protected]
plugin: heroku-config
root: /home/charles/.local/share/heroku/node_modules/heroku-config
See more details with DEBUG=*

and sure enough there really is no files attribute in the package.json - but I can't see anything in the readme for this package telling me why files is needed and what it should be set to. I am running ubuntu 16.04 LTS. I am getting this error for all heroku CLI commands, including the heroku help ones.

I am using heroku-config vs 1.5.1 and heroku/7.4.11 linux-x64 node-v10.4.1.

Suggestions? Or maybe I should just uninstall heroku-config from my system since I'm not sure what I installed it for in the first place...

New local env are not pushed

If I add new env in the env file and push it again to the same destination, the new value doesn't appear in heroku instance.

ENV=production

then I changed local to

ENV=production
HAPPY=yes

After I push HAPPY does not appear in heroku config

Cannot set multiline environment variables that contain = in the value

I'm trying to configure a certificate as value as follows:

GSHEET_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDI+N9b7PVVq/ab
dcCAC88BQyxIJW4J81OZPvfLDYo4cMaFuvoOti9DZRsCXF0wFOCkex4wWrfxaJ4C
CG5ulmX1FlPAMyonetU5NjC3BfSWiYxcbcld1/55TknkdQ9tWj9ysyL1avlrpvQ1
GoR7RVwJgQ/ey77JS8AkQvrP4yTeUABoF29oA/kLq9Qa/OOic6a3IgtEfoabaBlC
1o7OhY+BFMgSsMTclscUK5HPvZzxsWIvaNYFTcoXfZR0Vpyz+pWYx7ACGcnOIzvo
MtP8z223q+T0DUDfC9yWtuaVyNH/6gYJm1fdC+409faTrDNYQBcHyU4XbuCySR3K
igcCzA9/PGqMEFGN+lLB/j9paqygvDl+2CxjVQwOyhGScLEJD3q1lm/eK4Dwsxiw
YXDcm0CbDiChl6C7DCYJl6Fmre6O934k/IbTGETMzv0W9JpWwMNhDkPGaDo5b4Dx
nt5UVjMc9CGCcAksW4gsCQ==
-----END PRIVATE KEY-----"

However it fails on the == at the end of the value...

multiline environment variables

Currently I can export out a multiline environment variable with config:push and it shows up in the .env file as

MY_SECRET_KEY="-----BEGIN RSA PRIVATE KEY-----
MIIrandomtext
morerandomtext
-----END RSA PRIVATE KEY-----"

However importing that does not work it only imports the first line and throws warning while parsing the rest.

Currently I can only set them directly using the config:set like this.

heroku config:set MY_SECRET_KEY="$(cat mysecretkey.pem)" -a my-heroku-app

Allow Dot (".") in property name

I am configuring the deployment of a java spring based project in Heroku. The naming convention of the properties in our existing project is "x.y.z". Ex: integration.postmark.url. Currently the plugin is throwing error: unable to parse the properties which has a "." in the name. I have cloned the repo and updated the regex to allow it (attached file). I have linked the plugin in local with updated code and it is working.

Is it possible to include the change in next version?

file.js.txt

Wont work if there is a space before or after the = sign

Great plugin! This saved me a lot of time.

However I found an issue. The plugin wont upload the .env file if an ENV var has a space has spaces before or after the equal

  • 🚫 MY_ENV_VAR = XYZ
  • 🚫 MY_ENV_VAR= XYZ
  • 🚫 MY_ENV_VAR =XYZ
  • MY_ENV_VAR=XYZ

The tool returns Successfully wrote settings to Heroku! in all cases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.