Skip to content

Commit

Permalink
Merge pull request #15 from keaz/streaming-search-that-returns-a-stream
Browse files Browse the repository at this point in the history
Refactor streaming_search_inner to return a Stream object
  • Loading branch information
keaz authored Oct 29, 2024
2 parents b7637a7 + 20bda5d commit 839ea08
Show file tree
Hide file tree
Showing 7 changed files with 589 additions and 205 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI for Rust LDAP Client

on:
push:
branches:
- '*'
- '!main'

jobs:
build:
runs-on: ubuntu-latest

services:
ldap:
image: openidentityplatform/opendj
ports:
- 1389:1389
options: >
--env ROOT_USER_DN="cn=manager"
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get LDAP container ID
id: ldap_container_id
run: echo "LDAP_CONTAINER_ID=$(docker ps --filter 'ancestor=openidentityplatform/opendj:latest' -q)" >> $GITHUB_ENV

- name: Copy LDIF to LDAP container
run: docker cp ./data/data.ldif ${{ env.LDAP_CONTAINER_ID }}:/tmp/data.ldif

- name: Import LDIF into OpenDJ
run: |
docker exec ${{ job.services.ldap.id }} \
/opt/opendj/bin/ldapmodify -h localhost -p 1389 -D "cn=manager" -w password -a -f /tmp/data.ldif
# Step 3: Install Rust
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal

# Step 4: Build the Rust project
- name: Build
run: cargo build --verbose

# Step 5: Run unit tests
- name: Run tests
run: cargo test --verbose


55 changes: 55 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Publish to crates.io

on:
push:
branches:
- 'main'

jobs:
build:
runs-on: ubuntu-latest

services:
ldap:
image: openidentityplatform/opendj
ports:
- 1389:1389
options: >
--env ROOT_USER_DN="cn=manager"
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get LDAP container ID
id: ldap_container_id
run: echo "LDAP_CONTAINER_ID=$(docker ps --filter 'ancestor=openidentityplatform/opendj:latest' -q)" >> $GITHUB_ENV

- name: Copy LDIF to LDAP container
run: docker cp ./data/data.ldif ${{ env.LDAP_CONTAINER_ID }}:/tmp/data.ldif

- name: Import LDIF into OpenDJ
run: |
docker exec ${{ job.services.ldap.id }} \
/opt/opendj/bin/ldapmodify -h localhost -p 1389 -D "cn=manager" -w password -a -f /tmp/data.ldif
# Step 3: Install Rust
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal

# Step 4: Build the Rust project
- name: Build
run: cargo build --verbose

# Step 5: Run unit tests
- name: Run tests
run: cargo test --verbose

- name: Deploy to crates.io
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_TOKEN }}
22 changes: 0 additions & 22 deletions .github/workflows/rust.yml

This file was deleted.

13 changes: 7 additions & 6 deletions Cargo.toml
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.6.1"
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
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

A ldap client library that wraps [ldap3](https://github.com/inejge/ldap3) to make it easy to use.

### Status of the project
Currently this is in early alpha stage. Library only support use asynchronously.
![CI](https://github.com/keaz/simple-ldap/actions/workflows/ci.yml/badge.svg)
[![Crates.io](https://img.shields.io/crates/v/simple-ldap)](https://crates.io/crates/simple-ldap)
[![Documentation](https://docs.rs/simple-ldap/badge.svg)](https://docs.rs/simple-ldap)

## Usage
```
Expand Down Expand Up @@ -129,24 +130,37 @@ async fn main() -> Result<()> {
pool_size: 10,
dn_attribute: None,
};
let pool = pool::build_connection_pool(&ldap_config).await;
let mut ldap = pool.pool.get_connection().await.unwrap();

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::<User>(
.streaming_search(
"ou=people,dc=example,dc=com",
self::ldap3::Scope::OneLevel,
&name_filter,
2,
vec!["cn", "sn", "uid"],
&attra,
)
.await;
assert!(result.is_ok());
let result = result.unwrap();
assert!(result.len() == 2);
Ok(ldap.unbind().await?)
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(result.cleanup().await?)
}
```

Expand Down
61 changes: 30 additions & 31 deletions data/data.ldif
Original file line number Diff line number Diff line change
@@ -1,84 +1,83 @@
version: 1

dn: dc=example,dc=com
objectClass: domain
objectClass: top
dc: example

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


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

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

dn: uid=0dbaece8-f5f8-4e85-97d8-8bd614304bef,ou=people,dc=example,dc=com
objectClass: inetorgperson
objectClass: organizationalPerson
objectClass: person
objectClass: top
cn: James
sn: Gunn
cn: James
ou: people
uid: 0dbaece8-f5f8-4e85-97d8-8bd614304bef
uid: 42b05942-4f18-4279-827d-36534da1e437

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

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

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

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

dn: ou=group,dc=example,dc=com
objectClass: top
objectClass: organizationalUnit
ou: group
description: Groups

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

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
Loading

0 comments on commit 839ea08

Please sign in to comment.