ad-promise
Advanced tools
Comparing version 1.1.0 to 1.2.0
module.exports = { | ||
Name : "AdCall", | ||
MaxCallsAtOnce : 5000 | ||
chunks : null, | ||
members : 200 | ||
} |
@@ -10,4 +10,4 @@ | ||
const User = require('../../models/user'); | ||
const maxPromises = require('limitpromises'); | ||
const maxPromiseConfig = require('../../configs/config.maxPromiseGroup'); | ||
const limitpromises = require('limitpromises'); | ||
const maxPromiseConfig = require('../../configs/config.maxPromiseGroup'); | ||
@@ -26,3 +26,3 @@ const chunkItem = function(members, opts, self) { | ||
filter = '(&(|(objectCategory=User)(objectCategory=Group))(|' + filter + '))'; | ||
var localOpts = { | ||
@@ -34,38 +34,47 @@ filter: filter, | ||
}; | ||
search.call(self, localOpts, async function onSearch(err, members){ | ||
if (err) { | ||
reject(err); | ||
} | ||
// If no members have been found resolve immidiately | ||
if(!members || members.length === 0) return resolve([]); | ||
let usersResolved = maxPromises(member => { | ||
return new Promise( (resolve, reject) => { | ||
if(member){ | ||
if(!member.groupType){ | ||
let user = new User(pickAttributes(member, (opts || {}).attributes || defaultAttributes.user)); | ||
self.emit(user); | ||
users.push(user); | ||
resolve(user); | ||
} else { | ||
self.getUsersForGroup(opts, member.cn).then(nestedUsers => { | ||
users = [].concat(users,nestedUsers); | ||
resolve(); | ||
}, err => { | ||
// Ignore ECONNRESET errors; | ||
if ((err || {}).errno !== 'ECONNRESET') { | ||
reject(err); | ||
} | ||
}); | ||
} | ||
// We need to limit the Searches. Too many of them will cause timeouts. the more calls the more performant | ||
// but the more risk you'll get timeout errors | ||
let searchResults = limitpromises(() => { | ||
return new Promise((resolve, reject) => { | ||
search.call(self, localOpts, function onSearch(err, members){ | ||
if(err){ | ||
return reject(err) | ||
} | ||
}); | ||
}, members, 100, "members"); | ||
return resolve(members) | ||
}) | ||
}) | ||
}, [members], self.opts.maxSearchesAtOnce || maxPromiseConfig.members, "members"); | ||
try{ | ||
await Promise.all(usersResolved.map( userResolved => { return userResolved.promiseFunc })); | ||
resolve(users); | ||
} catch(err) { | ||
reject(err); | ||
} | ||
Promise.all(searchResults.map(res => {return res.promiseFunc})).then(async Members =>{ | ||
Members = Members[0]; | ||
let nestedUsersArr = []; | ||
for(let i in Members){ | ||
let member = Members[i]; | ||
if(member){ | ||
if(!member.groupType){ | ||
let user = new User(pickAttributes(member, (opts || {}).attributes || defaultAttributes.user)); | ||
self.emit(user); | ||
users.push(user); | ||
} else { | ||
let nestedUsers = self.getUsersForGroup(opts, member.cn); | ||
nestedUsersArr.push(nestedUsers); | ||
} | ||
} | ||
} | ||
Promise.all(nestedUsersArr).then(AllNestedUsers => { | ||
for(let i in AllNestedUsers){ | ||
users = [].concat(users, AllNestedUsers[i]); | ||
} | ||
return resolve(users); | ||
}, err => { | ||
return reject(err) | ||
}); | ||
}, err => { | ||
return reject(err); | ||
}); | ||
}); | ||
@@ -72,0 +81,0 @@ } |
@@ -9,3 +9,4 @@ var _ = require('underscore'); | ||
const defaultAttributes = require('../configs/config.defaultAttributes'); | ||
const maxPromises = require('limitpromises'); | ||
const limitPromises = require('limitpromises'); | ||
const maxPromiseConfig = require('../configs/config.maxPromiseGroup'); | ||
@@ -69,6 +70,6 @@ /** | ||
// Chunks represent the cn for each user; | ||
// We use the maxPromises Function which will limit the number of promises running at the same time. | ||
// We use the limitPromises Function which will limit the number of promises running at the same time. | ||
// This is necessary to avoid that the socket of the AD is in use and thus cannot be accessed | ||
if(!chunks || chunks.length === 0) return resolve([]); | ||
let allChunks = maxPromises(Chunk => { | ||
let allChunks = limitPromises(Chunk => { | ||
return new Promise((resolve, reject) => { | ||
@@ -84,3 +85,3 @@ chunkItem(Chunk, opts, self).then(members => { | ||
}); | ||
}, chunks, 1000000, "chunks"); | ||
}, chunks, maxPromiseConfig.chunks, "chunks"); | ||
@@ -87,0 +88,0 @@ |
{ | ||
"author": "Relief Melone (relief.melone@gmail.com)", | ||
"name": "ad-promise", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "This is a fork of the gheeres node-activedirectory. This is still a work in progress and not stable. The goal to use promises instead of the async library which is causing some problems in the current version of node-activedirectory", | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -26,3 +26,5 @@ AD-Promise for Node | ||
* [bunyan](https://github.com/trentm/node-bunyan) - A simple and fast JSON logging module for node.js services | ||
* [limitpromises](https://github.com/relief-melone/limitpromises) - lightweight module for making sure you only run a limited number of promises at once | ||
* [limitpromises](https://github.com/relief-melone/limitpromises) - lightweight module for making sure you only run a limited number | ||
of promises at once. Originally the async library was used instead of limitpromises. But as it does not limit how many async calls | ||
will be made at once which will make you run into problems if you have very larger AD-Groups (10k+ users) | ||
@@ -66,2 +68,3 @@ Installation | ||
* [findDeletedObjects](#findDeletedObjects) | ||
* [maxSearchesAtOnce](#maxSearchesAtOnce) | ||
@@ -753,2 +756,21 @@ --------------------------------------- | ||
<a name="authenticate" /> | ||
### maxSearchesAtOnce | ||
Originally node-activedirectory does not limit how many searches will be sent via LDAP parallel. This will cause problems with | ||
very large AD-Groups (10k+ users). ad-promise will limit this to 200 searches which seems to be a good trade off between performance | ||
and stability. You can however change this value if you want to. You can set the parameter like this | ||
```js | ||
var ActiveDirectory = require('ad-promise'); | ||
var config = { | ||
url: 'ldap://dc.domain.com', | ||
baseDN: 'dc=domain,dc=com', | ||
username: 'username@domain.com', | ||
password: 'password', | ||
maxSearchesAtOnce: 3000 | ||
} | ||
var ad = new ActiveDirectory(config); | ||
``` | ||
------------------------------------------------ | ||
@@ -755,0 +777,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
214640
4150
778