-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from ConductorOne/ggreer/import
Add import script that works with any number of ldif files.
- Loading branch information
Showing
3 changed files
with
19 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euxo pipefail | ||
|
||
|
||
for filename in big-*.ldif; do | ||
[ -e "$filename" ] || continue | ||
ldapadd -D 'CN=admin,DC=example,DC=org' -N -x -H 'ldap://localhost:389/' -w admin -f "$filename" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,21 @@ const fs = require('node:fs'); | |
const userCount = 1000; | ||
const groupCount = 50; | ||
const maxFileSize = 2000000; // php ldap admin has a 2MB limit | ||
const usersPerGroup = 100; | ||
|
||
let fileSize = 0; | ||
let fileCount = 0; | ||
const baseFileName = "big-"; | ||
|
||
let f; | ||
let f = null; | ||
// Only pass strings that constitute full objects to write(). | ||
// Otherwise the object will span across multiple files and import will fail. | ||
function write (data, opts = {}) { | ||
fileSize += data.length; | ||
if (fileSize > maxFileSize) { | ||
fs.closeSync(f); | ||
if (f) { | ||
fs.closeSync(f); | ||
} | ||
fileSize = data.length; | ||
fileCount++; | ||
f = null; | ||
|
@@ -56,7 +59,7 @@ cn: testgroup${groupIdStr} | |
gidNumber: ${groupId} | ||
`; | ||
|
||
for (let userId = 0; userId < userCount; userId++) { | ||
for (let userId = 0; userId < usersPerGroup; userId++) { | ||
const userIdStr = ("00000" + userId).slice(-5); | ||
groupStr += `memberUid: testuser${userIdStr}@example.com | ||
`; | ||
|
@@ -75,7 +78,7 @@ cn: othertestgroup${groupIdStr} | |
owner: [email protected],dc=example,dc=org | ||
`; | ||
|
||
for (let userId = 0; userId < userCount; userId++) { | ||
for (let userId = 0; userId < usersPerGroup; userId++) { | ||
const userIdStr = ("00000" + userId).slice(-5); | ||
groupStr += `uniquemember: cn=testuser${userIdStr}@example.com,dc=example,dc=org | ||
`; | ||
|