All Projects → nsweeting → exenv

nsweeting / exenv

Licence: MIT license
Exenv makes loading environment variables from external sources easy.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to exenv

ini
📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载
Stars: ✭ 72 (+105.71%)
Mutual labels:  config, dotenv, environment-variables, env
goodconf
Transparently load variables from environment or JSON/YAML file.
Stars: ✭ 80 (+128.57%)
Mutual labels:  config, yaml, environment-variables, env
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (+145.71%)
Mutual labels:  config, yaml, environment-variables
Strictyaml
Type-safe YAML parser and validator.
Stars: ✭ 836 (+2288.57%)
Mutual labels:  config, yaml, yml
webpack-dotenv-plugin
Use dotenv with webpack.
Stars: ✭ 53 (+51.43%)
Mutual labels:  dotenv, environment-variables, env
pyaml env
Parse YAML configuration with environment variables in Python
Stars: ✭ 36 (+2.86%)
Mutual labels:  yaml, secrets, environment-variables
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-42.86%)
Mutual labels:  config, yaml, environment-variables
env
A lightweight package for loading OS environment variables into structs for Go projects
Stars: ✭ 24 (-31.43%)
Mutual labels:  config, environment-variables, env
Dynaconf
Configuration Management for Python ⚙
Stars: ✭ 2,082 (+5848.57%)
Mutual labels:  config, yaml, environment-variables
Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+5200%)
Mutual labels:  config, environment-variables, env
dotenvy
Speed up your production sites by ditching .env for key/value variable pairs as Apache, Nginx, and shell equivalents
Stars: ✭ 31 (-11.43%)
Mutual labels:  dotenv, environment-variables, env
envfile
Parse and write environment files with Node.js
Stars: ✭ 42 (+20%)
Mutual labels:  dotenv, environment-variables, env
gconfigs
gConfigs - Config and Secret parser
Stars: ✭ 42 (+20%)
Mutual labels:  dotenv, secrets, environment-variables
ts-dotenv
Strongly-typed environment variables for Node.js
Stars: ✭ 18 (-48.57%)
Mutual labels:  dotenv, environment-variables, env
checkdotenv
Verify environment variables presence for Node JS.
Stars: ✭ 12 (-65.71%)
Mutual labels:  dotenv, environment-variables, env
php-env
A small and fast .env loader for PHP
Stars: ✭ 19 (-45.71%)
Mutual labels:  dotenv, environment-variables, env
Mconfig
MCONFIG is a lightweight Golang library for integrating configs files like (json, yml, toml) and environment variables into one config struct.
Stars: ✭ 28 (-20%)
Mutual labels:  config, yaml, environment-variables
read-env
🔧 Transform environment variables into JSON object with sanitized values.
Stars: ✭ 60 (+71.43%)
Mutual labels:  config, environment-variables, env
superconfig
Access environment variables. Also includes presence validation, type coercion and default values.
Stars: ✭ 33 (-5.71%)
Mutual labels:  config, dotenv, environment-variables
dart environment config
Environment specific config generator for Dart and Flutter applications during CI/CD builds
Stars: ✭ 87 (+148.57%)
Mutual labels:  dotenv, environment-variables

Exenv

Build Status Exenv Version

Exenv provides an adapter-based solution to loading environment variables from external sources.

It comes with the following adapter:

  • Exenv.Adapters.Dotenv (load from .env files)

But has support from external adapters as well:

Installation

This package can be installed by adding exenv to your list of dependencies in mix.exs:

def deps do
  [
    {:exenv, "~> 0.3"}
  ]
end

Documentation

Please see HexDocs for additional documentation. This readme provides a brief overview, but it is recommended that the docs are used.

Getting Started

If all you want is to load a .env file on application start - then you're already done! Out of the box, Exenv is configured to start itself with the Exenv.Adapters.Dotenv adapter configured with sane defaults. This means autoloading on application start - with the .env file required to be within your projects root directory.

Configuration

If you need finer grained control of things, Exenv provides extensive config mechansims.

We can pass configuration options to Exenv from application config.

config :exenv, [
  adapters: [
    {Exenv.Adapters.Dotenv, [file: "path/to/.env"]}
  ]
]

You can also run Exenv via your own supervision tree. In this case, you must instruct Exenv not to start itself.

config :exenv, start_on_application: false

Which allows you to add Exenv to your own application.

defmodule MySupervisor do
  use Supervisor

  def start_link(opts) do
    Supervisor.start_link(__MODULE__, :ok, opts)
  end

  def init(:ok) do
    children = [
      {Exenv, [adapters: [{Exenv.Adapters.Dotenv, [file: "path/to/.env"]}]]}
    ]

    Supervisor.init(children, strategy: :one_for_one)
  end
end

Options passed to the child_spec/1 callback take precedence over any application config.

By default, all adapters will autoload their environment vars when Exenv starts up. You can override this behaviour on a per-adapter basis, by simply passing the autoload: false key within your adapter config.

[
  adapters: [
    {Exenv.Adapters.Dotenv, [autoload: false, file: "path/to/.env"]}
  ]
]

You must then manually load all env vars from your defined adapters:

Exenv.load()

Runtime path evaluation

Any location where you pass a file path you can choose to instead pass an mfa which will be run and should evaluate to a proper file path. This allows for easier runtime setup of files.

config :exenv, [
  adapters: [
    {Exenv.Adapters.Dotenv, [file: {MyApp, :get_dotenv, []}]}
  ]
]

Encryption

Exenv has secrets encryption out of the box. Support will depend on the whether the adapter provides it. Using secrets encryption allows you to keep an encrypted version of your secrets checked into your repository. As long as the master key is accessible, these secrets can then be decrypted.

To get started with secrets encryption, first generate a master key.

mix exenv.master_key /config/master.key

This will generate a new master key at /config/master.key. You can then encrypt your secrets file.

mix exenv.encrypt /config/master.key /config/.env

This will encrypt the contents of /config/.env using /config/master.key. A new file will then be generated at /config/.env.enc with your encrypted secrets.

You must then provide the proper options to your adapters to enable encryption.

{Exenv.Adapters.Dotenv, [file: "path/to/.env.enc", encryption: true]}

The above will attempt to decrypt "path/to/.env.enc" using the contents of the "MASTER_KEY" env var. Alternatively, you can also provide a direct path to the master key file.

{Exenv.Adapters.Dotenv, [file: "path/to/.env.enc", encryption: [master_key: "path/to/master.key"]]}

To edit your secrets, you just need to decrypt the original encrypted secrets, and rencrypt the edited file.

mix exenv.decrypt /config/master.key /config/.env.enc

## Add to file

mix exenv.encrypt /config/master.key /config/.env
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].