-
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.
- Loading branch information
Showing
4 changed files
with
164 additions
and
64 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
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 |
---|---|---|
@@ -1,65 +1,114 @@ | ||
const log = require('./logging') | ||
const log = require('./logging'); | ||
const YAML = require('yamljs'); | ||
const ctservice = require('./ctservice') | ||
const transform = require('./transform') | ||
const ldapcache = require('./ldapcache') | ||
const ldapserver = require('./ldapserver') | ||
const ctservice = require('./ctservice'); | ||
const transform = require('./transform'); | ||
const ldapcache = require('./ldapcache'); | ||
const ldapserver = require('./ldapserver'); | ||
|
||
log.loglevel = log.loglevels.debug | ||
log.loglevel = log.loglevels.debug; | ||
|
||
const initCache = async (site, getChurchToolsDataFunc, authChurchToolsFunc) => { | ||
|
||
const adminuser = transform.getAdmin(site.ldap.admincn, site.ldap.dc) | ||
const adminuser = transform.getAdmin(site.ldap.admincn, site.ldap.dc); | ||
|
||
const siteCacheFunctions = ldapcache.init( | ||
site.site.name, | ||
transform.getRootObj(site.ldap.dc, site.ldap.admin, site.ldap.o), | ||
adminuser, | ||
site.site.name, | ||
transform.getRootObj(site.ldap.dc, site.ldap.admin, site.ldap.o), | ||
adminuser, | ||
site.ldap.password, | ||
authChurchToolsFunc | ||
) | ||
const churchtoolsdata = await getChurchToolsDataFunc(site.selectionGroupIds, site.tranformedGroups, site.site) | ||
const {users,groups} = transform.getLdapData(site, churchtoolsdata, adminuser) | ||
|
||
siteCacheFunctions.setData(users,groups) | ||
return siteCacheFunctions | ||
} | ||
); | ||
const churchtoolsdata = await getChurchToolsDataFunc( | ||
site.selectionGroupIds, | ||
site.tranformedGroups, | ||
site.site | ||
); | ||
const { users, groups } = transform.getLdapData( | ||
site, | ||
churchtoolsdata, | ||
adminuser | ||
); | ||
|
||
const updateLdapServerData = (siteldap) => { | ||
// Todo implement an update strategy | ||
} | ||
siteCacheFunctions.setData(users, groups); | ||
return siteCacheFunctions; | ||
}; | ||
|
||
const updateSiteData = ( | ||
site, | ||
getChurchToolsDataFunc, | ||
siteCacheFunctionsSetData | ||
) => { | ||
return new Promise(async (resolve) => { | ||
log.infoSite(site.site, 'Updating data from Church Tools'); | ||
const data = await getChurchToolsDataFunc( | ||
site.selectionGroupIds, | ||
site.tranformedGroups, | ||
site.site | ||
); | ||
const adminuser = transform.getAdmin(site.ldap.admincn, site.ldap.dc); | ||
const ldap = transform.getLdapData(site, data, adminuser); | ||
siteCacheFunctionsSetData(ldap.users, ldap.groups); | ||
resolve(); | ||
}); | ||
}; | ||
|
||
exports.getConfig = (file) => { | ||
return YAML.load(file) | ||
} | ||
return YAML.load(file); | ||
}; | ||
|
||
exports.ldapjs = {} | ||
exports.ldapjs = {}; | ||
|
||
exports.start = async (config, getChurchToolsDataFunc, authWithChurchToolsFunc, callback) => { | ||
log.info("Starting up CCF Ldap wrapper for ChurchTools ....") | ||
this.ldapjs = ldapserver.getLdapServer(config.server) | ||
exports.start = async ( | ||
config, | ||
getChurchToolsDataFunc, | ||
authWithChurchToolsFunc, | ||
callback | ||
) => { | ||
log.info('Starting up CCF Ldap wrapper for ChurchTools ....'); | ||
const updaters = new Map(); | ||
this.ldapjs = ldapserver.getLdapServer(config.server); | ||
|
||
for (const [key, value] of Object.entries(config.sites)) { | ||
const site = value; | ||
log.debugSite(site.site, "Get and transform data from ChurchTools") | ||
const cacheFunctions = await initCache(site, getChurchToolsDataFunc, authWithChurchToolsFunc(site)) | ||
await this.ldapjs.initSite(site, cacheFunctions) | ||
log.debugSite(site.site, 'Get and transform data from ChurchTools'); | ||
const cacheFunctions = await initCache( | ||
site, | ||
getChurchToolsDataFunc, | ||
authWithChurchToolsFunc(site) | ||
); | ||
await this.ldapjs.initSite(site, cacheFunctions); | ||
updaters.set( | ||
site.site.name, | ||
() => updateSiteData(site, getChurchToolsDataFunc, cacheFunctions.setData) | ||
); | ||
} | ||
log.debug('Done initializing data'); | ||
this.ldapjs.startUp(callback); | ||
return { | ||
updaters, | ||
stop: () => this.ldapjs.stopServer(), | ||
restart: (cb) => { | ||
this.ldapjs.stopServer(); | ||
this.ldapjs.startUp(cb); | ||
}, | ||
}; | ||
}; | ||
|
||
log.debug("Done initializing data") | ||
this.ldapjs.startUp(callback) | ||
return (cb) => { | ||
this.ldapjs.stopServer(); | ||
this.ldapjs.startUp(cb) | ||
exports.update = async (updaters) => { | ||
for await (const value of updaters.values()) { | ||
await value(); | ||
} | ||
} | ||
}; | ||
|
||
exports.snapshot = async (site) => { | ||
const data = await ctservice.getChurchToolsData(site.selectionGroupIds, site.tranformedGroups, site.site) | ||
const adminuser = transform.getAdmin(site.ldap.admincn, site.ldap.dc) | ||
const ldap = transform.getLdapData(site, data, adminuser) | ||
const data = await ctservice.getChurchToolsData( | ||
site.selectionGroupIds, | ||
site.tranformedGroups, | ||
site.site | ||
); | ||
const adminuser = transform.getAdmin(site.ldap.admincn, site.ldap.dc); | ||
const ldap = transform.getLdapData(site, data, adminuser); | ||
return { | ||
data, | ||
ldap | ||
} | ||
} | ||
ldap, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,14 +1,59 @@ | ||
const chai = require("chai"); | ||
const chai = require('chai'); | ||
const deepEqualInAnyOrder = require('deep-equal-in-any-order'); | ||
chai.use(deepEqualInAnyOrder); | ||
const expect = chai.expect | ||
const main = require('../src/main') | ||
const expect = chai.expect; | ||
const main = require('../src/main'); | ||
const log = require('../src/logging'); | ||
const ldapcache = require('../src/ldapcache'); | ||
|
||
describe("Transorm Production data to Ldap", () => { | ||
it("Equals Snapshot", () => { | ||
const expected = require('../production/config.json') | ||
const actual = main.getConfig('./production/config.yml') | ||
describe('Main: Production data to Ldap', () => { | ||
before(() => { | ||
log.logger.level = 'debug'; | ||
}); | ||
it('Equals Snapshot', () => { | ||
const expected = require('../production/config.json'); | ||
const actual = main.getConfig('./production/config.yml'); | ||
expect(actual).to.deep.equalInAnyOrder(expected); | ||
}) | ||
it("updates every - interval", () => {} ) | ||
}); | ||
xit('updates - on event (usualy triggerd by timer)', async () => { | ||
const config = require('../production/config.json'); | ||
const data = { | ||
groups: [{ id: 1, guid: '1', name: 'group' }], | ||
persons: [ | ||
{ | ||
id: 2, | ||
guid: '2', | ||
firstName: 'Peter', | ||
lastName: 'Pan', | ||
nickname: '', | ||
street: '', | ||
mobile: '', | ||
phonePrivate: '', | ||
zip: '', | ||
city: '', | ||
cmsuserid: '', | ||
email: '', | ||
ncuid: '', | ||
}, | ||
], | ||
memberships: [{ personId: 2, groupId: 1 }], | ||
}; | ||
const {updaters, stop} = await main.start( | ||
config, | ||
async () => data, // data func mock | ||
() => {}, // pasword check mock | ||
() => { log.debug("Started") } // server started cb | ||
); | ||
|
||
data.persons[0].lastName = 'Lustig'; | ||
data.groups[0].name = 'updated'; | ||
|
||
// simulate timer | ||
await main.update(updaters) | ||
|
||
expect(ldapcache.getUserById('ccf', 2).attributes.sn).to.equal('Lustig'); | ||
expect(ldapcache.getGroupById('ccf', 1).attributes.cn).to.equal('updated'); | ||
|
||
// test works but doesnot finsch - is in some async wait thing | ||
}); | ||
}); |