Skip to content

Commit

Permalink
simplify parse_admin_password
Browse files Browse the repository at this point in the history
  • Loading branch information
carneiro-cw committed Dec 20, 2024
1 parent 99c3f03 commit 10e42b5
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/eth/rpc/rpc_http_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,16 @@ impl Authentication {

/// Checks if the provided admin password is correct
fn parse_admin_password(headers: &HeaderMap<HeaderValue>) -> Authentication {
let Ok(real_pass) = std::env::var("ADMIN_PASSWORD") else {
return Authentication::Admin;
let real_pass = match std::env::var("ADMIN_PASSWORD") {
Ok(pass) if !pass.is_empty() => pass,
_ => return Authentication::Admin,
};
if real_pass.is_empty() {
return Authentication::Admin;
}
let Some(value) = headers.get("Authorization") else {
return Authentication::None;
};
let Ok(value) = value.to_str() else { return Authentication::None };
let Some(password) = value.strip_prefix("Password ") else {
return Authentication::None;
};
if real_pass == password {
Authentication::Admin
} else {
Authentication::None

match headers.get("Authorization")
.and_then(|val| val.to_str().ok())
.and_then(|val| val.strip_prefix("Password ")) {
Some(password) if password == real_pass => Authentication::Admin,
_ => Authentication::None,
}
}

Expand Down

0 comments on commit 10e42b5

Please sign in to comment.