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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! For the authors of configuration loaders and of module settings: the two ways a secret that
//! reaches a module through its configuration is kept out of the reports the graph writes.
//!
//! A loader deserialising configuration runs each deserialisation inside [`collect_secrets`] and
//! registers what it answers with [`CollectedSecrets::register`], so a `Secret<T>` read under
//! `#[serde(flatten)]` or `#[serde(untagged)]`, where no deserializer sees its name, is still
//! redacted (integrations DESIGN §2.3). A module or exporter whose `Module::settings` report a URL
//! writes it through [`setting_url`], so the comparison and the text of `DifferingSettings` carry
//! no credential (DESIGN §8.3).
//!
//! A panic's message is printed by the process's panic hook before ulo catches the panic, and the
//! default hook prints it raw: a registered secret or a connection string's password in the
//! message reaches stderr unredacted, whatever ulo reports of the panic afterwards. An application
//! calling [`install_redacting_hook`](crate::panic::install_redacting_hook) at the start of `main`
//! replaces the default hook with one that prints the message through the secrets the process's
//! apps registered; ulo never replaces the hook itself.
//!
//! Semver applies to this module as to the rest of the crate's public API: from 0.1.0, a change
//! that breaks a caller is released under a new breaking version (`0.x` to `0.(x+1)` before 1.0).
//! A pre-release of 0.1.0 may break it, and Cargo takes a later pre-release of the same version
//! for a requirement on an earlier one, so a crate depending on a pre-release pins it with `=`.
use crateModuleDef;
use crateSecret;
/// `url` as a module setting reports it: its scheme, host, port and path, never its userinfo,
/// query or fragment, and its scheme and `[unreadable]` when it does not read as a scheme and an
/// authority (DESIGN §8.3). Every integration crate whose `settings` report a URL writes it
/// through this, so two settings differing only in a credential compare equal and neither is
/// printed.
///
/// ```
/// use ulo::secrets::setting_url;
///
/// assert_eq!(setting_url("redis://user:pw@cache:6379/2?pass=x#frag"), "redis://cache:6379/2");
/// assert_eq!(setting_url("redis://token/x@cache"), "redis://[unreadable]");
/// ```
/// Runs one synchronous deserialisation with the secret collector open on this thread, answering
/// its value and every secret it produced (integrations §2.3, P6). `ulo-config` installs it around
/// each deserialisation it runs; `Secret<T>: Deserialize`, behind the `serde` feature, writes into
/// it, under `#[serde(flatten)]` and `#[serde(untagged)]` too. A collection open around this one
/// receives nothing of it. Without the `serde` feature nothing writes, and the answer is empty.
/// What it collects is also recorded for the hook
/// [`install_redacting_hook`](crate::panic::install_redacting_hook) installs, so a panic between
/// the load and the app's `wire` prints redacted under it.
/// The secrets one [`collect_secrets`] call recorded: the text of each scalar a `Secret`'s inner
/// value was read from, whatever its type, so a `Secret<T>` whose `T` is not `Display` is
/// recorded by the text it was read from. A value read more than once is recorded once per read;
/// the registry skips a repeat. `Debug` writes the count alone.