Skip to content

Commit

Permalink
create struct RequestHttpFrontend where SocketAddr is a String
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Mar 16, 2023
1 parent d909f7d commit d2303f9
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 189 deletions.
10 changes: 5 additions & 5 deletions bin/src/acme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sozu_command_lib::{
channel::Channel,
config::Config,
request::{AddBackend, AddCertificate, RemoveBackend, ReplaceCertificate, Request},
response::{HttpFrontend, PathRule, Response, ResponseStatus, Route, RulePosition},
response::{PathRule, RequestHttpFrontend, Response, ResponseStatus, Route, RulePosition},
};

use crate::util;
Expand Down Expand Up @@ -286,10 +286,10 @@ fn set_up_proxying(
path_begin: &str,
server_address: &SocketAddr,
) -> anyhow::Result<()> {
let add_http_front = Request::AddHttpFrontend(HttpFrontend {
let add_http_front = Request::AddHttpFrontend(RequestHttpFrontend {
route: Route::ClusterId(cluster_id.to_owned()),
hostname: String::from(hostname),
address: *frontend,
address: frontend.to_string(),
path: PathRule::Prefix(path_begin.to_owned()),
method: None,
position: RulePosition::Tree,
Expand Down Expand Up @@ -319,9 +319,9 @@ fn remove_proxying(
path_begin: &str,
server_address: SocketAddr,
) -> anyhow::Result<()> {
let remove_http_front = Request::RemoveHttpFrontend(HttpFrontend {
let remove_http_front = Request::RemoveHttpFrontend(RequestHttpFrontend {
route: Route::ClusterId(cluster_id.to_owned()),
address: *frontend,
address: frontend.to_string(),
hostname: String::from(hostname),
path: PathRule::Prefix(path_begin.to_owned()),
method: None,
Expand Down
10 changes: 5 additions & 5 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::BTreeMap, net::SocketAddr};
use std::collections::BTreeMap;

use clap::{Parser, Subcommand};

Expand Down Expand Up @@ -452,7 +452,7 @@ pub enum HttpFrontendCmd {
long = "address",
help = "frontend address, format: IP:port"
)]
address: SocketAddr,
address: String,
#[clap(subcommand, name = "route")]
route: Route,
#[clap(long = "hostname", aliases = &["host"])]
Expand Down Expand Up @@ -481,7 +481,7 @@ pub enum HttpFrontendCmd {
long = "address",
help = "frontend address, format: IP:port"
)]
address: SocketAddr,
address: String,
#[clap(subcommand, name = "route")]
route: Route,
#[clap(long = "hostname", aliases = &["host"])]
Expand Down Expand Up @@ -518,7 +518,7 @@ pub enum TcpFrontendCmd {
long = "address",
help = "frontend address, format: IP:port"
)]
address: SocketAddr,
address: String,
#[clap(
long = "tags",
help = "Specify tag (key-value pair) to apply on front-end (example: 'key=value, other-key=other-value')",
Expand All @@ -539,7 +539,7 @@ pub enum TcpFrontendCmd {
long = "address",
help = "frontend address, format: IP:port"
)]
address: SocketAddr,
address: String,
},
}

Expand Down
12 changes: 9 additions & 3 deletions bin/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,15 @@ pub fn start_server(
accept_cancel_tx,
)?;

let _ = server.load_static_cluster_configuration().await.map_err(|load_error|
error!("Error loading static cluster configuration: {:#}", load_error)
);
let _ = server
.load_static_cluster_configuration()
.await
.map_err(|load_error| {
error!(
"Error loading static cluster configuration: {:#}",
load_error
)
});

if let Some(path) = saved_state_path {
server
Expand Down
18 changes: 9 additions & 9 deletions bin/src/ctl/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use sozu_command_lib::{
},
config::{Config, FileListenerProtocolConfig, Listener, ProxyProtocolConfig},
request::{
ActivateListener, AddCertificate, Cluster, DeactivateListener, FrontendFilters,
ActivateListener, AddBackend, AddCertificate, Cluster, DeactivateListener, FrontendFilters,
ListenerType, LoadBalancingParams, MetricsConfiguration, RemoveBackend, RemoveCertificate,
RemoveListener, ReplaceCertificate, Request, AddBackend,
RemoveListener, ReplaceCertificate, Request,
},
response::{HttpFrontend, PathRule, RulePosition, TcpFrontend},
response::{PathRule, RequestHttpFrontend, RequestTcpFrontend, RulePosition},
};

use crate::{
Expand Down Expand Up @@ -173,14 +173,14 @@ impl CommandManager {
pub fn tcp_frontend_command(&mut self, cmd: TcpFrontendCmd) -> anyhow::Result<()> {
match cmd {
TcpFrontendCmd::Add { id, address, tags } => {
self.order_request(Request::AddTcpFrontend(TcpFrontend {
self.order_request(Request::AddTcpFrontend(RequestTcpFrontend {
cluster_id: id,
address,
tags,
}))
}
TcpFrontendCmd::Remove { id, address } => {
self.order_request(Request::RemoveTcpFrontend(TcpFrontend {
self.order_request(Request::RemoveTcpFrontend(RequestTcpFrontend {
cluster_id: id,
address,
tags: None,
Expand All @@ -200,7 +200,7 @@ impl CommandManager {
method,
route,
tags,
} => self.order_request(Request::AddHttpFrontend(HttpFrontend {
} => self.order_request(Request::AddHttpFrontend(RequestHttpFrontend {
route: route.into(),
address,
hostname,
Expand All @@ -218,7 +218,7 @@ impl CommandManager {
address,
method,
route,
} => self.order_request(Request::RemoveHttpFrontend(HttpFrontend {
} => self.order_request(Request::RemoveHttpFrontend(RequestHttpFrontend {
route: route.into(),
address,
hostname,
Expand All @@ -241,7 +241,7 @@ impl CommandManager {
method,
route,
tags,
} => self.order_request(Request::AddHttpsFrontend(HttpFrontend {
} => self.order_request(Request::AddHttpsFrontend(RequestHttpFrontend {
route: route.into(),
address,
hostname,
Expand All @@ -258,7 +258,7 @@ impl CommandManager {
address,
method,
route,
} => self.order_request(Request::RemoveHttpsFrontend(HttpFrontend {
} => self.order_request(Request::RemoveHttpsFrontend(RequestHttpFrontend {
route: route.into(),
address,
hostname,
Expand Down
16 changes: 8 additions & 8 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::{
LoadBalancingAlgorithms, LoadBalancingParams, LoadMetric, Request, WorkerRequest,
},
response::{
HttpFrontend, HttpListenerConfig, HttpsListenerConfig, PathRule, Route, RulePosition,
TcpFrontend, TcpListenerConfig,
HttpListenerConfig, HttpsListenerConfig, PathRule, RequestHttpFrontend, RequestTcpFrontend,
Route, RulePosition, TcpListenerConfig,
},
};

Expand Down Expand Up @@ -599,9 +599,9 @@ impl HttpFrontendConfig {
expired_at: None,
}));

v.push(Request::AddHttpsFrontend(HttpFrontend {
v.push(Request::AddHttpsFrontend(RequestHttpFrontend {
route: Route::ClusterId(cluster_id.to_string()),
address: self.address,
address: self.address.to_string(),
hostname: self.hostname.clone(),
path: self.path.clone(),
method: self.method.clone(),
Expand All @@ -610,9 +610,9 @@ impl HttpFrontendConfig {
}));
} else {
//create the front both for HTTP and HTTPS if possible
v.push(Request::AddHttpFrontend(HttpFrontend {
v.push(Request::AddHttpFrontend(RequestHttpFrontend {
route: Route::ClusterId(cluster_id.to_string()),
address: self.address,
address: self.address.to_string(),
hostname: self.hostname.clone(),
path: self.path.clone(),
method: self.method.clone(),
Expand Down Expand Up @@ -706,9 +706,9 @@ impl TcpClusterConfig {
})];

for frontend in &self.frontends {
v.push(Request::AddTcpFrontend(TcpFrontend {
v.push(Request::AddTcpFrontend(RequestTcpFrontend {
cluster_id: self.cluster_id.clone(),
address: frontend.address,
address: frontend.address.to_string(),
tags: frontend.tags.clone(),
}));
}
Expand Down
48 changes: 24 additions & 24 deletions command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
certificate::{CertificateAndKey, CertificateFingerprint},
config::ProxyProtocolConfig,
response::{
HttpFrontend, HttpListenerConfig, HttpsListenerConfig, MessageId, TcpFrontend,
TcpListenerConfig,
HttpListenerConfig, HttpsListenerConfig, MessageId, RequestHttpFrontend,
RequestTcpFrontend, TcpListenerConfig,
},
state::ClusterId,
};
Expand Down Expand Up @@ -52,18 +52,18 @@ pub enum Request {
cluster_id: String,
},

AddHttpFrontend(HttpFrontend),
RemoveHttpFrontend(HttpFrontend),
AddHttpFrontend(RequestHttpFrontend),
RemoveHttpFrontend(RequestHttpFrontend),

AddHttpsFrontend(HttpFrontend),
RemoveHttpsFrontend(HttpFrontend),
AddHttpsFrontend(RequestHttpFrontend),
RemoveHttpsFrontend(RequestHttpFrontend),

AddCertificate(AddCertificate),
ReplaceCertificate(ReplaceCertificate),
RemoveCertificate(RemoveCertificate),

AddTcpFrontend(TcpFrontend),
RemoveTcpFrontend(TcpFrontend),
AddTcpFrontend(RequestTcpFrontend),
RemoveTcpFrontend(RequestTcpFrontend),

AddBackend(AddBackend),
RemoveBackend(RemoveBackend),
Expand Down Expand Up @@ -427,12 +427,12 @@ mod tests {
println!("{message:?}");
assert_eq!(
message,
Request::AddHttpFrontend(HttpFrontend {
Request::AddHttpFrontend(RequestHttpFrontend {
route: Route::ClusterId(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::Prefix(String::from("xxx")),
method: None,
address: "0.0.0.0:8080".parse().unwrap(),
address: "0.0.0.0:8080".to_string(),
position: RulePosition::Tree,
tags: None,
})
Expand Down Expand Up @@ -481,12 +481,12 @@ mod tests {
test_message!(
add_http_front,
"../assets/add_http_front.json",
Request::AddHttpFrontend(HttpFrontend {
Request::AddHttpFrontend(RequestHttpFrontend {
route: Route::ClusterId(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::Prefix(String::from("xxx")),
method: None,
address: "0.0.0.0:8080".parse().unwrap(),
address: "0.0.0.0:8080".to_string(),
position: RulePosition::Tree,
tags: None,
})
Expand All @@ -495,12 +495,12 @@ mod tests {
test_message!(
remove_http_front,
"../assets/remove_http_front.json",
Request::RemoveHttpFrontend(HttpFrontend {
Request::RemoveHttpFrontend(RequestHttpFrontend {
route: Route::ClusterId(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::Prefix(String::from("xxx")),
method: None,
address: "0.0.0.0:8080".parse().unwrap(),
address: "0.0.0.0:8080".to_string(),
position: RulePosition::Tree,
tags: Some(BTreeMap::from([
("owner".to_owned(), "John".to_owned()),
Expand All @@ -515,12 +515,12 @@ mod tests {
test_message!(
add_https_front,
"../assets/add_https_front.json",
Request::AddHttpsFrontend(HttpFrontend {
Request::AddHttpsFrontend(RequestHttpFrontend {
route: Route::ClusterId(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::Prefix(String::from("xxx")),
method: None,
address: "0.0.0.0:8443".parse().unwrap(),
address: "0.0.0.0:8443".to_string(),
position: RulePosition::Tree,
tags: None,
})
Expand All @@ -529,12 +529,12 @@ mod tests {
test_message!(
remove_https_front,
"../assets/remove_https_front.json",
Request::RemoveHttpsFrontend(HttpFrontend {
Request::RemoveHttpsFrontend(RequestHttpFrontend {
route: Route::ClusterId(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::Prefix(String::from("xxx")),
method: None,
address: "0.0.0.0:8443".parse().unwrap(),
address: "0.0.0.0:8443".to_string(),
position: RulePosition::Tree,
tags: Some(BTreeMap::from([
("owner".to_owned(), "John".to_owned()),
Expand Down Expand Up @@ -652,12 +652,12 @@ mod tests {
println!("{command:?}");
assert!(
command
== Request::AddHttpFrontend(HttpFrontend {
== Request::AddHttpFrontend(RequestHttpFrontend {
route: Route::ClusterId(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::Prefix(String::from("xxx")),
method: None,
address: "127.0.0.1:4242".parse().unwrap(),
address: "127.0.0.1:4242".to_string(),
position: RulePosition::Tree,
tags: None,
})
Expand All @@ -671,12 +671,12 @@ mod tests {
println!("{command:?}");
assert!(
command
== Request::RemoveHttpFrontend(HttpFrontend {
== Request::RemoveHttpFrontend(RequestHttpFrontend {
route: Route::ClusterId(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::Prefix(String::from("xxx")),
method: None,
address: "127.0.0.1:4242".parse().unwrap(),
address: "127.0.0.1:4242".to_string(),
position: RulePosition::Tree,
tags: Some(BTreeMap::from([
("owner".to_owned(), "John".to_owned()),
Expand Down Expand Up @@ -726,12 +726,12 @@ mod tests {
println!("{command:?}");
assert!(
command
== Request::AddHttpFrontend(HttpFrontend {
== Request::AddHttpFrontend(RequestHttpFrontend {
route: Route::ClusterId(String::from("aa")),
hostname: String::from("cltdl.fr"),
path: PathRule::Prefix(String::from("")),
method: None,
address: "127.0.0.1:4242".parse().unwrap(),
address: "127.0.0.1:4242".to_string(),
position: RulePosition::Tree,
tags: Some(BTreeMap::from([
("owner".to_owned(), "John".to_owned()),
Expand Down

0 comments on commit d2303f9

Please sign in to comment.