1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-12-29 09:34:38 +01:00

Updated function documentation

This commit is contained in:
Torsten Flammiger 2022-01-16 20:15:53 +01:00
parent 9205c07048
commit 3e79d15495

View file

@ -125,28 +125,27 @@ impl Users {
/// Returns a list of local users as list of usernames. /// Returns a list of local users as list of usernames.
/// ///
/// A user account is considered `local` if the length of it's password /// A user account is considered `local` if the length of it's password is greater then zero.
/// is greater then zero.
/// If utils::string_from_bytes returns an error that username will be skipped
#[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>> {
let users: Vec<String> = self let users: Vec<String> = self
.userid_password .userid_password
.iter() .iter()
.filter_map(|(username, pw)| self.get_username_on_valid_password(&username, &pw)) .filter_map(|(username, pw)| self.get_username_with_valid_password(&username, &pw))
.collect(); .collect();
Ok(users) Ok(users)
} }
/// A private helper to avoid double filtering the iterator /// A private helper to avoid double filtering the iterator in get_local_users().
/// If utils::string_from_bytes(...) returns an error that username will be skipped
/// and the error will be logged. TODO: add error cause.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
fn get_username_on_valid_password(&self, username: &[u8], password: &[u8]) -> Option<String> { fn get_username_with_valid_password(&self, username: &[u8], password: &[u8]) -> Option<String> {
// A valid password is not empty // A valid password is not empty
if password.len() > 0 { if password.len() > 0 {
match utils::string_from_bytes(username) { match utils::string_from_bytes(username) {
Ok(u) => Some(u), Ok(u) => Some(u),
Err(_) => { Err(_) => {
// TODO: add error cause!
// let msg: String = format!( // let msg: String = format!(
// "Failed to parse username while calling get_local_users(): {}", // "Failed to parse username while calling get_local_users(): {}",
// e.to_string() // e.to_string()