1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Keeping a credential out of the config file.
//!
//! A config file is the layer most likely to end up in version control, so
//! `#[layered(no_file)]` is the marker that matters for a secret: the field can
//! still come from the environment — the usual channel for credentials — but a
//! `db_password` key in `myapp.toml` can never populate it, even by accident.
//!
//! `#[layered(no_env, no_file)]` narrows a field to the command line alone.
//! Reach for that sparingly: a command-line argument is visible in `ps` output
//! to every other user on the machine, and is recorded in shell history, so it
//! is usually a *worse* place for a secret than the environment.
//!
//! ## Running this example
//!
//! ```bash
//! # The usual channel: read the secret from the environment, without ever
//! # writing its value into a command line or a file.
//! MYAPP_DB_PASSWORD="$DB_PASSWORD" cargo run --example sensitive_data
//!
//! # db_user is read from examples/config.toml as normal...
//! MYAPP_DB_USER=readonly cargo run --example sensitive_data
//!
//! # ...but a `db_password` key in that file is ignored, because the field
//! # opts out of the file layer.
//! ```
use Parser;
use Layered;