From d536addf0af498fec12dd7f081bec8444009c160 Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Tue, 9 Aug 2022 09:44:32 +0200 Subject: [PATCH] migration-tool: misc cleanup --- migration-tool/src/ldap.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/migration-tool/src/ldap.rs b/migration-tool/src/ldap.rs index 8beec7a..f4f5c9d 100644 --- a/migration-tool/src/ldap.rs +++ b/migration-tool/src/ldap.rs @@ -131,7 +131,7 @@ fn bind_ldap( }; if let Err(e) = ldap_connection .simple_bind(&binddn, &password) - .and_then(|r| r.success()) + .and_then(ldap3::LdapResult::success) { println!("Error connecting as '{}': {}", binddn, e); bind_ldap(ldap_connection, Some(binddn)) @@ -150,12 +150,11 @@ impl TryFrom for User { .attrs .get(attr) .ok_or_else(|| anyhow!("Missing {} for user", attr)) - .and_then(|u| { - if u.len() > 1 { - Err(anyhow!("Too many {}s", attr)) - } else { - Ok(u.first().unwrap().to_owned()) - } + .and_then(|u| -> Result { + u.iter() + .next() + .map(String::to_owned) + .ok_or_else(|| anyhow!("Too many {}s", attr)) }) }; let id = get_required_attribute("uid") @@ -170,13 +169,8 @@ impl TryFrom for User { .attrs .get(attr) .and_then(|v| v.first().map(|s| s.as_str())) - .and_then(|s| { - if s.is_empty() { - None - } else { - Some(s.to_owned()) - } - }) + .filter(|s| !s.is_empty()) + .map(str::to_owned) }; let last_name = get_optional_attribute("sn").or_else(|| get_optional_attribute("surname")); let display_name = get_optional_attribute("cn")