mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-29 22:38:36 +08:00
code cleanup and improvements.
This commit is contained in:
@@ -16,12 +16,16 @@ struct JwtAuth<'a>(&'a str);
|
||||
impl AuthValidator for BasicAuth<'_> {
|
||||
fn validate(&self, session: &Session) -> bool {
|
||||
if let Some(header) = session.get_header("authorization") {
|
||||
if let Some((_, val)) = header.to_str().ok().unwrap().split_once(' ') {
|
||||
let decoded = STANDARD.decode(val).ok().unwrap();
|
||||
let decoded_str = String::from_utf8(decoded).ok().unwrap();
|
||||
if let Some(h) = header.to_str().ok() {
|
||||
if let Some((_, val)) = h.split_once(' ') {
|
||||
if let Some(decoded) = STANDARD.decode(val).ok() {
|
||||
if let Some(decoded_str) = String::from_utf8(decoded).ok() {
|
||||
return decoded_str == self.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
@@ -29,7 +33,10 @@ impl AuthValidator for BasicAuth<'_> {
|
||||
impl AuthValidator for ApiKeyAuth<'_> {
|
||||
fn validate(&self, session: &Session) -> bool {
|
||||
if let Some(header) = session.get_header("x-api-key") {
|
||||
return header.to_str().ok().unwrap() == self.0;
|
||||
if let Some(header) = header.to_str().ok() {
|
||||
return header == self.0;
|
||||
}
|
||||
// return header.to_str().ok().unwrap() == self.0;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
@@ -12,48 +12,6 @@ pub struct MetricTypes {
|
||||
pub latency: Duration,
|
||||
pub version: Version,
|
||||
}
|
||||
/*
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref REQUEST_COUNT: IntCounter = register_int_counter!(
|
||||
"aralez_requests_total",
|
||||
"Total number of requests handled by Aralez"
|
||||
).unwrap();
|
||||
pub static ref RESPONSE_CODES: IntCounterVec = register_int_counter_vec!(
|
||||
"aralez_responses_total",
|
||||
"Responses grouped by status code",
|
||||
&["status"]
|
||||
).unwrap();
|
||||
pub static ref REQUEST_LATENCY: Histogram = register_histogram!(
|
||||
"aralez_request_latency_seconds",
|
||||
"Request latency in seconds",
|
||||
vec![0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0]
|
||||
).unwrap();
|
||||
pub static ref RESPONSE_LATENCY: Histogram = register_histogram!(
|
||||
"aralez_response_latency_seconds",
|
||||
"Response latency in seconds",
|
||||
vec![0.01, 0.05, 0.1, 0.25, 0.5, 1.0, 2.0, 5.0]
|
||||
).unwrap();
|
||||
pub static ref REQUESTS_BY_METHOD: IntCounterVec = register_int_counter_vec!(
|
||||
"aralez_requests_by_method_total",
|
||||
"Number of requests by HTTP method",
|
||||
&["method"]
|
||||
).unwrap();
|
||||
pub static ref REQUESTS_BY_UPSTREAM: IntCounterVec = register_int_counter_vec!(
|
||||
"aralez_requests_by_upstream",
|
||||
"Number of requests by UPSTREAM server",
|
||||
&["upstream"]
|
||||
).unwrap();
|
||||
pub static ref REQUESTS_BY_VERSION: IntCounterVec = register_int_counter_vec!(
|
||||
"aralez_requests_by_version_total",
|
||||
"Number of requests by HTTP versions",
|
||||
&["version"]
|
||||
).unwrap();
|
||||
pub static ref ERROR_COUNT: IntCounter = register_int_counter!(
|
||||
"aralez_errors_total",
|
||||
"Total number of errors"
|
||||
).unwrap();
|
||||
}
|
||||
*/
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
@@ -89,11 +47,8 @@ pub static REQUESTS_BY_UPSTREAM: LazyLock<IntCounterVec> =
|
||||
pub static REQUESTS_BY_VERSION: LazyLock<IntCounterVec> =
|
||||
LazyLock::new(|| register_int_counter_vec!("aralez_requests_by_version_total", "Number of requests by HTTP versions", &["version"]).unwrap());
|
||||
|
||||
pub static ERROR_COUNT: LazyLock<IntCounter> = LazyLock::new(|| register_int_counter!("aralez_errors_total", "Total number of errors").unwrap());
|
||||
|
||||
pub fn calc_metrics(metric_types: &MetricTypes) {
|
||||
REQUEST_COUNT.inc();
|
||||
ERROR_COUNT.inc();
|
||||
let timer = REQUEST_LATENCY.start_timer();
|
||||
timer.observe_duration();
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ async fn populate_file_upstreams(config: &mut Configuration, parsed: &Config) {
|
||||
server_list.push(Arc::from(InnerMap {
|
||||
address: Arc::from(ip),
|
||||
port,
|
||||
is_ssl: true,
|
||||
is_ssl: false,
|
||||
is_http2: false,
|
||||
to_https: path_config.to_https.unwrap_or(false),
|
||||
rate_limit: path_config.rate_limit,
|
||||
@@ -265,7 +265,7 @@ fn parce_tls_grades(what: Option<String>) -> Option<String> {
|
||||
},
|
||||
None => {
|
||||
warn!("TLS grade not set, defaulting to: medium");
|
||||
Some("b".to_string())
|
||||
Some("medium".to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,13 +227,13 @@ pub fn listdir(dir: String) -> Vec<tls::CertificateConfig> {
|
||||
certificate_configs.push(y);
|
||||
}
|
||||
}
|
||||
for (_, v) in f.iter() {
|
||||
let y = CertificateConfig {
|
||||
cert_path: v[0].clone(),
|
||||
key_path: v[1].clone(),
|
||||
};
|
||||
certificate_configs.push(y);
|
||||
}
|
||||
// for (_, v) in f.iter() {
|
||||
// let y = CertificateConfig {
|
||||
// cert_path: v[0].clone(),
|
||||
// key_path: v[1].clone(),
|
||||
// };
|
||||
// certificate_configs.push(y);
|
||||
// }
|
||||
certificate_configs
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ impl ProxyHttp for LB {
|
||||
let hostname = return_header_host_from_upstream(session, &self.ump_upst);
|
||||
_ctx.hostname = hostname;
|
||||
let mut backend_id = None;
|
||||
|
||||
if _ctx.extraparams.sticky_sessions {
|
||||
if let Some(cookies) = session.req_header().headers.get("cookie") {
|
||||
if let Ok(cookie_str) = cookies.to_str() {
|
||||
@@ -239,7 +238,7 @@ impl ProxyHttp for LB {
|
||||
let mut buf = buffer.borrow_mut();
|
||||
buf.clear();
|
||||
write!(buf, "{}", client_ip).unwrap_or(());
|
||||
upstream_request.append_header("X-Forward-For", buf.as_str()).unwrap_or(false);
|
||||
upstream_request.append_header("X-Forwarded-For", buf.as_str()).unwrap_or(false);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user