bbc/config_to_env

Name: config_to_env

Owner: BBC

Description: Take a config file, and load (some of) it into your process environment

Created: 2015-05-31 19:40:07.0

Updated: 2016-08-24 13:04:38.0

Pushed: 2016-08-24 13:06:00.0

Homepage: null

Size: 7

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

config_to_env

Take a json configuration file, and load it into the running process environment variables before anything in your program runs.

Why would you want to use this?

We have a number of applications that use environment variable configuration overrides, but our deployment system uses json file configs. It's useful for us to simply surface the configuration as environment variables as our app loads.

How to use

The api is extremely simple, and mainly works at require time.

You just need to set a couple of constants to enable the config:

JSON_CONFIG = '/path/to/your/file.json'
require 'config_to_env'

This will load the contents of your json file into the environment of the currently running process. A file like this:

{
    "environment": "test",
    "configuration": {
        "aa": "one",
        "bb": "two"
    },
    "secondary_configuration": {
        "cc": "three"
    }
}

Will be loaded into the environment as the following:

ENVIRONMENT: 'test'
CONFIGURATION_AA: 'one'
CONFIGURATION_BB: 'two'
SECONDARY_CONFIGURATION_CC: 'three'

You can optionally specify particular nodes of the json that you want to include:

JSON_CONFIG_NODES = ['environment', 'configuration']

Which would give you:

ENVIRONMENT: 'test'
AA: 'one'
BB: 'two'

The secondary configuration is dropped entirely.

License

config_to_env is available to everyone under the terms of the MIT open source licence. Take a look at the LICENSE file in the code.

Copyright (c) 2015 BBC


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.