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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
use ;
use ;
use Session;
use HttpModules;
use HttpPeer;
// use crate::session_wrapper::{SessionWrapper, SessionWrapperImpl};
use ;
use Debug;
use File;
use BufReader;
use Path;
// pub use deserialize::{DeserializeMap, MapVisitor, OneOrMany, _private};
// pub use pandora_module_utils_macros::{merge_conf, merge_opt, DeserializeMap, RequestFilter};
// Required for macros
pub use async_trait;
pub use clap;
pub use serde;
pub use serde_yaml;
/// Request filter result indicating how the current request should be processed further
/// Trait to be implemented by request filters.
//
// /// Trait for configuration structures that can be loaded from YAML files. This trait has a blanket
// /// implementation for any structure implementing [`serde::Deserialize`].
// pub trait FromYaml {
// /// Loads and merges configuration from a number of YAML files. Glob patterns in file names
// /// will be resolved and file names will be sorted before further processing.
// fn load_from_files<I>(files: I) -> Result<Self, Box<Error>>
// where
// Self: Sized,
// I: IntoIterator,
// I::Item: AsRef<str>;
//
// /// Loads configuration from a YAML file.
// fn load_from_yaml(path: impl AsRef<Path>) -> Result<Self, Box<Error>>
// where
// Self: Sized;
//
// /// Loads configuration from a YAML file, using existing data for missing fields.
// fn merge_load_from_yaml(self, path: impl AsRef<Path>) -> Result<Self, Box<Error>>
// where
// Self: Sized;
//
// /// Loads configuration from a YAML string.
// fn from_yaml(yaml_conf: impl AsRef<str>) -> Result<Self, Box<Error>>
// where
// Self: Sized;
//
// /// Loads configuration from a YAML string, using existing data for missing fields.
// fn merge_from_yaml(self, yaml_conf: impl AsRef<str>) -> Result<Self, Box<Error>>
// where
// Self: Sized;
// }
//
// impl<D> FromYaml for D
// where
// D: Debug + Default,
// for<'de> D: DeserializeSeed<'de, Value = D>,
// {
// fn load_from_files<I>(files: I) -> Result<Self, Box<Error>>
// where
// I: IntoIterator,
// I::Item: AsRef<str>,
// {
// let mut files = files
// .into_iter()
// .filter_map(|path| match glob::glob(path.as_ref()) {
// Ok(iter) => {
// let mut iter = iter.peekable();
// if iter.peek().is_none() {
// error!(
// "Glob pattern {} didn't result in any configuration files",
// path.as_ref()
// );
// }
// Some(iter)
// }
// Err(err) => {
// error!("Ignoring invalid glob pattern `{}`: {err}", path.as_ref());
// None
// }
// })
// .flatten()
// .filter_map(|path| match path {
// Ok(path) => Some(path),
// Err(err) => {
// error!("Failed resolving glob pattern: {err}");
// None
// }
// })
// .collect::<Vec<_>>();
// files.sort();
//
// let result = files.into_iter().try_fold(Self::default(), |conf, path| {
// info!("Loading configuration file `{}`", path.display());
// conf.merge_load_from_yaml(path)
// });
//
// if let Ok(conf) = &result {
// trace!("Successfully loaded configuration: {conf:#?}");
// }
//
// result
// }
//
// fn load_from_yaml(path: impl AsRef<Path>) -> Result<Self, Box<Error>> {
// Self::default().merge_load_from_yaml(path)
// }
//
// fn merge_load_from_yaml(self, path: impl AsRef<Path>) -> Result<Self, Box<Error>> {
// let path = path.as_ref();
// let file = File::open(path).map_err(|err| {
// Error::because(
// ErrorType::FileOpenError,
// format!("failed opening configuration file `{}`", path.display()),
// err,
// )
// })?;
// let reader = BufReader::new(file);
//
// let conf = self
// .deserialize(serde_yaml::Deserializer::from_reader(reader))
// .map_err(|err| {
// Error::because(
// ErrorType::FileReadError,
// format!("failed reading configuration file `{}`", path.display()),
// err,
// )
// })?;
//
// Ok(conf)
// }
//
// fn from_yaml(yaml_conf: impl AsRef<str>) -> Result<Self, Box<Error>> {
// Self::default().merge_from_yaml(yaml_conf)
// }
//
// fn merge_from_yaml(self, yaml_conf: impl AsRef<str>) -> Result<Self, Box<Error>> {
// let conf = self
// .deserialize(serde_yaml::Deserializer::from_str(yaml_conf.as_ref()))
// .map_err(|err| {
// Error::because(ErrorType::ReadError, "failed reading configuration", err)
// })?;
//
// Ok(conf)
// }
// }