#env-var #env #file #api-key #name #filename #read

env_file

Reading files with name taken from environment variable

4 releases

Uses old Rust 2015

0.1.3 Feb 1, 2017
0.1.2 Feb 1, 2017
0.1.1 Jan 28, 2017
0.1.0 Jan 28, 2017

#84 in #filename

24 downloads per month

MIT license

5KB
51 lines

This crate helps to read contents of a file with name taken from environment variable.

Build Status

Reading files with name taken from environment variable

Some applications have sensitive data, like API keys, which is unsafe to keep in VCS. One possible solution is keeping secret data in files, taking their names from environment variables. Say, you have to use cloud provider API key to control your PaaS system and you need a key for external data API. You can then run your application like:

$ CLOUD_API_KEY=/etc/secrets/cloud_api.key DATA_API_KEY=/etc/secrets/data_api.key your_app

The same pattern simplifies testing (with test keys and not production ones). It is extendable too: you may have a default location for production use with ability to override it via environment variables.

Usage

Add this to your Cargo.toml:

[dependencies]
env_file = "0.1"

and this to your crate root:

extern crate env_file;

Example

extern crate env_file;

let api_key = read("CLOUD_API_KEY").unwrap_or("default_key".to_string());

No runtime deps