Skip to content

Commit

Permalink
fix(clippy): clean clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
luizfonseca committed May 13, 2024
1 parent d3a40a4 commit 15afc98
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 63 deletions.
50 changes: 25 additions & 25 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ pub struct ConfigRoute {

#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub enum LogLevel {
DEBUG,
INFO,
WARN,
ERROR,
Debug,
Info,
Warn,
Error,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -160,7 +160,7 @@ impl Default for Config {
service_name: "proksi".to_string(),
routes: vec![],
logging: Some(ConfigLogging {
level: LogLevel::INFO,
level: LogLevel::Info,
access_logs: true,
error_logs: false,
}),
Expand All @@ -174,20 +174,20 @@ impl Default for Config {
}
}

impl Config {
// Allow the configuration to be extracted from any `Provider`.
fn from<T: figment::Provider>(provider: T) -> Result<Config, figment::Error> {
Figment::from(provider).extract()
}
// impl Config {
// // Allow the configuration to be extracted from any `Provider`.
// fn from<T: figment::Provider>(provider: T) -> Result<Config, figment::Error> {
// Figment::from(provider).extract()
// }

// Provide a default provider, a `Figment`.
fn figment() -> Figment {
use figment::providers::Env;
// // Provide a default provider, a `Figment`.
// fn figment() -> Figment {
// use figment::providers::Env;

// In reality, whatever the library desires.
Figment::from(Config::default()).merge(Env::prefixed("APP_"))
}
}
// // In reality, whatever the library desires.
// Figment::from(Config::default()).merge(Env::prefixed("APP_"))
// }
// }

/// Implement the `Provider` trait for the `Config` struct.
/// This allows the `Config` struct to be used as a configuration provider with *defaults*.
Expand Down Expand Up @@ -224,11 +224,11 @@ where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
match s.to_uppercase().as_str() {
"DEBUG" => Ok(LogLevel::DEBUG),
"INFO" => Ok(LogLevel::INFO),
"WARN" => Ok(LogLevel::WARN),
"ERROR" => Ok(LogLevel::ERROR),
match s.to_lowercase().as_str() {
"debug" => Ok(LogLevel::Debug),
"info" => Ok(LogLevel::Info),
"warn" => Ok(LogLevel::Warn),
"error" => Ok(LogLevel::Error),
_ => Err(serde::de::Error::custom(
"expected one of DEBUG, INFO, WARN, ERROR",
)),
Expand Down Expand Up @@ -304,7 +304,7 @@ mod tests {

let proxy_config = config.unwrap();
assert_eq!(proxy_config.service_name, "new_name");
assert_eq!(proxy_config.logging.unwrap().level, LogLevel::WARN);
assert_eq!(proxy_config.logging.unwrap().level, LogLevel::Warn);
assert_eq!(proxy_config.routes[0].host, "changed.example.com");
assert_eq!(proxy_config.routes[0].upstreams[0].ip, "10.0.1.2/24");

Expand All @@ -318,7 +318,7 @@ mod tests {
let proxy_config = config.unwrap();
let logging = proxy_config.logging.unwrap();
assert_eq!(proxy_config.service_name, "proksi");
assert_eq!(logging.level, LogLevel::INFO);
assert_eq!(logging.level, LogLevel::Info);
assert_eq!(logging.access_logs, true);
assert_eq!(logging.error_logs, false);
assert_eq!(proxy_config.routes.len(), 0);
Expand Down Expand Up @@ -346,7 +346,7 @@ mod tests {
let paths = proxy_config.paths.unwrap();

assert_eq!(proxy_config.service_name, "proksi");
assert_eq!(logging.level, LogLevel::INFO);
assert_eq!(logging.level, LogLevel::Info);
assert_eq!(logging.access_logs, true);
assert_eq!(logging.error_logs, false);
assert_eq!(proxy_config.routes.len(), 1);
Expand Down
4 changes: 2 additions & 2 deletions src/docker/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct DockerClient {
}

impl DockerClient {
pub async fn start_service(&self) -> () {
pub async fn start_service(&self) {
let mut default_filters = HashMap::new();
default_filters.insert("label", vec!["proksi.host", "proksi.port"]);

Expand All @@ -28,7 +28,7 @@ impl DockerClient {
}
}

async fn list_containers<T>(&self, filters: HashMap<T, Vec<T>>) -> ()
async fn list_containers<T>(&self, filters: HashMap<T, Vec<T>>)
where
T: Into<String> + Hash + serde::ser::Serialize + Eq,
{
Expand Down
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{collections::HashMap, sync::Arc};

use ::pingora::{server::Server, services::background::background_service};
use config::load_proxy_config;
use instant_acme::KeyAuthorization;
use pingora::listeners::TlsSettings;
use pingora_load_balancing::{health_check::TcpHealthCheck, LoadBalancer};
Expand Down Expand Up @@ -55,6 +56,12 @@ impl Storage {
}
}

impl Default for Storage {
fn default() -> Self {
Self::new()
}
}

fn create_tracing_subscriber() {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
Expand All @@ -64,6 +71,8 @@ fn create_tracing_subscriber() {
fn main() {
create_tracing_subscriber();

let _proxy_config = load_proxy_config("/etc/proksi/configs");

let storage = Arc::new(tokio::sync::Mutex::new(Storage::new()));

let test_hosts = vec![
Expand Down
21 changes: 2 additions & 19 deletions src/proxy_server/cert_store.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
use async_trait::async_trait;
use instant_acme::KeyAuthorization;
use pingora::listeners::TlsAccept;
use pingora_boringssl::{
pkey::{PKey, Private},
ssl::NameType,
x509::X509,
};
use pingora_boringssl::{pkey::PKey, ssl::NameType, x509::X509};
use tracing::debug;

use crate::StorageArc;

/// Provides the correct certificates when performing the SSL handshake
#[derive(Debug, Clone)]
pub struct CertValue {
cert: pingora::tls::x509::X509,
key: PKey<Private>,
}

#[derive(Debug)]
pub struct OrderPayload {
url: String,
key_auth: KeyAuthorization,
}

#[derive(Debug)]
pub struct CertStore {
/// The path to the directory containing the certificates
// certs: HashMap<String, CertValue>,
// orders: HashMap<String, OrderPayload>,
//
storage: StorageArc,
pub storage: StorageArc,
}

impl CertStore {
Expand Down
11 changes: 2 additions & 9 deletions src/proxy_server/http_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use std::{
fs::{create_dir_all, read_dir, File},
io::Read,
sync::Arc,
};
use std::{fs::File, io::Read, sync::Arc};

use async_trait::async_trait;
use bytes::Bytes;
use http::{
header::{CONTENT_LENGTH, CONTENT_TYPE, LOCATION},
uri::Scheme,
Expand All @@ -22,9 +17,7 @@ pub struct HttpLB(pub Arc<LoadBalancer<RoundRobin>>);
impl ProxyHttp for HttpLB {
type CTX = ();

fn new_ctx(&self) -> Self::CTX {
()
}
fn new_ctx(&self) -> Self::CTX {}

/// Filters based on path (used by LetsEncrypt/ZeroSSL challenges)
async fn request_filter(
Expand Down
2 changes: 1 addition & 1 deletion src/proxy_server/https_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl ProxyHttp for Router {
ctx: &mut Self::CTX,
) -> pingora::Result<bool> {
let req_host = get_host(session);
let host_without_port = req_host.split(":").collect::<Vec<&str>>()[0].to_string();
let host_without_port = req_host.split(':').collect::<Vec<&str>>()[0].to_string();

// If there's no host matching, returns a 404
let upstream_lb = self.routes.get(&host_without_port);
Expand Down
11 changes: 5 additions & 6 deletions src/services/letsencrypt/http01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ pub struct HttpLetsencrypt {
}

impl HttpLetsencrypt {
pub fn new(hosts: &Vec<String>, contact: &str, cert_store: StorageArc) -> Self {
pub fn new(hosts: &[String], contact: &str, cert_store: StorageArc) -> Self {
HttpLetsencrypt {
challenge_type: ChallengeType::Http01,
url: LetsEncrypt::Staging.url().to_string(),
contact: contact.to_string(),
hosts: hosts.clone(),
hosts: hosts.to_vec(),
cert_store,
}
}

///
async fn create_account(
&self,
) -> Result<(instant_acme::Account, instant_acme::AccountCredentials), ()> {
Expand Down Expand Up @@ -103,7 +102,7 @@ impl HttpLetsencrypt {
}
Err(e) => {
println!("Failed to created account: {:?}", e);
return Err(());
Err(())
}
}
}
Expand Down Expand Up @@ -255,7 +254,7 @@ impl BackgroundService for HttpLetsencrypt {
}

// write challenges to disk
for (key, value) in lkd.get_orders().into_iter() {
for (key, value) in lkd.get_orders().iter() {
let (token, url, key_auth) = value;
// Create a new folder for the challenge
create_dir_all(format!("{}/{}", self.challenges_path(), key)).unwrap();
Expand Down Expand Up @@ -293,8 +292,8 @@ impl BackgroundService for HttpLetsencrypt {
let non_excluded_hosts = self
.hosts
.iter()
.filter(|&host| !excluded_hosts.contains(host))
.cloned()
.filter(|host| !excluded_hosts.contains(host))
.collect::<Vec<String>>();

info!("Generating certificates for {:?}", non_excluded_hosts);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use tracing::info;

pub fn access_log(_attrs: Option<u32>) -> () {
pub fn _access_log(_attrs: Option<u32>) {
info!(
duration = "1ms",
log = "access.log",
Expand Down

0 comments on commit 15afc98

Please sign in to comment.