-
Notifications
You must be signed in to change notification settings - Fork 7
/
ctldap-config.js
59 lines (55 loc) · 2.2 KB
/
ctldap-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* ctldap - ChurchTools LDAP-Wrapper 3.0
* @copyright 2017-2023 Michael Lux
* @licence GNU/GPL v3.0
*/
import { readYamlEnvSync } from "yaml-env-defaults";
import { CtldapSite } from "./ctldap-site.js";
export class CtldapConfig {
/**
* CtldapConfig constructor.
*/
constructor() {
const yaml = readYamlEnvSync('./ctldap.yml');
const config = yaml.config;
this.trace = CtldapConfig.asOptionalBool(config.trace);
this.debug = this.trace || CtldapConfig.asOptionalBool(config.debug);
this.ldapIp = config.ldapIp;
this.ldapPort = config.ldapPort;
if (typeof config.cacheLifetime !== 'number' && isNaN(config.cacheLifetime)) {
this.cacheLifetime = 300000; // 5 minutes
} else {
this.cacheLifetime = Number(config.cacheLifetime);
}
this.ldapUser = config.ldapUser;
this.ldapPassword = config.ldapPassword;
this.ctUri = config.ctUri;
this.apiToken = config.apiToken;
this.specialGroupMappings = config.specialGroupMappings || {};
this.dnLowerCase = CtldapConfig.asOptionalBool(config.dnLowerCase);
this.emailLowerCase = CtldapConfig.asOptionalBool(config.emailLowerCase);
this.emailsUnique = CtldapConfig.asOptionalBool(config.emailsUnique);
this.ldapCertFilename = config.ldapCertFilename;
this.ldapKeyFilename = config.ldapKeyFilename;
this.ldapBaseDn = config.ldapBaseDn;
// Configure sites
const sites = yaml.sites || {};
// If ldapBaseDn is set, create a site from the global config properties.
if (config.ldapBaseDn) {
sites[config.ldapBaseDn] = {
ldapUser: config.ldapUser,
ldapPassword: config.ldapPassword,
ctUri: config.ctUri,
apiToken: config.apiToken,
specialGroupMappings: config.specialGroupMappings
}
}
this.sites = Object.keys(sites).map((siteName) => new CtldapSite(this, siteName, sites[siteName]));
}
static asOptionalBool (val) {
if (val === undefined) {
return undefined;
}
return (val || 'false').toLowerCase() !== 'false';
}
}