name the function after its purpose: iter_locals -> get_local_users

merge-requests/254/head
Torsten Flammiger 3 years ago
parent 91eb6c4d08
commit c03bf6ef11

@ -129,20 +129,35 @@ impl Users {
/// and the function will log the error /// and the function will log the error
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn get_local_users(&self) -> Result<Vec<String>> { pub fn get_local_users(&self) -> Result<Vec<String>> {
self.userid_password let users: Vec<String> = self
.userid_password
.iter() .iter()
.filter(|(_, pw)| pw.len() > 0) .filter_map(|(username, pw)| self.get_username_on_valid_password(&username, &pw))
.map(|(username, _)| match utils::string_from_bytes(&username) { .collect();
Ok(s) => s, Ok(users)
Err(e) => { }
Error::bad_database(format!(
"Failed to parse username while calling get_local_users(): {}", /// A private helper to avoid double filtering the iterator
e.to_string() fn get_username_on_valid_password(&self, username: &[u8], password: &[u8]) -> Option<String> {
)); // A valid password is not empty
if password.len() > 0 {
match utils::string_from_bytes(username) {
Ok(u) => Some(u),
Err(_) => {
// TODO: add error cause!
// let msg: String = format!(
// "Failed to parse username while calling get_local_users(): {}",
// e.to_string()
// );
Error::bad_database(
"Failed to parse username while calling get_username_on_valid_password",
);
None None
} }
}) }
.collect::<Result<Vec<String>>>() } else {
None
}
} }
/// Returns the password hash for the given user. /// Returns the password hash for the given user.

Loading…
Cancel
Save