Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor streaming_search_inner to return a Stream object #15

Merged
merged 13 commits into from
Oct 29, 2024
13 changes: 7 additions & 6 deletions Cargo.toml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the return type of a function warrants a major version bump.

PS. cargo-semver-checks is a pretty neat semver linter.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bumped major version

Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ readme = "README.md"
repository = "https://github.com/keaz/simple-ldap"
keywords = ["ldap", "ldap3", "async", "high-level"]
name = "simple-ldap"
version = "1.7.0"
version = "2.0.0"
edition = "2021"


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1.75"
async-trait = "0.1.83"
deadpool = "0.10.0"
ldap3 = { version = "0.11.3", default-features = false }
log = "0.4.20"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
futures = "0.3.31"
ldap3 = { version = "0.11.5", default-features = false }
log = "0.4.22"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"

[features]
default = ["ldap3/default"]
Expand Down
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,34 +129,35 @@ async fn main() -> Result<()> {
pool_size: 10,
dn_attribute: None,
};

let pool = pool::build_connection_pool(&ldap_config).await;
let ldap = pool.get_connection().await.unwrap();

let name_filter = EqFilter::from("cn".to_string(), "James".to_string());
let attra = vec!["cn", "sn", "uid"];
let result = ldap
.streaming_search(
"ou=people,dc=example,dc=com",
self::ldap3::Scope::OneLevel,
&name_filter,
2,
&attra,
)
.await;

let mut result = result.unwrap();
let mut count = 0;
loop {
match result.next::<User>().await {
Ok(StreamResult::Record(_)) => {
count += 1;
}
_ => {
break;

let pool = pool::build_connection_pool(&ldap_config).await;
let ldap = pool.get_connection().await.unwrap();

let name_filter = EqFilter::from("cn".to_string(), "James".to_string());
let attra = vec!["cn", "sn", "uid"];
let result = ldap
.streaming_search(
"ou=people,dc=example,dc=com",
self::ldap3::Scope::OneLevel,
&name_filter,
2,
&attra,
)
.await;
assert!(result.is_ok());
let mut result = result.unwrap();
let mut count = 0;
while let Some(record) = result.next().await {
match record {
Ok(record) => {
let _ = record.to_record::<User>().unwrap();
count += 1;
}
Err(_) => {
break;
}
}
}
}
assert!(count == 2);
Ok(ldap.unbind().await?)
}
Expand Down
71 changes: 52 additions & 19 deletions data/data.ldif
Original file line number Diff line number Diff line change
@@ -1,84 +1,117 @@
version: 1

dn: dc=example,dc=com
objectClass: domain
objectClass: top
objectClass: domain
dc: example
entryUUID: 724bddc1-a3d1-3d8d-b43c-ae7f3fa6954f

dn: ou=people,dc=example,dc=com
objectClass: organizationalUnit
objectClass: top
objectClass: organizationalUnit
ou: people
description: Users

entryUUID: eb8f50dc-6283-3541-a1b3-d0ac3cae9e28

dn: uid=f92f4cb2-e821-44a4-bb13-b8ebadf4ecc5,ou=people,dc=example,dc=com
objectClass: top
objectClass: inetorgperson
objectClass: organizationalPerson
objectClass: person
objectClass: top
cn: Sam
sn: Smith
cn: Sam
ou: people
uid: f92f4cb2-e821-44a4-bb13-b8ebadf4ecc5
entryUUID: d03a2650-afae-3e43-8fe6-3df3b486a8f9

dn: uid=42b05942-4f18-4279-827d-36534da1e437,ou=people,dc=example,dc=com
objectClass: top
objectClass: inetorgperson
objectClass: organizationalPerson
objectClass: person
objectClass: top
cn: James
sn: Gunn
cn: James
ou: people
uid: 42b05942-4f18-4279-827d-36534da1e437
entryUUID: b34503f5-c572-302c-a135-4f78665f0032

dn: uid=0dbaece8-f5f8-4e85-97d8-8bd614304bef,ou=people,dc=example,dc=com
objectClass: top
objectClass: inetorgperson
objectClass: organizationalPerson
objectClass: person
objectClass: top
cn: James
sn: Gunn
cn: James
ou: people
uid: 0dbaece8-f5f8-4e85-97d8-8bd614304bef
entryUUID: cb0bafca-46aa-3db4-9c3c-abab3a273a70

dn: uid=0xbaece8-f5f8-4e85-97d8-8bd614304bef,ou=people,dc=example,dc=com
objectClass: top
objectClass: inetorgperson
objectClass: organizationalPerson
objectClass: person
objectClass: top
cn: James
sn: Gunn
cn: James
ou: people
uid: 0xbaece8-f5f8-4e85-97d8-8bd614304bef
entryUUID: 352b9f11-3394-3bf1-857b-9d4df00bb4a4

dn: uid=e219fbc0-6df5-4bc3-a6ee-986843bb157e,ou=people,dc=example,dc=com
objectClass: top
objectClass: inetorgperson
objectClass: organizationalPerson
objectClass: person
objectClass: top
cn: Jhone
sn: Eliet
cn: Jhone
ou: people
uid: e219fbc0-6df5-4bc3-a6ee-986843bb157e
entryUUID: 158464c3-f19b-388d-856a-4bed06c24dcb

dn: uid=cb4bc91e-21d8-4bcc-bf6a-317b84c2e58b,ou=people,dc=example,dc=com
objectClass: top
objectClass: inetorgperson
objectClass: organizationalPerson
objectClass: person
objectClass: top
cn: David
sn: Hanks
cn: David
ou: people
uid: cb4bc91e-21d8-4bcc-bf6a-317b84c2e58b
entryUUID: 82b49fc0-c700-3b64-881a-7a9fb315ba85

dn: uid=4d9b08fe-9a14-4df0-9831-ea9992837f0d,ou=people,dc=example,dc=com
objectClass: top
objectClass: inetorgperson
objectClass: organizationalPerson
objectClass: person
objectClass: top
cn: David
sn: Hanks
cn: David
ou: people
uid: 4d9b08fe-9a14-4df0-9831-ea9992837f0d
entryUUID: 7036d8ba-8170-31d5-9f7f-38e11f63d13f

dn: ou=group,dc=example,dc=com
objectClass: top
objectClass: organizationalUnit
ou: group
description: Groups
createTimestamp: 20241011170327Z
creatorsName: cn=Directory Manager,cn=Root DNs,cn=config
entryUUID: 68d83ad5-29d5-4505-a58c-1ef19121683a

dn: cn=grp1,ou=group,dc=example,dc=com
objectClass: top
objectClass: groupOfNames
cn: grp1
member: uid=e219fbc0-6df5-4bc3-a6ee-986843bb157e,ou=people,dc=example,dc=com
createTimestamp: 20241011170342Z
creatorsName: cn=Directory Manager,cn=Root DNs,cn=config
entryUUID: 4618dc11-b54c-4db7-97f2-da09a33112e7

dn: cn=grp2,ou=group,dc=example,dc=com
objectClass: top
objectClass: groupOfNames
cn: grp2
member: uid=e219fbc0-6df5-4bc3-a6ee-986843bb157e,ou=people,dc=example,dc=com
createTimestamp: 20241011170356Z
creatorsName: cn=Directory Manager,cn=Root DNs,cn=config
entryUUID: 415d5386-3812-499c-a951-9a5945400ff8

Loading
Loading