Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "ldap-agent", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"author": "Julio Sansossio", | ||
"license": "ISC", | ||
"author": { | ||
"name": "Julio Sansossio", | ||
"url": "https://github.com/Sansossio" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"db", | ||
"database", | ||
"ldap", | ||
"data" | ||
], | ||
"devDependencies": { | ||
@@ -10,0 +19,0 @@ "eslint": "^4.9.0", |
255
README.md
# Ldap Agent | ||
Connected to ldap server | ||
Connected to ldap server | ||
## Install | ||
```sh | ||
npm install --save ldap-agent | ||
``` | ||
## Examples | ||
### Config file | ||
```json | ||
{ | ||
"cn": ["Manager"], | ||
"dc": ["maxcrc", "com"], | ||
"url": "ldap://127.0.0.1:389", | ||
"password": "123456" | ||
} | ||
``` | ||
### Add | ||
```js | ||
// Module | ||
const LdapAgent = require('../index'); | ||
// Config | ||
const config = require('./config.json'); | ||
// Init client | ||
const Client = new LdapAgent(config); | ||
/* Connection */ | ||
// With promise | ||
Client.Init() | ||
.then(() => { | ||
console.log('Connected to ldap server'); // Connected | ||
// Add entry | ||
const entry = { | ||
cn: 'foo', | ||
sn: 'bar', | ||
mail: 'sergio@telefonica.com', | ||
objectclass: [ | ||
'person', | ||
'organizationalPerson', | ||
'inetOrgPerson', | ||
], | ||
}; | ||
return Client.Add(['usuarios'], ['testFolder'], entry, 'mail'); // Send query | ||
}) | ||
.then((data) => { | ||
console.log('Field added:', data); // Query success | ||
}) | ||
.catch((errorGeneric) => { | ||
console.error(`Error generic: ${errorGeneric.message}`); | ||
}); | ||
``` | ||
### Connection (callback) | ||
```js | ||
// Module | ||
const LdapAgent = require('../index'); | ||
// Config | ||
const config = require('./config.json'); | ||
// Init client | ||
const Client = new LdapAgent(config); | ||
/* Connection */ | ||
Client.Init((connectError) => { | ||
// Error handler | ||
if (connectError) { | ||
console.error(`Error connection: ${connectError.message}`); | ||
return; | ||
} | ||
// Connection ready | ||
console.log('Connected to ldap server (callback)'); | ||
}); | ||
``` | ||
### Connection (promise) | ||
```js | ||
// Module | ||
const LdapAgent = require('../index'); | ||
// Config | ||
const config = require('./config.json'); | ||
// Init client | ||
const Client = new LdapAgent(config); | ||
/* Connection */ | ||
Client.Init() | ||
.then(() => { | ||
console.log('Connected to ldap server (promise)'); | ||
}) | ||
.catch((connectError) => { | ||
console.error(`Error connection: ${connectError.message}`); | ||
}); | ||
``` | ||
### Delete | ||
```js | ||
// Module | ||
const LdapAgent = require('../index'); | ||
// Config | ||
const config = require('./config.json'); | ||
// Init client | ||
const Client = new LdapAgent(config); | ||
/* Connection */ | ||
// With promise | ||
Client.Init() | ||
.then(() => { | ||
console.log('Connected to ldap server'); // Connected | ||
// Delete entry | ||
const condition = { | ||
mail: 'test@telefonica.com', | ||
}; | ||
return Client.Delete(condition, ['usuarios'], ['testFolder']); // Send query | ||
}) | ||
.then((data) => { | ||
console.log('Field deleted:', data); // Query success | ||
}) | ||
.catch((errorGeneric) => { | ||
console.error(`Error generic: ${errorGeneric.message}`); | ||
}); | ||
``` | ||
### Search all | ||
```js | ||
// Module | ||
const LdapAgent = require('../index'); | ||
// Config | ||
const config = require('./config.json'); | ||
// Init client | ||
const Client = new LdapAgent(config); | ||
/* Connection */ | ||
// With promise | ||
Client.Init() | ||
.then(() => { | ||
console.log('Connected to ldap server'); // Connected | ||
return Client.Find(['usuarios'], ['testFolder'], { attributes: 'sn' }); // Send query | ||
}) | ||
.then((data) => { | ||
console.log(`${data.length} fields found!`); // Query success | ||
}) | ||
.catch((errorGeneric) => { | ||
console.error(`Error generic: ${errorGeneric.message}`); | ||
}); | ||
``` | ||
### Search with one filter | ||
```js | ||
// Module | ||
const LdapAgent = require('../index'); | ||
// Config | ||
const config = require('./config.json'); | ||
// Init client | ||
const Client = new LdapAgent(config); | ||
/* Connection */ | ||
// With promise | ||
Client.Init() | ||
.then(() => { | ||
console.log('Connected to ldap server'); // Connected | ||
// Config | ||
const options = { | ||
attributes: 'sn', | ||
filter: { | ||
mail: 'test@telefonica.com', | ||
}, | ||
}; | ||
return Client.Find(['usuarios'], ['testFolder'], options); // Send query | ||
}) | ||
.then((data) => { | ||
console.log('Field found:', data); // Query success | ||
}) | ||
.catch((errorGeneric) => { | ||
console.error(`Error generic: ${errorGeneric.message}`); | ||
}); | ||
``` | ||
### Search two filters | ||
```js | ||
// Module | ||
const LdapAgent = require('../index'); | ||
// Config | ||
const config = require('./config.json'); | ||
// Init client | ||
const Client = new LdapAgent(config); | ||
/* Connection */ | ||
// With promise | ||
Client.Init() | ||
.then(() => { | ||
console.log('Connected to ldap server'); // Connected | ||
// Config | ||
const options = { | ||
attributes: 'sn', | ||
filter: { | ||
mail: '*@telefonica.com', | ||
sn: 'bar', | ||
}, | ||
}; | ||
return Client.Find(['usuarios'], ['testFolder'], options); // Send query | ||
}) | ||
.then((data) => { | ||
console.log('Fields found:', data.length); // Query success | ||
}) | ||
.catch((errorGeneric) => { | ||
console.error(`Error generic: ${errorGeneric.message}`); | ||
}); | ||
``` | ||
### Update values | ||
```js | ||
// Module | ||
const LdapAgent = require('../index'); | ||
// Config | ||
const config = require('./config.json'); | ||
// Init client | ||
const Client = new LdapAgent(config); | ||
/* Connection */ | ||
// With promise | ||
Client.Init() | ||
.then(() => { | ||
console.log('Connected to ldap server'); // Connected | ||
// Update params | ||
const update = { | ||
sn: 'New value', | ||
}; | ||
const where = { | ||
mail: 'test@telefonica.com', | ||
}; | ||
return Client.Update(update, where, ['usuarios'], ['testFolder']); // Send query | ||
}) | ||
.then((data) => { | ||
console.log('Field updated:', data); // Query success | ||
}) | ||
.catch((errorGeneric) => { | ||
console.error(`Error generic: ${errorGeneric.message}`); | ||
}); | ||
``` | ||
19532
256