Skip to content

Commit

Permalink
use default values wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Apr 12, 2023
1 parent b6bc86d commit b125338
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 116 deletions.
12 changes: 3 additions & 9 deletions bin/src/acme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@ fn set_up_proxying(
hostname: String::from(hostname),
address: frontend.to_string(),
path: PathRule::prefix(path_begin.to_owned()),
method: None,
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
});

order_request(channel, add_http_front).with_context(|| "Request AddHttpFront failed")?;
Expand All @@ -303,9 +301,7 @@ fn set_up_proxying(
cluster_id: cluster_id.to_string(),
backend_id: format!("{cluster_id}-0"),
address: server_address.to_string(),
load_balancing_parameters: None,
sticky_id: None,
backup: None,
..Default::default()
});

order_request(channel, add_backend).with_context(|| "AddBackend request failed")?;
Expand All @@ -325,9 +321,7 @@ fn remove_proxying(
address: frontend.to_string(),
hostname: String::from(hostname),
path: PathRule::prefix(path_begin.to_owned()),
method: None,
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
});
order_request(channel, remove_http_front).with_context(|| "RemoveHttpFront request failed")?;

Expand Down
9 changes: 3 additions & 6 deletions bin/src/ctl/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ impl CommandManager {
https_redirect,
proxy_protocol: proxy_protocol.and_then(|pp| Some(pp as i32)),
load_balancing: load_balancing_policy as i32,
load_metric: None,
answer_503: None,
..Default::default()
}))
}
ClusterCmd::Remove { id } => {
Expand Down Expand Up @@ -228,8 +227,7 @@ impl CommandManager {
hostname,
path: PathRule::from_cli_options(path_prefix, path_regex, path_equals),
method: method.map(String::from),
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
})),
}
}
Expand Down Expand Up @@ -271,8 +269,7 @@ impl CommandManager {
hostname,
path: PathRule::from_cli_options(path_prefix, path_regex, path_equals),
method: method.map(String::from),
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
})),
}
}
Expand Down
4 changes: 4 additions & 0 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ impl ListenerBuilder {
public_address: self.public_address.clone(),
expect_proxy: self.expect_proxy.unwrap_or(false),
sticky_name: self.sticky_name.clone(),
front_timeout: self.front_timeout.unwrap_or(DEFAULT_FRONT_TIMEOUT),
back_timeout: self.back_timeout.unwrap_or(DEFAULT_BACK_TIMEOUT),
connect_timeout: self.connect_timeout.unwrap_or(DEFAULT_CONNECT_TIMEOUT),
request_timeout: self.request_timeout.unwrap_or(DEFAULT_REQUEST_TIMEOUT),
answer_404,
answer_503,
..Default::default()
Expand Down
39 changes: 12 additions & 27 deletions command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ impl FromStr for LoadBalancingAlgorithms {
}
}


pub fn is_false(b: &bool) -> bool {
!*b
}
Expand Down Expand Up @@ -312,10 +311,8 @@ mod tests {
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
address: "0.0.0.0:8080".to_string(),
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
})
);
}
Expand Down Expand Up @@ -346,8 +343,7 @@ mod tests {
https_redirect: true,
proxy_protocol: Some(ProxyProtocolConfig::ExpectHeader as i32),
load_balancing: LoadBalancingAlgorithms::RoundRobin as i32,
load_metric: None,
answer_503: None,
..Default::default()
})
);

Expand All @@ -366,10 +362,8 @@ mod tests {
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
address: "0.0.0.0:8080".to_string(),
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
})
);

Expand All @@ -380,16 +374,15 @@ mod tests {
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
address: "0.0.0.0:8080".to_string(),
position: RulePosition::Tree.into(),
tags: BTreeMap::from([
("owner".to_owned(), "John".to_owned()),
(
"uuid".to_owned(),
"0dd8d7b1-a50a-461a-b1f9-5211a5f45a83".to_owned()
)
])
]),
..Default::default()
})
);

Expand All @@ -400,10 +393,8 @@ mod tests {
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
address: "0.0.0.0:8443".to_string(),
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
})
);

Expand All @@ -414,16 +405,15 @@ mod tests {
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
address: "0.0.0.0:8443".to_string(),
position: RulePosition::Tree.into(),
tags: BTreeMap::from([
("owner".to_owned(), "John".to_owned()),
(
"uuid".to_owned(),
"0dd8d7b1-a50a-461a-b1f9-5211a5f45a83".to_owned()
)
])
]),
..Default::default()
})
);

Expand Down Expand Up @@ -532,10 +522,8 @@ mod tests {
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
address: "127.0.0.1:4242".to_string(),
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
});
println!("expected: {:?}", add_http_frontend);
assert!(parsed_request == add_http_frontend);
Expand All @@ -552,13 +540,12 @@ mod tests {
cluster_id: Some(String::from("xxx")),
hostname: String::from("yyy"),
path: PathRule::prefix(String::from("xxx")),
method: None,
address: "127.0.0.1:4242".to_string(),
position: RulePosition::Tree.into(),
tags: BTreeMap::from([
("owner".to_owned(), "John".to_owned()),
("id".to_owned(), "some-long-id".to_owned())
]),
..Default::default()
})
);
}
Expand All @@ -574,9 +561,8 @@ mod tests {
cluster_id: String::from("xxx"),
backend_id: String::from("xxx-0"),
address: "0.0.0.0:8080".to_string(),
sticky_id: None,
load_balancing_parameters: Some(LoadBalancingParams { weight: 0 }),
backup: None,
..Default::default()
})
);
}
Expand Down Expand Up @@ -607,13 +593,12 @@ mod tests {
cluster_id: Some(String::from("aa")),
hostname: String::from("cltdl.fr"),
path: PathRule::prefix(String::from("")),
method: None,
address: "127.0.0.1:4242".to_string(),
position: RulePosition::Tree.into(),
tags: BTreeMap::from([
("owner".to_owned(), "John".to_owned()),
("id".to_owned(), "some-long-id".to_owned())
]),
..Default::default()
})
);
}
Expand Down
12 changes: 1 addition & 11 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,6 @@ mod tests {
hostname: String::from("test.local"),
path: PathRule::prefix(String::from("/abc")),
address: "0.0.0.0:8080".to_string(),
position: RulePosition::Tree.into(),
..Default::default()
}))
.expect("Could not execute request");
Expand Down Expand Up @@ -1416,7 +1415,6 @@ mod tests {
hostname: String::from("test.local"),
path: PathRule::prefix(String::from("/abc")),
address: "0.0.0.0:8080".to_string(),
position: RulePosition::Tree.into(),
..Default::default()
}),
Request::RemoveBackend(RemoveBackend {
Expand Down Expand Up @@ -1563,8 +1561,7 @@ mod tests {
backend_id: String::from("cluster_1-0"),
address: "127.0.0.1:1026".to_string(),
load_balancing_parameters: Some(LoadBalancingParams::default()),
sticky_id: None,
backup: None,
..Default::default()
}))
.expect("Could not execute request");

Expand Down Expand Up @@ -1609,9 +1606,6 @@ mod tests {
state
.dispatch(&Request::AddHttpsListener(HttpsListenerConfig {
address: "0.0.0.0:8443".parse().unwrap(),
// answer_404: String::new(),
answer_503: String::new(),
sticky_name: String::new(),
..Default::default()
}))
.expect("Could not execute request");
Expand All @@ -1635,8 +1629,6 @@ mod tests {
.dispatch(&Request::AddHttpListener(HttpListenerConfig {
address: "0.0.0.0:8080".parse().unwrap(),
answer_404: "test".to_string(),
answer_503: String::new(),
sticky_name: String::new(),
..Default::default()
}))
.expect("Could not execute request");
Expand Down Expand Up @@ -1684,8 +1676,6 @@ mod tests {
Request::AddHttpListener(HttpListenerConfig {
address: "0.0.0.0:8080".parse().unwrap(),
answer_404: String::from("test"),
answer_503: String::new(),
sticky_name: String::new(),
..Default::default()
}),
Request::ActivateListener(ActivateListener {
Expand Down
8 changes: 2 additions & 6 deletions e2e/src/sozu/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,7 @@ impl Worker {
cluster_id: cluster_id.into(),
sticky_session: false,
https_redirect: false,
proxy_protocol: None,
load_balancing: LoadBalancingAlgorithms::default() as i32,
load_metric: None,
answer_503: None,
..Default::default()
}
}

Expand Down Expand Up @@ -313,8 +310,7 @@ impl Worker {
backend_id: backend_id.into(),
address,
load_balancing_parameters: Some(LoadBalancingParams::default()),
sticky_id: None,
backup: None,
..Default::default()
}
}
}
12 changes: 3 additions & 9 deletions lib/examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ fn main() -> anyhow::Result<()> {
address: "127.0.0.1:8080".to_string(),
hostname: String::from("lolcatho.st"),
path: PathRule::prefix(String::from("/")),
method: None,
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
};

let http_backend = AddBackend {
Expand Down Expand Up @@ -128,9 +126,7 @@ fn main() -> anyhow::Result<()> {
address: "127.0.0.1:8443".to_string(),
hostname: String::from("lolcatho.st"),
path: PathRule::prefix(String::from("/")),
method: None,
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
};

command2.write_message(&WorkerRequest {
Expand Down Expand Up @@ -178,9 +174,7 @@ fn main() -> anyhow::Result<()> {
address: "127.0.0.1:8443".to_string(),
hostname: String::from("test.local"),
path: PathRule::prefix(String::from("/")),
method: None,
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
};

command2.write_message(&WorkerRequest {
Expand Down
2 changes: 1 addition & 1 deletion lib/examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ fn main() -> anyhow::Result<()> {
address: "127.0.0.1:8080".to_string(),
hostname: String::from("example.com"),
path: PathRule::prefix(String::from("/")),
method: None,
position: RulePosition::Pre.into(),
tags: BTreeMap::from([
("owner".to_owned(), "John".to_owned()),
("id".to_owned(), "my-own-http-front".to_owned()),
]),
..Default::default()
};
let http_backend = AddBackend {
cluster_id: String::from("test"),
Expand Down
16 changes: 4 additions & 12 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,9 +1162,7 @@ mod tests {
address: "127.0.0.1:1024".to_string(),
hostname: String::from("localhost"),
path: PathRule::prefix(String::from("/")),
method: None,
position: RulePosition::Tree.into(),
tags: BTreeMap::new(),
..Default::default()
};
command
.write_message(&WorkerRequest {
Expand Down Expand Up @@ -1245,11 +1243,9 @@ mod tests {
let front = RequestHttpFrontend {
address: "127.0.0.1:1031".to_string(),
hostname: String::from("localhost"),
method: None,
path: PathRule::prefix(String::from("/")),
position: RulePosition::Tree.into(),
cluster_id: Some(String::from("cluster_1")),
tags: BTreeMap::new(),
..Default::default()
};
command
.write_message(&WorkerRequest {
Expand Down Expand Up @@ -1354,13 +1350,11 @@ mod tests {
});

let cluster = Cluster {
answer_503: None,
cluster_id: String::from("cluster_1"),
https_redirect: true,
load_balancing: LoadBalancingAlgorithms::default() as i32,
load_metric: None,
proxy_protocol: None,
sticky_session: false,
..Default::default()
};
command
.write_message(&WorkerRequest {
Expand All @@ -1371,11 +1365,9 @@ mod tests {
let front = RequestHttpFrontend {
address: "127.0.0.1:1041".to_string(),
hostname: String::from("localhost"),
method: None,
path: PathRule::prefix(String::from("/")),
position: RulePosition::Tree.into(),
cluster_id: Some(String::from("cluster_1")),
tags: BTreeMap::new(),
..Default::default()
};
command
.write_message(&WorkerRequest {
Expand Down

0 comments on commit b125338

Please sign in to comment.