diff --git a/Cargo.toml b/Cargo.toml index cb708a7..c2aa92d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,8 @@ license = "GPL-3.0-or-later" repository = "https://git.candifloss.cc/candifloss/ldap-kit.git" [workspace.dependencies] -anyhow = "1.0.102" -clap = { version = "4.6.1", features = ["derive"] } +anyhow = "1.0.104" +clap = { version = "4.6.4", features = ["derive"] } ldap3 = "0.12.1" -serde = { version = "1.0.228", features = ["derive"] } -toml = "1.1.2" +serde = { version = "1.0.229", features = ["derive"] } +toml = "1.1.4" diff --git a/crates/ldap/Cargo.toml b/crates/ldap/Cargo.toml index ba5d159..9c9ad6e 100644 --- a/crates/ldap/Cargo.toml +++ b/crates/ldap/Cargo.toml @@ -6,3 +6,6 @@ license.workspace = true repository.workspace = true [dependencies] +anyhow.workspace = true +config = { version = "0.1.0", path = "../config" } +ldap3.workspace = true diff --git a/crates/ldap/src/client.rs b/crates/ldap/src/client.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/ldap/src/lib.rs b/crates/ldap/src/lib.rs index b93cf3f..1227be5 100644 --- a/crates/ldap/src/lib.rs +++ b/crates/ldap/src/lib.rs @@ -1,14 +1,5 @@ -pub fn add(left: u64, right: u64) -> u64 { - left + right -} +mod client; +mod user; -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} +//pub use client::LdapClient; +pub use user::User; \ No newline at end of file diff --git a/crates/ldap/src/user.rs b/crates/ldap/src/user.rs new file mode 100644 index 0000000..295d021 --- /dev/null +++ b/crates/ldap/src/user.rs @@ -0,0 +1,31 @@ +//! LDAP user. + +use std::collections::HashMap; + +/// LDAP user entry. +#[derive(Debug, Clone)] +pub struct User { + /// Distinguished Name. + pub dn: String, + + /// LDAP attributes. + /// + /// Keys are attribute names. + /// Values contain all values of that attribute. + pub attributes: HashMap>, +} + +impl User { + /// Return the first value of an attribute. + pub fn attribute(&self, name: &str) -> Option<&str> { + self.attributes + .get(name) + .and_then(|values| values.first()) + .map(String::as_str) + } + + /// Check whether an attribute exists. + pub fn has_attribute(&self, name: &str) -> bool { + self.attributes.contains_key(name) + } +} \ No newline at end of file