Skip to content

Simple rust crate to read contents of file specified in environment variable

License

Notifications You must be signed in to change notification settings

serejkus/env_file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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());

About

Simple rust crate to read contents of file specified in environment variable

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages