Skip to content

Commit

Permalink
Use clippy with Rust 1.67.0 and format source code
Browse files Browse the repository at this point in the history
Signed-off-by: Florentin Dubois <florentin.dubois@clever-cloud.com>
  • Loading branch information
FlorentinDUBOIS committed Feb 6, 2023
1 parent d7e439b commit 384489c
Show file tree
Hide file tree
Showing 54 changed files with 482 additions and 569 deletions.
2 changes: 1 addition & 1 deletion bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
let variables = vec!["SOZU_CONFIG", "SOZU_PID_FILE_PATH"];
for variable in variables {
if let Ok(val) = env::var(variable) {
println!("cargo:rustc-env={}={}", variable, val);
println!("cargo:rustc-env={variable}={val}");
}
}
}
36 changes: 17 additions & 19 deletions bin/src/acme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn main(
let challenge = auth.http_challenge();
let challenge_token = challenge.http_token();

let path = format!("/.well-known/acme-challenge/{}", challenge_token);
let path = format!("/.well-known/acme-challenge/{challenge_token}");
let key_authorization = challenge.http_proof();
debug!(
"HTTP challenge token: {} key: {}",
Expand Down Expand Up @@ -175,12 +175,10 @@ pub fn main(
info!("challenge request answered");
// the challenge can be called multiple times
//return true;
} else {
if let Err(e) = request
.respond(Response::from_data(&b"not found"[..]).with_status_code(404))
{
error!("Error responding with 404 to request: {}", e);
}
} else if let Err(e) =
request.respond(Response::from_data(&b"not found"[..]).with_status_code(404))
{
error!("Error responding with 404 to request: {}", e);
}
}

Expand Down Expand Up @@ -266,7 +264,7 @@ fn generate_id() -> String {
.take(6)
.map(|c| c as char)
.collect();
format!("ID-{}", s)
format!("ID-{s}")
}

fn generate_app_id(app_id: &str) -> String {
Expand All @@ -275,7 +273,7 @@ fn generate_app_id(app_id: &str) -> String {
.take(6)
.map(|c| c as char)
.collect();
format!("{}-ACME-{}", app_id, s)
format!("{app_id}-ACME-{s}")
}

fn set_up_proxying(
Expand All @@ -289,7 +287,7 @@ fn set_up_proxying(
let add_http_front = ProxyRequestOrder::AddHttpFrontend(HttpFrontend {
route: Route::ClusterId(cluster_id.to_owned()),
hostname: String::from(hostname),
address: frontend.clone(),
address: *frontend,
path: PathRule::Prefix(path_begin.to_owned()),
method: None,
position: RulePosition::Tree,
Expand All @@ -300,7 +298,7 @@ fn set_up_proxying(

let add_backend = ProxyRequestOrder::AddBackend(Backend {
cluster_id: String::from(cluster_id),
backend_id: format!("{}-0", cluster_id),
backend_id: format!("{cluster_id}-0"),
address: server_address,
load_balancing_parameters: None,
sticky_id: None,
Expand All @@ -321,7 +319,7 @@ fn remove_proxying(
) -> anyhow::Result<()> {
let remove_http_front_order = ProxyRequestOrder::RemoveHttpFrontend(HttpFrontend {
route: Route::ClusterId(cluster_id.to_owned()),
address: frontend.clone(),
address: *frontend,
hostname: String::from(hostname),
path: PathRule::Prefix(path_begin.to_owned()),
method: None,
Expand All @@ -333,7 +331,7 @@ fn remove_proxying(

let remove_backend_order = ProxyRequestOrder::RemoveBackend(RemoveBackend {
cluster_id: String::from(cluster_id),
backend_id: format!("{}-0", cluster_id),
backend_id: format!("{cluster_id}-0"),
address: server_address,
});

Expand All @@ -352,17 +350,17 @@ fn add_certificate(
tls_versions: &Vec<TlsVersion>,
) -> anyhow::Result<()> {
let certificate = Config::load_file(certificate_path)
.with_context(|| format!("could not load certificate"))?;
.with_context(|| "could not load certificate".to_string())?;

let key = Config::load_file(key_path).with_context(|| format!("could not load key"))?;
let key = Config::load_file(key_path).with_context(|| "could not load key".to_string())?;

let certificate_chain = Config::load_file(chain_path)
.map(split_certificate_chain)
.with_context(|| format!("could not load certificate chain"))?;
.with_context(|| "could not load certificate chain".to_string())?;

let certificate_order = match old_fingerprint {
None => ProxyRequestOrder::AddCertificate(AddCertificate {
address: frontend.clone(),
address: *frontend,
certificate: CertificateAndKey {
certificate,
certificate_chain,
Expand All @@ -374,7 +372,7 @@ fn add_certificate(
}),

Some(f) => ProxyRequestOrder::ReplaceCertificate(ReplaceCertificate {
address: frontend.clone(),
address: *frontend,
new_certificate: CertificateAndKey {
certificate,
certificate_chain,
Expand Down Expand Up @@ -410,7 +408,7 @@ fn order_command(
.read_message()
.with_context(|| "Could not read response on channel")?;
if id != response.id {
panic!("received message with invalid id: {:?}", response);
panic!("received message with invalid id: {response:?}");
}
match response.status {
CommandStatus::Processing => {
Expand Down
7 changes: 3 additions & 4 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub enum LoggingLevel {
}
impl std::fmt::Display for LoggingLevel {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}

Expand Down Expand Up @@ -858,7 +858,7 @@ fn parse_tls_versions(i: &str) -> Result<TlsVersion, String> {
"TLSv1.1" => Ok(TlsVersion::TLSv1_1),
"TLSv1.2" => Ok(TlsVersion::TLSv1_2),
"TLSv1.3" => Ok(TlsVersion::TLSv1_2),
s => Err(format!("unrecognized TLS version: {}", s)),
s => Err(format!("unrecognized TLS version: {s}")),
}
}

Expand All @@ -870,8 +870,7 @@ fn parse_tags(string_to_parse: &str) -> Result<BTreeMap<String, String>, String>
tags.insert(key.to_owned(), value.to_owned());
} else {
return Err(format!(
"something went wrong while parsing the tags '{}'",
string_to_parse
"something went wrong while parsing the tags '{string_to_parse}'"
));
}
}
Expand Down
65 changes: 29 additions & 36 deletions bin/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,67 +145,62 @@ pub enum Success {
impl std::fmt::Display for Success {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::ClientClose(id) => write!(f, "Close client: {}", id),
Self::ClientNew(id) => write!(f, "New client successfully added: {}", id),
Self::ClientClose(id) => write!(f, "Close client: {id}"),
Self::ClientNew(id) => write!(f, "New client successfully added: {id}"),
Self::DumpState(_) => write!(f, "Successfully gathered state from the main process"),
Self::HandledClientRequest => write!(f, "Successfully handled the client request"),
Self::ListFrontends(_) => write!(f, "Successfully gathered the list of frontends"),
Self::ListListeners(_) => write!(f, "Successfully listed all listeners"),
Self::ListWorkers(_) => write!(f, "Successfully listed all workers"),
Self::LoadState(path, ok, error) => write!(
f,
"Successfully loaded state from path {}, {} ok messages, {} errors",
path, ok, error
),
Self::Logging(logging_filter) => write!(
f,
"Successfully set the logging level to {}",
logging_filter
"Successfully loaded state from path {path}, {ok} ok messages, {error} errors"
),
Self::Logging(logging_filter) => {
write!(f, "Successfully set the logging level to {logging_filter}")
}
Self::Metrics(metrics_cfg) => {
write!(f, "Successfully set the metrics to {:?}", metrics_cfg)
write!(f, "Successfully set the metrics to {metrics_cfg:?}")
}
Self::MasterStop => write!(f, "stopping main process"),
Self::NotifiedClient(id) => {
write!(f, "Successfully notified client {} of the advancement", id)
write!(f, "Successfully notified client {id} of the advancement")
}
Self::PropagatedWorkerEvent => {
write!(f, "Sent worker response to all subscribing clients")
}
Self::Query(_) => write!(f, "Ran the query successfully"),
Self::ReloadConfiguration(ok, error) => write!(
f,
"Successfully reloaded configuration, ok: {}, errors: {}",
ok, error
"Successfully reloaded configuration, ok: {ok}, errors: {error}"
),
Self::SaveState(counter, path) => {
write!(f, "saved {} config messages to {}", counter, path)
write!(f, "saved {counter} config messages to {path}")
}
Self::Status(_) => {
write!(f, "Sent a status response to client")
}
Self::SubscribeEvent(client_id) => {
write!(f, "Successfully Added {} to subscribers", client_id)
write!(f, "Successfully Added {client_id} to subscribers")
}
Self::UpgradeMain(pid) => write!(
f,
"new main process launched with pid {}, closing the old one",
pid
"new main process launched with pid {pid}, closing the old one"
),
Self::UpgradeWorker(id) => {
write!(f, "Successfully upgraded worker with new id: {}", id)
write!(f, "Successfully upgraded worker with new id: {id}")
}
Self::WorkerKilled(id) => write!(f, "Successfully killed worker {}", id),
Self::WorkerLaunched(id) => write!(f, "Successfully launched worker {}", id),
Self::WorkerKilled(id) => write!(f, "Successfully killed worker {id}"),
Self::WorkerLaunched(id) => write!(f, "Successfully launched worker {id}"),
Self::WorkerOrder(worker) => match worker {
Some(worker_id) => {
write!(f, "Successfully executed the order on worker {}", worker_id)
write!(f, "Successfully executed the order on worker {worker_id}")
}
None => write!(f, "Successfully executed the order on all workers"),
},
Self::WorkerResponse => write!(f, "Successfully handled worker response"),
Self::WorkerRestarted(id) => write!(f, "Successfully restarted worker {}", id),
Self::WorkerStopped(id) => write!(f, "Successfully stopped worker {}", id),
Self::WorkerRestarted(id) => write!(f, "Successfully restarted worker {id}"),
Self::WorkerStopped(id) => write!(f, "Successfully stopped worker {id}"),
}
}
}
Expand Down Expand Up @@ -658,7 +653,7 @@ impl CommandServer {
&self.state,
listeners,
)
.with_context(|| format!("Could not start new worker {}", new_worker_id))?;
.with_context(|| format!("Could not start new worker {new_worker_id}"))?;

info!("created new worker: {}", new_worker_id);
self.next_worker_id += 1;
Expand Down Expand Up @@ -691,16 +686,13 @@ impl CommandServer {
let mut orders = self.state.generate_activate_orders();
for (count, order) in orders.drain(..).enumerate() {
new_worker
.send(
format!("RESTART-{}-ACTIVATE-{}", new_worker_id, count),
order,
)
.send(format!("RESTART-{new_worker_id}-ACTIVATE-{count}"), order)
.await;
}

new_worker
.send(
format!("RESTART-{}-STATUS", new_worker_id),
format!("RESTART-{new_worker_id}-STATUS"),
ProxyRequestOrder::Status,
)
.await;
Expand Down Expand Up @@ -747,7 +739,7 @@ impl CommandServer {
}
}
}
bail!(format!("Could not find worker {}", id))
bail!(format!("Could not find worker {id}"))
}

async fn handle_worker_response(
Expand All @@ -763,12 +755,13 @@ impl CommandServer {
let event = CommandResponse::new(
response.id.to_string(),
CommandStatus::Processing,
format!("{}", worker_id),
format!("{worker_id}"),
Some(CommandResponseContent::Event(event.clone())),
);
client_tx.send(event).await.with_context(|| {
format!("could not send message to client {}", client_id)
})?
client_tx
.send(event)
.await
.with_context(|| format!("could not send message to client {client_id}"))?
}
}
return Ok(Success::PropagatedWorkerEvent);
Expand Down Expand Up @@ -825,7 +818,7 @@ pub fn start_server(
if fs::metadata(&path).is_ok() {
info!("A socket is already present. Deleting...");
fs::remove_file(&path)
.with_context(|| format!("could not delete previous socket at {:?}", path))?;
.with_context(|| format!("could not delete previous socket at {path:?}"))?;
}

let unix_listener = match UnixListener::bind(&path) {
Expand Down Expand Up @@ -929,7 +922,7 @@ async fn accept_clients(
};
let (client_tx, client_rx) = channel(10000);

let client_id = format!("CL-{}", counter);
let client_id = format!("CL-{counter}");

smol::spawn(client_loop(
client_id.clone(),
Expand Down

0 comments on commit 384489c

Please sign in to comment.