-
Notifications
You must be signed in to change notification settings - Fork 45
/
mod.rs
49 lines (39 loc) · 1.47 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
use std::collections::HashMap;
use anyhow::Result;
use reqwest::Url;
use crate::{config::Config, contexts::Context, contexts::ContextProvider};
pub mod dns;
pub mod file;
pub struct VariableIncludeContextProvider<'a> {
pub config: &'a Config,
}
impl<'a> ContextProvider for VariableIncludeContextProvider<'a> {
fn get_prefix(&self) -> String {
String::from("include_variables")
}
fn get_contexts(&self) -> Result<Vec<super::Context>> {
let mut contexts = HashMap::<String, String>::new();
if let Some(variable_includes) = &self.config.include_variables {
for variable_include in variable_includes {
let url = Url::parse(variable_include)?;
if url.scheme() == "dns+txt" {
dns::txt_record_values(&url, &mut contexts)?;
} else if url.scheme() == "file+toml" {
file::toml_values(&url, &mut contexts)?;
} else if url.scheme() == "file+yaml" {
file::yaml_values(&url, &mut contexts)?;
} else {
return Err(anyhow::anyhow!(
"Unknown variable include scheme: {}",
url.scheme()
));
}
}
}
let contexts = contexts
.into_iter()
.map(|(key, value)| Context::KeyValueContext(key, value.into()))
.collect::<Vec<_>>();
Ok(contexts)
}
}