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
#[cfg(test)]
#[path = "descriptor_deserializer_test.rs"]
mod descriptor_deserializer_test;
use crate::types::{Config, ExternalConfig};
use serde_ignored;
use toml;
pub(crate) fn load_config(descriptor_string: &str, validate: bool) -> Config {
let config: Config = if validate {
let deserializer = toml::de::Deserializer::new(descriptor_string);
match serde_ignored::deserialize(deserializer, |path| {
error!("Found unknown key: {}", path);
}) {
Ok(value) => value,
Err(error) => {
error!("Unable to parse internal descriptor: {}", error);
panic!("Unable to parse internal descriptor: {}", error);
}
}
} else {
match toml::from_str(descriptor_string) {
Ok(value) => value,
Err(error) => {
error!("Unable to parse internal descriptor: {}", error);
panic!("Unable to parse internal descriptor: {}", error);
}
}
};
config
}
pub(crate) fn load_external_config(descriptor_string: &str, file: &str) -> ExternalConfig {
let deserializer = toml::de::Deserializer::new(descriptor_string);
let config: ExternalConfig = match serde_ignored::deserialize(deserializer, |path| {
warn!("Found unknown key: {} in file: {}", path, file);
}) {
Ok(value) => value,
Err(error) => {
error!("Unable to parse external file: {:#?}, {}", &file, error);
panic!("Unable to parse external file: {:#?}, {}", &file, error);
}
};
config
}