Skip to content

Commit

Permalink
rename HttpFrontend::route to cluster_id
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Mar 27, 2023
1 parent f03aac9 commit 5924101
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 82 deletions.
4 changes: 2 additions & 2 deletions bin/src/acme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn set_up_proxying(
server_address: &SocketAddr,
) -> anyhow::Result<()> {
let add_http_front = Request::AddHttpFrontend(RequestHttpFrontend {
route: Some(cluster_id.to_owned()),
cluster_id: Some(cluster_id.to_owned()),
hostname: String::from(hostname),
address: frontend.to_string(),
path: PathRule::prefix(path_begin.to_owned()),
Expand Down Expand Up @@ -321,7 +321,7 @@ fn remove_proxying(
server_address: SocketAddr,
) -> anyhow::Result<()> {
let remove_http_front = Request::RemoveHttpFrontend(RequestHttpFrontend {
route: Some(cluster_id.to_owned()),
cluster_id: Some(cluster_id.to_owned()),
address: frontend.to_string(),
hostname: String::from(hostname),
path: PathRule::prefix(path_begin.to_owned()),
Expand Down
20 changes: 10 additions & 10 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{collections::BTreeMap, net::SocketAddr};
use clap::{Parser, Subcommand};

use sozu_command_lib::{
certificate::TlsVersion, request::LoadBalancingAlgorithms, state::ClusterId,
certificate::TlsVersion, request::LoadBalancingAlgorithms, state::ClusterId as StateClusterId,
};

#[derive(Parser, PartialEq, Eq, Clone, Debug)]
Expand Down Expand Up @@ -425,7 +425,7 @@ pub enum FrontendCmd {
}

#[derive(Subcommand, PartialEq, Eq, Clone, Debug)]
pub enum Route {
pub enum ClusterId {
/// traffic will go to the backend servers with this cluster id
Id {
/// traffic will go to the backend servers with this cluster id
Expand All @@ -436,11 +436,11 @@ pub enum Route {
}

#[allow(clippy::from_over_into)]
impl std::convert::Into<Option<ClusterId>> for Route {
fn into(self) -> Option<ClusterId> {
impl std::convert::Into<Option<StateClusterId>> for ClusterId {
fn into(self) -> Option<StateClusterId> {
match self {
Route::Deny => None,
Route::Id { id } => Some(id),
ClusterId::Deny => None,
ClusterId::Id { id } => Some(id),
}
}
}
Expand All @@ -455,8 +455,8 @@ pub enum HttpFrontendCmd {
help = "frontend address, format: IP:port"
)]
address: SocketAddr,
#[clap(subcommand, name = "route")]
route: Route,
#[clap(subcommand, name = "cluster_id")]
cluster_id: ClusterId,
#[clap(long = "hostname", aliases = &["host"])]
hostname: String,
#[clap(short = 'p', long = "path-prefix", help = "URL prefix of the frontend")]
Expand Down Expand Up @@ -484,8 +484,8 @@ pub enum HttpFrontendCmd {
help = "frontend address, format: IP:port"
)]
address: SocketAddr,
#[clap(subcommand, name = "route")]
route: Route,
#[clap(subcommand, name = "cluster_id")]
cluster_id: ClusterId,
#[clap(long = "hostname", aliases = &["host"])]
hostname: String,
#[clap(short = 'p', long = "path-prefix", help = "URL prefix of the frontend")]
Expand Down
30 changes: 24 additions & 6 deletions bin/src/ctl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,20 @@ pub fn print_frontend_list(frontends: ListedFrontends) {
table.set_format(*prettytable::format::consts::FORMAT_BOX_CHARS);
table.add_row(row!["HTTP frontends "]);
table.add_row(row![
"route", "address", "hostname", "path", "method", "position", "tags"
"cluster_id",
"address",
"hostname",
"path",
"method",
"position",
"tags"
]);
for http_frontend in frontends.http_frontends.iter() {
table.add_row(row!(
http_frontend.route.clone().unwrap_or("Deny".to_owned()),
http_frontend
.cluster_id
.clone()
.unwrap_or("Deny".to_owned()),
http_frontend.address.to_string(),
http_frontend.hostname.to_string(),
format!("{:?}", http_frontend.path),
Expand All @@ -155,11 +164,20 @@ pub fn print_frontend_list(frontends: ListedFrontends) {
table.set_format(*prettytable::format::consts::FORMAT_BOX_CHARS);
table.add_row(row!["HTTPS frontends"]);
table.add_row(row![
"route", "address", "hostname", "path", "method", "position", "tags"
"cluster_id",
"address",
"hostname",
"path",
"method",
"position",
"tags"
]);
for https_frontend in frontends.https_frontends.iter() {
table.add_row(row!(
https_frontend.route.clone().unwrap_or("Deny".to_owned()),
https_frontend
.cluster_id
.clone()
.unwrap_or("Deny".to_owned()),
https_frontend.address.to_string(),
https_frontend.hostname.to_string(),
format!("{:?}", https_frontend.path),
Expand Down Expand Up @@ -480,7 +498,7 @@ pub fn print_query_response_data(

for (key, values) in frontend_data.iter() {
let mut row = Vec::new();
match &key.route {
match &key.cluster_id {
Some(cluster_id) => row.push(cell!(cluster_id)),
None => row.push(cell!("-")),
}
Expand All @@ -504,7 +522,7 @@ pub fn print_query_response_data(

for (key, values) in https_frontend_data.iter() {
let mut row = Vec::new();
match &key.route {
match &key.cluster_id {
Some(cluster_id) => row.push(cell!(cluster_id)),
None => row.push(cell!("-")),
}
Expand Down
16 changes: 8 additions & 8 deletions bin/src/ctl/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ impl CommandManager {
path_equals,
address,
method,
route,
cluster_id: route,
tags,
} => self.order_request(Request::AddHttpFrontend(RequestHttpFrontend {
route: route.into(),
cluster_id: route.into(),
address: address.to_string(),
hostname,
path: PathRule::from_cli_options(path_prefix, path_regex, path_equals),
Expand All @@ -216,9 +216,9 @@ impl CommandManager {
path_equals,
address,
method,
route,
cluster_id: route,
} => self.order_request(Request::RemoveHttpFrontend(RequestHttpFrontend {
route: route.into(),
cluster_id: route.into(),
address: address.to_string(),
hostname,
path: PathRule::from_cli_options(path_prefix, path_regex, path_equals),
Expand All @@ -238,10 +238,10 @@ impl CommandManager {
path_equals,
address,
method,
route,
cluster_id: route,
tags,
} => self.order_request(Request::AddHttpsFrontend(RequestHttpFrontend {
route: route.into(),
cluster_id: route.into(),
address: address.to_string(),
hostname,
path: PathRule::from_cli_options(path_prefix, path_regex, path_equals),
Expand All @@ -256,9 +256,9 @@ impl CommandManager {
path_equals,
address,
method,
route,
cluster_id: route,
} => self.order_request(Request::RemoveHttpsFrontend(RequestHttpFrontend {
route: route.into(),
cluster_id: route.into(),
address: address.to_string(),
hostname,
path: PathRule::from_cli_options(path_prefix, path_regex, path_equals),
Expand Down
2 changes: 1 addition & 1 deletion command/assets/add_http_front.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "ADD_HTTP_FRONTEND",
"content": {
"route": "xxx",
"cluster_id": "xxx",
"address": "0.0.0.0:8080",
"hostname": "yyy",
"path": {
Expand Down
2 changes: 1 addition & 1 deletion command/assets/add_https_front.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "ADD_HTTPS_FRONTEND",
"content": {
"route": "xxx",
"cluster_id": "xxx",
"address": "0.0.0.0:8443",
"hostname": "yyy",
"path": {
Expand Down
2 changes: 1 addition & 1 deletion command/assets/remove_http_front.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "REMOVE_HTTP_FRONTEND",
"content": {
"route": "xxx",
"cluster_id": "xxx",
"address": "0.0.0.0:8080",
"hostname": "yyy",
"path": {
Expand Down
2 changes: 1 addition & 1 deletion command/assets/remove_https_front.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "REMOVE_HTTPS_FRONTEND",
"content": {
"route": "xxx",
"cluster_id": "xxx",
"address": "0.0.0.0:8443",
"hostname": "yyy",
"path": {
Expand Down
4 changes: 2 additions & 2 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ impl HttpFrontendConfig {
}));

v.push(Request::AddHttpsFrontend(RequestHttpFrontend {
route: Some(cluster_id.to_string()),
cluster_id: Some(cluster_id.to_string()),
address: self.address.to_string(),
hostname: self.hostname.clone(),
path: self.path.clone(),
Expand All @@ -748,7 +748,7 @@ impl HttpFrontendConfig {
} else {
//create the front both for HTTP and HTTPS if possible
v.push(Request::AddHttpFrontend(RequestHttpFrontend {
route: Some(cluster_id.to_string()),
cluster_id: Some(cluster_id.to_string()),
address: self.address.to_string(),
hostname: self.hostname.clone(),
path: self.path.clone(),
Expand Down
34 changes: 17 additions & 17 deletions command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ pub struct RequestTcpFrontend {
/// A frontend as requested from the client, with a string SocketAddress
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct RequestHttpFrontend {
/// the route is DENY if none
pub route: Option<ClusterId>,
/// Send a 401, DENY, if cluster_id is None
pub cluster_id: Option<ClusterId>,
pub address: String,
pub hostname: String,
#[serde(default)]
Expand All @@ -342,7 +342,7 @@ impl RequestHttpFrontend {
.address
.parse::<SocketAddr>()
.with_context(|| "wrong socket address")?,
route: self.route,
cluster_id: self.cluster_id,
hostname: self.hostname,
path: self.path,
method: self.method,
Expand Down Expand Up @@ -465,13 +465,13 @@ mod tests {

#[test]
fn config_message_test() {
let raw_json = r#"{ "id": "ID_TEST", "version": 0, "type": "ADD_HTTP_FRONTEND", "content":{"route": "xxx", "hostname": "yyy", "path": {"kind": "PREFIX", "value": "xxx"}, "address": "0.0.0.0:8080"}}"#;
let raw_json = r#"{ "id": "ID_TEST", "version": 0, "type": "ADD_HTTP_FRONTEND", "content":{"cluster_id": "xxx", "hostname": "yyy", "path": {"kind": "PREFIX", "value": "xxx"}, "address": "0.0.0.0:8080"}}"#;
let message: Request = serde_json::from_str(raw_json).unwrap();
println!("{message:?}");
assert_eq!(
message,
Request::AddHttpFrontend(RequestHttpFrontend {
route: Some(String::from("xxx")),
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
Expand Down Expand Up @@ -525,7 +525,7 @@ mod tests {
add_http_front,
"../assets/add_http_front.json",
Request::AddHttpFrontend(RequestHttpFrontend {
route: Some(String::from("xxx")),
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
Expand All @@ -539,7 +539,7 @@ mod tests {
remove_http_front,
"../assets/remove_http_front.json",
Request::RemoveHttpFrontend(RequestHttpFrontend {
route: Some(String::from("xxx")),
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
Expand All @@ -559,7 +559,7 @@ mod tests {
add_https_front,
"../assets/add_https_front.json",
Request::AddHttpsFrontend(RequestHttpFrontend {
route: Some(String::from("xxx")),
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
Expand All @@ -573,7 +573,7 @@ mod tests {
remove_https_front,
"../assets/remove_https_front.json",
Request::RemoveHttpsFrontend(RequestHttpFrontend {
route: Some(String::from("xxx")),
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
Expand Down Expand Up @@ -690,13 +690,13 @@ mod tests {

#[test]
fn add_front_test() {
let raw_json = r#"{"type": "ADD_HTTP_FRONTEND", "content": {"route": "xxx", "hostname": "yyy", "path": {"kind": "PREFIX", "value": "xxx"}, "address": "127.0.0.1:4242", "sticky_session": false}}"#;
let raw_json = r#"{"type": "ADD_HTTP_FRONTEND", "content": {"cluster_id": "xxx", "hostname": "yyy", "path": {"kind": "PREFIX", "value": "xxx"}, "address": "127.0.0.1:4242", "sticky_session": false}}"#;
let command: Request = serde_json::from_str(raw_json).expect("could not parse json");
println!("{command:?}");
assert!(
command
== Request::AddHttpFrontend(RequestHttpFrontend {
route: Some(String::from("xxx")),
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
Expand All @@ -709,13 +709,13 @@ mod tests {

#[test]
fn remove_front_test() {
let raw_json = r#"{"type": "REMOVE_HTTP_FRONTEND", "content": {"route": "xxx", "hostname": "yyy", "path": {"kind": "PREFIX", "value": "xxx"}, "address": "127.0.0.1:4242", "tags": { "owner": "John", "id": "some-long-id" }}}"#;
let raw_json = r#"{"type": "REMOVE_HTTP_FRONTEND", "content": {"cluster_id": "xxx", "hostname": "yyy", "path": {"kind": "PREFIX", "value": "xxx"}, "address": "127.0.0.1:4242", "tags": { "owner": "John", "id": "some-long-id" }}}"#;
let command: Request = serde_json::from_str(raw_json).expect("could not parse json");
println!("{command:?}");
assert!(
command
== Request::RemoveHttpFrontend(RequestHttpFrontend {
route: Some(String::from("xxx")),
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
Expand Down Expand Up @@ -764,13 +764,13 @@ mod tests {

#[test]
fn http_front_crash_test() {
let raw_json = r#"{"type": "ADD_HTTP_FRONTEND", "content": {"route": "aa", "hostname": "cltdl.fr", "path": {"kind": "PREFIX", "value": ""}, "address": "127.0.0.1:4242", "tags": { "owner": "John", "id": "some-long-id" }}}"#;
let raw_json = r#"{"type": "ADD_HTTP_FRONTEND", "content": {"cluster_id": "aa", "hostname": "cltdl.fr", "path": {"kind": "PREFIX", "value": ""}, "address": "127.0.0.1:4242", "tags": { "owner": "John", "id": "some-long-id" }}}"#;
let command: Request = serde_json::from_str(raw_json).expect("could not parse json");
println!("{command:?}");
assert!(
command
== Request::AddHttpFrontend(RequestHttpFrontend {
route: Some(String::from("aa")),
cluster_id: Some(String::from("aa")),
hostname: String::from("cltdl.fr"),
path: PathRule::prefix(String::from("")),
method: None,
Expand All @@ -786,13 +786,13 @@ mod tests {

#[test]
fn http_front_crash_test2() {
let raw_json = r#"{"route": "aa", "hostname": "cltdl.fr", "path": {"kind": "PREFIX", "value": ""}, "address": "127.0.0.1:4242" }"#;
let raw_json = r#"{"cluster_id": "aa", "hostname": "cltdl.fr", "path": {"kind": "PREFIX", "value": ""}, "address": "127.0.0.1:4242" }"#;
let front: HttpFrontend = serde_json::from_str(raw_json).expect("could not parse json");
println!("{front:?}");
assert!(
front
== HttpFrontend {
route: Some(String::from("aa")),
cluster_id: Some(String::from("aa")),
hostname: String::from("cltdl.fr"),
path: PathRule::prefix(String::from("")),
method: None,
Expand Down
6 changes: 3 additions & 3 deletions command/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ pub struct AvailableMetrics {

#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct HttpFrontend {
/// The route is DENY if None
pub route: Option<ClusterId>,
/// Send a 401, DENY, if cluster_id is None
pub cluster_id: Option<ClusterId>,
pub address: SocketAddr,
pub hostname: String,
#[serde(default)]
Expand All @@ -125,7 +125,7 @@ pub struct HttpFrontend {
impl Into<RequestHttpFrontend> for HttpFrontend {
fn into(self) -> RequestHttpFrontend {
RequestHttpFrontend {
route: self.route,
cluster_id: self.cluster_id,
address: self.address.to_string(),
hostname: self.hostname,
path: self.path,
Expand Down

0 comments on commit 5924101

Please sign in to comment.