| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import path from "path";
- import os from 'os';
- import { LdapAuthenticationConfiguration } from 'craftlab-auth/dist'
- export interface Configuration {
- port: number;
- slave: boolean;
- slaves: Array<string>;
- masterPubKey: string;
- masterPrivateKey: string;
- hostname: string;
- apiKeys: string[];
- ldapAuthentication: LdapAuthenticationConfiguration|null
- }
- class ConfigurationManagerLoader {
- public static Load(fileName: string): Configuration {
- let config = require(fileName);
- config.slaves = config.slaves || [];
- if (config.slave && config.slaves?.length)
- throw new Error("Cannot have slaves while beeing slave");
- if (config.slave && !config.masterPubKey)
- throw new Error("Missing master public key for slave. Run with --generate-masterkey get get one");
- if (config.slaves.length && !config.masterPrivateKey)
- throw new Error("Missing master private key for slaves. Run with --generate-masterkey get get one");
- return {
- port: config.port || 9090,
- slave: config.slave || false,
- slaves: config.slaves || new Array(),
- masterPubKey: config.masterPubKey || "",
- masterPrivateKey: config.masterPrivateKey || "",
- apiKeys: config.apiKeys || [],
- hostname: os.hostname(),
- ldapAuthentication: config.ldapAuthentication ? <LdapAuthenticationConfiguration>{
- bindDnField: config.ldapAuthentication.bindDnField,
- bindBase: config.ldapAuthentication.bindBase,
- ldapUrl: config.ldapAuthentication.ldapUrl,
- usernameField: config.ldapAuthentication.usernameField,
- ldapFilter: config.ldapAuthentication.ldapFilter
- } : null
- };
- }
- }
- let ConfigurationManager = ConfigurationManagerLoader.Load(path.join(__dirname, "../config.json"));
- export default ConfigurationManager;
|