Added Config structure option to configuration type

This commit is contained in:
PinkP4nther 2021-08-23 08:40:10 -07:00
commit 1aa97d6493
2 changed files with 22 additions and 10 deletions

View file

@ -1,4 +1,4 @@
use sslrelay::{self, ConfigType, HandlerCallbacks};
use sslrelay::{self, ConfigType, RelayConfig, HandlerCallbacks};
// Handler object
@ -37,7 +37,15 @@ fn main() {
let mut relay = sslrelay::SSLRelay::new(Handler);
// Load Configuration
relay.load_config(ConfigType::Default);
relay.load_config(ConfigType::Conf(RelayConfig {
bind_host: "0.0.0.0".to_string(),
bind_port: "443".to_string(),
remote_host: "remote.com".to_string(),
remote_port: "443".to_string(),
ssl_private_key_path: "./remote.com.key".to_string(),
ssl_cert_path: "./remote.com.crt".to_string(),
verbose_level: 2,
}));
// Start listening
relay.start();

View file

@ -16,14 +16,14 @@ mod http;
use http as http_helper;
#[derive(Clone)]
struct RelayConfig {
bind_host: String,
bind_port: String,
remote_host: String,
remote_port: String,
ssl_private_key_path: String,
ssl_cert_path: String,
verbose_level: i8,
pub struct RelayConfig {
pub bind_host: String,
pub bind_port: String,
pub remote_host: String,
pub remote_port: String,
pub ssl_private_key_path: String,
pub ssl_cert_path: String,
pub verbose_level: i8,
}
pub trait HandlerCallbacks {
@ -36,6 +36,7 @@ pub trait HandlerCallbacks {
pub enum ConfigType<T> {
Env,
Path(T),
Conf(RelayConfig),
Default,
}
@ -117,6 +118,9 @@ impl<H: HandlerCallbacks + std::marker::Sync + std::marker::Send + 'static> SSLR
}
};
},
ConfigType::Conf(conf) => {
return conf;
}
ConfigType::Default => {}
}