mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
migration-tool: misc cleanup
This commit is contained in:
parent
2ca083541e
commit
d536addf0a
@ -131,7 +131,7 @@ fn bind_ldap(
|
|||||||
};
|
};
|
||||||
if let Err(e) = ldap_connection
|
if let Err(e) = ldap_connection
|
||||||
.simple_bind(&binddn, &password)
|
.simple_bind(&binddn, &password)
|
||||||
.and_then(|r| r.success())
|
.and_then(ldap3::LdapResult::success)
|
||||||
{
|
{
|
||||||
println!("Error connecting as '{}': {}", binddn, e);
|
println!("Error connecting as '{}': {}", binddn, e);
|
||||||
bind_ldap(ldap_connection, Some(binddn))
|
bind_ldap(ldap_connection, Some(binddn))
|
||||||
@ -150,12 +150,11 @@ impl TryFrom<ResultEntry> for User {
|
|||||||
.attrs
|
.attrs
|
||||||
.get(attr)
|
.get(attr)
|
||||||
.ok_or_else(|| anyhow!("Missing {} for user", attr))
|
.ok_or_else(|| anyhow!("Missing {} for user", attr))
|
||||||
.and_then(|u| {
|
.and_then(|u| -> Result<String> {
|
||||||
if u.len() > 1 {
|
u.iter()
|
||||||
Err(anyhow!("Too many {}s", attr))
|
.next()
|
||||||
} else {
|
.map(String::to_owned)
|
||||||
Ok(u.first().unwrap().to_owned())
|
.ok_or_else(|| anyhow!("Too many {}s", attr))
|
||||||
}
|
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
let id = get_required_attribute("uid")
|
let id = get_required_attribute("uid")
|
||||||
@ -170,13 +169,8 @@ impl TryFrom<ResultEntry> for User {
|
|||||||
.attrs
|
.attrs
|
||||||
.get(attr)
|
.get(attr)
|
||||||
.and_then(|v| v.first().map(|s| s.as_str()))
|
.and_then(|v| v.first().map(|s| s.as_str()))
|
||||||
.and_then(|s| {
|
.filter(|s| !s.is_empty())
|
||||||
if s.is_empty() {
|
.map(str::to_owned)
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(s.to_owned())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
let last_name = get_optional_attribute("sn").or_else(|| get_optional_attribute("surname"));
|
let last_name = get_optional_attribute("sn").or_else(|| get_optional_attribute("surname"));
|
||||||
let display_name = get_optional_attribute("cn")
|
let display_name = get_optional_attribute("cn")
|
||||||
|
Loading…
Reference in New Issue
Block a user