mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-30 23:08:40 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72ed870538 |
@@ -5,14 +5,39 @@ use crate::utils::tools::{clone_dashmap, clone_dashmap_into, print_upstreams};
|
|||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::path::Path;
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
|
|
||||||
pub async fn load_configuration(d: &str, kind: &str) -> (Option<Configuration>, String) {
|
pub async fn load_configuration(d: &str, kind: &str) -> (Option<Configuration>, String) {
|
||||||
|
let mut conf_files = Vec::new();
|
||||||
let yaml_data = match kind {
|
let yaml_data = match kind {
|
||||||
"filepath" => match fs::read_to_string(d) {
|
"filepath" => match fs::read_to_string(d) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
|
let mut confdir = Path::new(d).parent().unwrap().to_path_buf();
|
||||||
|
confdir.push("conf.d");
|
||||||
|
if let Ok(entries) = fs::read_dir(&confdir) {
|
||||||
|
let mut paths: Vec<_> = entries
|
||||||
|
.flatten()
|
||||||
|
.map(|e| e.path())
|
||||||
|
.filter(|p| p.extension().and_then(|e| e.to_str()) == Some("yaml"))
|
||||||
|
.collect();
|
||||||
|
paths.sort();
|
||||||
|
|
||||||
|
for path in paths {
|
||||||
|
let content = fs::read_to_string(&path);
|
||||||
|
match content {
|
||||||
|
Ok(content) => {
|
||||||
|
conf_files.push(content);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!("Reading: {}: {:?}", path.display(), e)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
info!("Reading upstreams from {}", d);
|
info!("Reading upstreams from {}", d);
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
@@ -32,18 +57,28 @@ pub async fn load_configuration(d: &str, kind: &str) -> (Option<Configuration>,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let parsed: Config = match serde_yaml::from_str(&yaml_data) {
|
let mut parsed: Config = match serde_yaml::from_str(&yaml_data) {
|
||||||
Ok(cfg) => {
|
Ok(cfg) => cfg,
|
||||||
// println!("{:#?}", cfg);
|
|
||||||
cfg
|
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to parse upstreams file: {}", e);
|
error!("Failed to parse upstreams file: {}", e);
|
||||||
return (None, e.to_string());
|
return (None, e.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut toreturn = Configuration::default();
|
|
||||||
|
|
||||||
|
if let Some(ref mut upstreams) = parsed.upstreams {
|
||||||
|
for uconf in conf_files {
|
||||||
|
let p: HashMap<String, HostConfig> = match serde_yaml::from_str(&uconf) {
|
||||||
|
Ok(ucfg) => ucfg,
|
||||||
|
Err(e) => {
|
||||||
|
error!("Failed to parse upstreams file: {}", e);
|
||||||
|
return (None, e.to_string());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
upstreams.extend(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut toreturn = Configuration::default();
|
||||||
populate_headers_and_auth(&mut toreturn, &parsed).await;
|
populate_headers_and_auth(&mut toreturn, &parsed).await;
|
||||||
toreturn.typecfg = parsed.provider.clone();
|
toreturn.typecfg = parsed.provider.clone();
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ pub type UpstreamsDashMap = DashMap<Arc<str>, DashMap<Arc<str>, (Vec<Arc<InnerMa
|
|||||||
|
|
||||||
pub type UpstreamsIdMap = DashMap<String, Arc<InnerMap>>;
|
pub type UpstreamsIdMap = DashMap<String, Arc<InnerMap>>;
|
||||||
pub type Headers = DashMap<Arc<str>, DashMap<Arc<str>, Vec<(String, Arc<str>)>>>;
|
pub type Headers = DashMap<Arc<str>, DashMap<Arc<str>, Vec<(String, Arc<str>)>>>;
|
||||||
|
// pub type UpstreamsSerDde = Option<HashMap<String, HostConfig>>;
|
||||||
|
// pub type UpstreamsSerDe = HashMap<String, HostConfig>;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct Extraparams {
|
pub struct Extraparams {
|
||||||
|
|||||||
Reference in New Issue
Block a user