config-secret
config-secret
is an additional source for the config crate that follows the Docker/Kubernetes convention.
It allows to inject some parts of your configuration by using a file specified as environment variable. See examples.
Installation
[]
= "0.13"
= "0.1.0"
Usage
use Config;
use EnvironmentSecretFile;
let source = with_prefix.separator;
let config = builder.add_source.build.unwrap;
let settings = config..unwrap;
// settings...
Examples
Definition
Let's introduce our types and our config
initializer:
use ;
use EnvironmentSecretFile;
use Deserialize;
Full configuration
We can add an environment variable to set a secret that configure the whole configuration:
APP_FILE=/run/secrets/my_secret.json
let settings = get_settings.unwrap;
assert!;
Partial configuration
We can add environments variables that set only a sub section of your configuration:
APP_SERVER_HOST=127.0.0.1
APP_SERVER_PORT=5000
APP_REDIS_FILE=/run/secrets/redis.yaml
nodes:
- redis://10.0.0.1:6379
- redis://10.0.0.2:6379
- redis://10.0.0.3:6379
username: redis
password: superpassword
let settings = get_settings.unwrap;
assert!;
assert!;