Skip to content

Commit

Permalink
kill matchEgCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Mar 17, 2019
1 parent e0c4c12 commit cb37447
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 191 deletions.
15 changes: 0 additions & 15 deletions lib/conditions/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const express = require('express');
const chalk = require('chalk');
const logger = require('../logger').policy;
const schemas = require('../schemas');
Expand All @@ -25,20 +24,6 @@ function register({ name, handler, schema }) {

function init() {
predefined.forEach(register);

// extending express.request
express.request.matchEGCondition = function (conditionConfig) {
logger.debug(`matchEGCondition for ${conditionConfig.name}`);
const func = conditions[conditionConfig.name];

if (!func) {
logger.warn(`Condition not found for ${conditionConfig.name}`);
return null;
}

return func(conditionConfig)(this);
};

return { register };
}

Expand Down
20 changes: 11 additions & 9 deletions lib/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const eventBus = require('../eventBus');
const schemas = require('../schemas');

class Config {
constructor () {
constructor() {
this.models = {};

this.configTypes = {
Expand All @@ -29,7 +29,7 @@ class Config {
};
}

loadConfig (type) {
loadConfig(type) {
const configType = this.configTypes[type];
let configPath = this[configType.pathProperty] || path.join(process.env.EG_CONFIG_DIR, `${configType.baseFilename}.yml`);
let config;
Expand Down Expand Up @@ -59,9 +59,9 @@ class Config {
log.debug(`ConfigPath: ${configPath}`);
}

loadGatewayConfig () { this.loadConfig('gateway'); }
loadGatewayConfig() { this.loadConfig('gateway'); }

loadModels () {
loadModels() {
['users.json', 'credentials.json', 'applications.json'].forEach(model => {
const module = path.resolve(process.env.EG_CONFIG_DIR, 'models', model);
const name = path.basename(module, '.json');
Expand All @@ -71,7 +71,9 @@ class Config {
});
}

watch () {
watch() {
if (typeof this.systemConfigPath !== 'string' || typeof this.gatewayConfigPath !== 'string') { return; }

const watchEvents = ['add', 'change'];

const watchOptions = {
Expand All @@ -96,15 +98,15 @@ class Config {
});
}

unwatch () {
unwatch() {
this.watcher && this.watcher.close();
}

updateGatewayConfig (modifier) {
updateGatewayConfig(modifier) {
return this._updateConfigFile('gateway', modifier);
}

_updateConfigFile (type, modifier) {
_updateConfigFile(type, modifier) {
const configType = this.configTypes[type];
const path = this[configType.pathProperty];

Expand Down Expand Up @@ -166,7 +168,7 @@ class Config {
// Kindly borrowed from https://github.com/macbre/optimist-config-file/blob/master/lib/envvar-replace.js
// Thanks a lot guys 🙌

function envReplace (str, vars) {
function envReplace(str, vars) {
return str.replace(/\$?\$\{([A-Za-z0-9_]+)(:-(.*?))?\}/g, function (varStr, varName, _, defValue) {
// Handle escaping:
if (varStr.indexOf('$$') === 0) {
Expand Down
Loading

0 comments on commit cb37447

Please sign in to comment.