-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmod.rs
109 lines (99 loc) · 3.27 KB
/
mod.rs
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
99
100
101
102
103
104
105
106
107
108
109
//! Agent configuration (logging, intervals, addresses, etc).
//!
//! All structs defined in this module include public data only. The real agent
//! settings blocks are separate/different from these {Agent}Config blocks and
//! can contain signers. Functionality of these config blocks is minimized to
//! just the data itself.
mod logging;
pub use logging::*;
mod signer;
pub use signer::*;
pub mod kathy;
pub mod processor;
pub mod relayer;
pub mod updater;
pub mod watcher;
use std::path::PathBuf;
use self::{
kathy::KathyConfig, processor::ProcessorConfig, relayer::RelayerConfig, updater::UpdaterConfig,
watcher::WatcherConfig,
};
/// Full agent configuration
#[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgentConfig {
/// RPC specifier
pub rpc_style: RpcStyles,
/// Path to the DB
pub db: PathBuf,
/// Metrics port
pub metrics: Option<u16>,
/// Logging configuration
pub logging: LogConfig,
/// Updater configuration
pub updater: UpdaterConfig,
/// Relayer configuration
pub relayer: RelayerConfig,
/// Processor configuration
pub processor: ProcessorConfig,
/// Watcher configuration
pub watcher: WatcherConfig,
/// Kathy configuration
pub kathy: KathyConfig,
}
#[macro_export]
/// Creates environment variable override block for overriding non-base settings
/// Use of `$self_`: https://veykril.github.io/tlborm/decl-macros/minutiae/identifiers.html
macro_rules! decl_env_overrides {
($name:ident {$self_:ident, $block:block}) => {
affix::paste! {
impl EnvOverridablePrivate for [<$name Config>] {
fn load_env_overrides_private(&mut $self_) $block
}
}
};
($name:ident $block:block) => {
affix::paste! {
impl EnvOverridablePrivate for [<$name Config>] {}
}
};
}
#[macro_export]
/// Creates agent config block on that comes with interval and enabled by
/// default
macro_rules! decl_config {
(
$name:ident {
$($(#[$tags:meta])* $prop:ident: $type:ty,)*
}
) => {
affix::paste! {
pub(self) trait EnvOverridablePrivate {
fn load_env_overrides_private(&mut self) {}
}
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[doc = "Config for `" $name "`"]
#[allow(missing_copy_implementations)]
pub struct [<$name Config>] {
$(
$(#[$tags])*
pub $prop: $type,
)*
/// Agent interval
pub interval: u64,
}
impl [<$name Config>] {
/// Override config with environment variables if present
pub fn load_env_overrides(&mut self) {
if let Ok(var) = std::env::var(std::stringify!([<$name:upper _INTERVAL>])) {
self.interval = var
.parse::<u64>()
.expect(std::stringify!([invalid <$name:upper _INTERVAL> value]));
}
self.load_env_overrides_private();
}
}
}
}
}