mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-30 23:08:40 +08:00
reStructurization of files
This commit is contained in:
@@ -7,13 +7,13 @@ globals:
|
|||||||
- "Access-Control-Allow-Methods:POST, GET, OPTIONS"
|
- "Access-Control-Allow-Methods:POST, GET, OPTIONS"
|
||||||
- "Access-Control-Max-Age:86400"
|
- "Access-Control-Max-Age:86400"
|
||||||
- "X-Custom-Header:Something Special"
|
- "X-Custom-Header:Something Special"
|
||||||
authorization: # Optional, only one of auth methods below can be active at a time
|
# authorization: # Optional, only one of auth methods below can be active at a time
|
||||||
# - "basic"
|
# - "basic"
|
||||||
# - "zangag:Anhnazand1234"
|
# - "zangag:Anhnazand1234"
|
||||||
# - "apikey"
|
# - "apikey"
|
||||||
# - "5a28cc4c-ce10-4ff1-824e-743c38835f5c"
|
# - "5a28cc4c-ce10-4ff1-824e-743c38835f5c"
|
||||||
- "jwt"
|
# - "jwt"
|
||||||
- "910517d9-f9a1-48de-8826-dbadacbd84af-cb6f830e-ab16-47ec-9d8f-0090de732774"
|
# - "910517d9-f9a1-48de-8826-dbadacbd84af-cb6f830e-ab16-47ec-9d8f-0090de732774"
|
||||||
consul: # If the provider is consul. Otherwise ignored
|
consul: # If the provider is consul. Otherwise ignored
|
||||||
servers:
|
servers:
|
||||||
- "http://master1:8500"
|
- "http://master1:8500"
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ mod filewatch;
|
|||||||
pub mod healthcheck;
|
pub mod healthcheck;
|
||||||
pub mod jwt;
|
pub mod jwt;
|
||||||
pub mod parceyaml;
|
pub mod parceyaml;
|
||||||
|
pub mod structs;
|
||||||
pub mod tools;
|
pub mod tools;
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
use crate::utils::parceyaml::{load_configuration, Configuration, ServiceMapping};
|
use crate::utils::parceyaml::load_configuration;
|
||||||
use crate::utils::tools::{clone_dashmap_into, compare_dashmaps, UpstreamsDashMap};
|
use crate::utils::structs::{Configuration, ServiceMapping, UpstreamsDashMap};
|
||||||
|
use crate::utils::tools::{clone_dashmap_into, compare_dashmaps};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use futures::channel::mpsc::Sender;
|
use futures::channel::mpsc::Sender;
|
||||||
use futures::SinkExt;
|
use futures::SinkExt;
|
||||||
// use hickory_client::client::{Client, ClientHandle};
|
|
||||||
// use hickory_client::proto::rr::{DNSClass, Name, RecordType};
|
|
||||||
// use hickory_client::proto::runtime::TokioRuntimeProvider;
|
|
||||||
// use hickory_client::proto::tcp::TcpClientStream;
|
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use pingora::prelude::sleep;
|
use pingora::prelude::sleep;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
// use std::str::FromStr;
|
|
||||||
use reqwest::header::{HeaderMap, HeaderValue};
|
use reqwest::header::{HeaderMap, HeaderValue};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -19,8 +15,6 @@ use std::time::Duration;
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct Service {
|
struct Service {
|
||||||
// #[serde(rename = "ServiceName")]
|
|
||||||
// service_name: String,
|
|
||||||
#[serde(rename = "ServiceTaggedAddresses")]
|
#[serde(rename = "ServiceTaggedAddresses")]
|
||||||
tagged_addresses: HashMap<String, TaggedAddress>,
|
tagged_addresses: HashMap<String, TaggedAddress>,
|
||||||
}
|
}
|
||||||
@@ -148,20 +142,3 @@ async fn get_by_http(url: String, token: Option<String>) -> Option<DashMap<Strin
|
|||||||
upstreams.insert("/".to_string(), (values, AtomicUsize::new(0)));
|
upstreams.insert("/".to_string(), (values, AtomicUsize::new(0)));
|
||||||
Some(upstreams)
|
Some(upstreams)
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[allow(dead_code)]
|
|
||||||
// async fn get_by_dns() {
|
|
||||||
// let (stream, sender) = TcpClientStream::new(([192, 168, 22, 1], 53).into(), None, None, TokioRuntimeProvider::new());
|
|
||||||
// let client = Client::new(stream, sender, None);
|
|
||||||
// let (mut client, bg) = client.await.expect("connection failed");
|
|
||||||
// tokio::spawn(bg);
|
|
||||||
// let query = client.query(Name::from_str("_frontend-dev-frontend-srv._tcp.service.consul.").unwrap(), DNSClass::IN, RecordType::SRV);
|
|
||||||
// // let query = client.query(Name::from_str("matyan.org.").unwrap(), DNSClass::IN, RecordType::A);
|
|
||||||
// let response = query.await.unwrap();
|
|
||||||
//
|
|
||||||
// for t in response.answers().iter() {
|
|
||||||
// for y in t.data().as_srv().iter() {
|
|
||||||
// println!(" DNS ==> {:?} : {:?}", y.target().to_utf8(), y.port());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::utils::consul;
|
use crate::utils::consul;
|
||||||
use crate::utils::filewatch;
|
use crate::utils::filewatch;
|
||||||
use crate::utils::parceyaml::Configuration;
|
use crate::utils::structs::Configuration;
|
||||||
use crate::web::webserver;
|
use crate::web::webserver;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::channel::mpsc::Sender;
|
use futures::channel::mpsc::Sender;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::utils::parceyaml::{load_configuration, Configuration};
|
use crate::utils::parceyaml::load_configuration;
|
||||||
|
use crate::utils::structs::Configuration;
|
||||||
use futures::channel::mpsc::Sender;
|
use futures::channel::mpsc::Sender;
|
||||||
use futures::SinkExt;
|
use futures::SinkExt;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::utils::structs::{UpstreamsDashMap, UpstreamsIdMap};
|
||||||
use crate::utils::tools::*;
|
use crate::utils::tools::*;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
|
|||||||
@@ -1,59 +1,11 @@
|
|||||||
use crate::utils::tools::*;
|
use crate::utils::structs::*;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use serde_yaml::Error;
|
use serde_yaml::Error;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct ServiceMapping {
|
|
||||||
pub proxy: String,
|
|
||||||
pub real: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct Extraparams {
|
|
||||||
pub stickysessions: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct Consul {
|
|
||||||
pub servers: Option<Vec<String>>,
|
|
||||||
pub services: Option<Vec<ServiceMapping>>,
|
|
||||||
pub token: Option<String>,
|
|
||||||
}
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct Config {
|
|
||||||
provider: String,
|
|
||||||
stickysessions: bool,
|
|
||||||
upstreams: Option<HashMap<String, HostConfig>>,
|
|
||||||
globals: Option<HashMap<String, Vec<String>>>,
|
|
||||||
consul: Option<Consul>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct HostConfig {
|
|
||||||
paths: HashMap<String, PathConfig>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct PathConfig {
|
|
||||||
ssl: bool,
|
|
||||||
servers: Vec<String>,
|
|
||||||
headers: Option<Vec<String>>,
|
|
||||||
}
|
|
||||||
pub struct Configuration {
|
|
||||||
pub upstreams: UpstreamsDashMap,
|
|
||||||
pub headers: Headers,
|
|
||||||
pub consul: Option<Consul>,
|
|
||||||
pub typecfg: String,
|
|
||||||
pub extraparams: Extraparams,
|
|
||||||
pub globals: Option<DashMap<String, Vec<String>>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
// pub fn load_configuration(d: &str, kind: &str) -> Option<(UpstreamsDashMap, Headers, String)> {
|
|
||||||
pub fn load_configuration(d: &str, kind: &str) -> Option<Configuration> {
|
pub fn load_configuration(d: &str, kind: &str) -> Option<Configuration> {
|
||||||
let mut toreturn: Configuration = Configuration {
|
let mut toreturn: Configuration = Configuration {
|
||||||
upstreams: Default::default(),
|
upstreams: Default::default(),
|
||||||
@@ -66,9 +18,6 @@ pub fn load_configuration(d: &str, kind: &str) -> Option<Configuration> {
|
|||||||
toreturn.upstreams = UpstreamsDashMap::new();
|
toreturn.upstreams = UpstreamsDashMap::new();
|
||||||
toreturn.headers = Headers::new();
|
toreturn.headers = Headers::new();
|
||||||
|
|
||||||
// let upstreamsmap = UpstreamsDashMap::new();
|
|
||||||
// let headersmap = DashMap::new();
|
|
||||||
|
|
||||||
let mut yaml_data = d.to_string();
|
let mut yaml_data = d.to_string();
|
||||||
match kind {
|
match kind {
|
||||||
"filepath" => {
|
"filepath" => {
|
||||||
@@ -172,21 +121,6 @@ pub fn load_configuration(d: &str, kind: &str) -> Option<Configuration> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct AppConfig {
|
|
||||||
pub hc_interval: u16,
|
|
||||||
pub hc_method: String,
|
|
||||||
pub upstreams_conf: String,
|
|
||||||
pub log_level: String,
|
|
||||||
pub config_address: String,
|
|
||||||
pub proxy_address_http: String,
|
|
||||||
pub master_key: String,
|
|
||||||
pub proxy_address_tls: Option<String>,
|
|
||||||
pub tls_certificate: Option<String>,
|
|
||||||
pub tls_key_file: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
// pub fn parce_main_config(path: &str) -> DashMap<String, String> {
|
|
||||||
pub fn parce_main_config(path: &str) -> AppConfig {
|
pub fn parce_main_config(path: &str) -> AppConfig {
|
||||||
info!("Parsing configuration");
|
info!("Parsing configuration");
|
||||||
let data = fs::read_to_string(path).unwrap();
|
let data = fs::read_to_string(path).unwrap();
|
||||||
|
|||||||
68
src/utils/structs.rs
Normal file
68
src/utils/structs.rs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
use dashmap::DashMap;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::sync::atomic::AtomicUsize;
|
||||||
|
|
||||||
|
pub type UpstreamsDashMap = DashMap<String, DashMap<String, (Vec<(String, u16, bool)>, AtomicUsize)>>;
|
||||||
|
pub type Headers = DashMap<String, DashMap<String, Vec<(String, String)>>>;
|
||||||
|
pub type UpstreamsIdMap = DashMap<String, (String, u16, bool)>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct ServiceMapping {
|
||||||
|
pub proxy: String,
|
||||||
|
pub real: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Extraparams {
|
||||||
|
pub stickysessions: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Consul {
|
||||||
|
pub servers: Option<Vec<String>>,
|
||||||
|
pub services: Option<Vec<ServiceMapping>>,
|
||||||
|
pub token: Option<String>,
|
||||||
|
}
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Config {
|
||||||
|
pub provider: String,
|
||||||
|
pub stickysessions: bool,
|
||||||
|
pub upstreams: Option<HashMap<String, HostConfig>>,
|
||||||
|
pub globals: Option<HashMap<String, Vec<String>>>,
|
||||||
|
pub consul: Option<Consul>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct HostConfig {
|
||||||
|
pub paths: HashMap<String, PathConfig>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct PathConfig {
|
||||||
|
pub ssl: bool,
|
||||||
|
pub servers: Vec<String>,
|
||||||
|
pub headers: Option<Vec<String>>,
|
||||||
|
}
|
||||||
|
pub struct Configuration {
|
||||||
|
pub upstreams: UpstreamsDashMap,
|
||||||
|
pub headers: Headers,
|
||||||
|
pub consul: Option<Consul>,
|
||||||
|
pub typecfg: String,
|
||||||
|
pub extraparams: Extraparams,
|
||||||
|
pub globals: Option<DashMap<String, Vec<String>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct AppConfig {
|
||||||
|
pub hc_interval: u16,
|
||||||
|
pub hc_method: String,
|
||||||
|
pub upstreams_conf: String,
|
||||||
|
pub log_level: String,
|
||||||
|
pub config_address: String,
|
||||||
|
pub proxy_address_http: String,
|
||||||
|
pub master_key: String,
|
||||||
|
pub proxy_address_tls: Option<String>,
|
||||||
|
pub tls_certificate: Option<String>,
|
||||||
|
pub tls_key_file: Option<String>,
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::utils::structs::{UpstreamsDashMap, UpstreamsIdMap};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::any::type_name;
|
use std::any::type_name;
|
||||||
@@ -22,10 +23,6 @@ pub fn print_upstreams(upstreams: &UpstreamsDashMap) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type UpstreamsDashMap = DashMap<String, DashMap<String, (Vec<(String, u16, bool)>, AtomicUsize)>>;
|
|
||||||
pub type Headers = DashMap<String, DashMap<String, Vec<(String, String)>>>;
|
|
||||||
pub type UpstreamsIdMap = DashMap<String, (String, u16, bool)>;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn typeoff<T>(_: T) {
|
pub fn typeoff<T>(_: T) {
|
||||||
let to = type_name::<T>();
|
let to = type_name::<T>();
|
||||||
@@ -44,7 +41,6 @@ pub fn string_to_bool(val: Option<&str>) -> Option<bool> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn clone_dashmap(original: &UpstreamsDashMap) -> UpstreamsDashMap {
|
pub fn clone_dashmap(original: &UpstreamsDashMap) -> UpstreamsDashMap {
|
||||||
let new_map: UpstreamsDashMap = DashMap::new();
|
let new_map: UpstreamsDashMap = DashMap::new();
|
||||||
|
|
||||||
@@ -117,7 +113,6 @@ pub fn compare_dashmaps(map1: &UpstreamsDashMap, map2: &UpstreamsDashMap) -> boo
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn merge_headers(target: &DashMap<String, Vec<(String, String)>>, source: &DashMap<String, Vec<(String, String)>>) {
|
pub fn merge_headers(target: &DashMap<String, Vec<(String, String)>>, source: &DashMap<String, Vec<(String, String)>>) {
|
||||||
for entry in source.iter() {
|
for entry in source.iter() {
|
||||||
let global_key = entry.key().clone();
|
let global_key = entry.key().clone();
|
||||||
@@ -137,10 +132,8 @@ pub fn clone_idmap_into(original: &UpstreamsDashMap, cloned: &UpstreamsIdMap) {
|
|||||||
let (vec, _) = inner_entry.value();
|
let (vec, _) = inner_entry.value();
|
||||||
let new_vec = vec.clone();
|
let new_vec = vec.clone();
|
||||||
for x in vec.iter() {
|
for x in vec.iter() {
|
||||||
// let id = format!("{}:{}:{}", x.0.to_string(), x.1.to_string(), x.2.to_string());
|
|
||||||
let mut id = String::new();
|
let mut id = String::new();
|
||||||
write!(&mut id, "{}:{}:{}", x.0, x.1, x.2).unwrap();
|
write!(&mut id, "{}:{}:{}", x.0, x.1, x.2).unwrap();
|
||||||
|
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(id.clone().into_bytes());
|
hasher.update(id.clone().into_bytes());
|
||||||
let hash = hasher.finalize();
|
let hash = hasher.finalize();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::utils::discovery::{APIUpstreamProvider, ConsulProvider, Discovery, FromFileProvider};
|
use crate::utils::discovery::{APIUpstreamProvider, ConsulProvider, Discovery, FromFileProvider};
|
||||||
use crate::utils::parceyaml::Configuration;
|
use crate::utils::structs::Configuration;
|
||||||
use crate::utils::tools::*;
|
use crate::utils::tools::*;
|
||||||
use crate::utils::*;
|
use crate::utils::*;
|
||||||
use crate::web::proxyhttp::LB;
|
use crate::web::proxyhttp::LB;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use crate::utils::auth::authenticate;
|
use crate::utils::auth::authenticate;
|
||||||
use crate::utils::parceyaml::{AppConfig, Extraparams};
|
use crate::utils::structs::{AppConfig, Extraparams, Headers, UpstreamsDashMap, UpstreamsIdMap};
|
||||||
use crate::utils::tools::*;
|
|
||||||
use crate::web::gethosts::GetHost;
|
use crate::web::gethosts::GetHost;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use crate::utils::parceyaml::Extraparams;
|
use crate::utils::structs::{Extraparams, Headers, UpstreamsDashMap, UpstreamsIdMap};
|
||||||
use crate::utils::tools::*;
|
|
||||||
use crate::web::proxyhttp::LB;
|
use crate::web::proxyhttp::LB;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::utils::parceyaml::Configuration;
|
use crate::utils::structs::Configuration;
|
||||||
use axum::body::Body;
|
use axum::body::Body;
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum::http::{Response, StatusCode};
|
use axum::http::{Response, StatusCode};
|
||||||
|
|||||||
Reference in New Issue
Block a user