|
@@ -19,6 +19,7 @@ class ConfigManager {
|
|
|
this.configModel = configModel;
|
|
this.configModel = configModel;
|
|
|
this.configLoader = new ConfigLoader(this.configModel);
|
|
this.configLoader = new ConfigLoader(this.configModel);
|
|
|
this.configObject = null;
|
|
this.configObject = null;
|
|
|
|
|
+ this.configKeys = [];
|
|
|
|
|
|
|
|
this.getConfig = this.getConfig.bind(this);
|
|
this.getConfig = this.getConfig.bind(this);
|
|
|
}
|
|
}
|
|
@@ -29,6 +30,9 @@ class ConfigManager {
|
|
|
async loadConfigs() {
|
|
async loadConfigs() {
|
|
|
this.configObject = await this.configLoader.load();
|
|
this.configObject = await this.configLoader.load();
|
|
|
debug('ConfigManager#loadConfigs', this.configObject);
|
|
debug('ConfigManager#loadConfigs', this.configObject);
|
|
|
|
|
+
|
|
|
|
|
+ // cache all config keys
|
|
|
|
|
+ this.configKeys = this.getAllConfigKeys();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -52,14 +56,12 @@ class ConfigManager {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * get a config specified by namespace and prefix
|
|
|
|
|
|
|
+ * get a config specified by namespace and regular expresssion
|
|
|
*/
|
|
*/
|
|
|
- getConfigByPrefix(namespace, prefix) {
|
|
|
|
|
- const regexp = new RegExp(`^${prefix}:`);
|
|
|
|
|
- const keys = this.getAllKeys();
|
|
|
|
|
|
|
+ getConfigByRegExp(namespace, regexp) {
|
|
|
const result = {};
|
|
const result = {};
|
|
|
|
|
|
|
|
- for (const key of keys) {
|
|
|
|
|
|
|
+ for (const key of this.configKeys) {
|
|
|
if (regexp.test(key)) {
|
|
if (regexp.test(key)) {
|
|
|
result[key] = this.getConfig(namespace, key);
|
|
result[key] = this.getConfig(namespace, key);
|
|
|
}
|
|
}
|
|
@@ -68,10 +70,19 @@ class ConfigManager {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * get a config specified by namespace and prefix
|
|
|
|
|
+ */
|
|
|
|
|
+ getConfigByPrefix(namespace, prefix) {
|
|
|
|
|
+ const regexp = new RegExp(`^${prefix}:`);
|
|
|
|
|
+
|
|
|
|
|
+ return this.getConfigByRegExp(namespace, regexp);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* generate an array of config keys from this.configObject
|
|
* generate an array of config keys from this.configObject
|
|
|
*/
|
|
*/
|
|
|
- getAllKeys() {
|
|
|
|
|
|
|
+ getAllConfigKeys() {
|
|
|
// type: fromDB, fromEnvVars
|
|
// type: fromDB, fromEnvVars
|
|
|
const types = Object.keys(this.configObject);
|
|
const types = Object.keys(this.configObject);
|
|
|
let namespaces = [];
|
|
let namespaces = [];
|