New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

devebot

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

devebot - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

lib/services/sandbox-manager.js

2

index.js

@@ -16,3 +16,3 @@ 'use strict';

var config = configLoader(appRootPath + '/config');
var configDevebot = config.SYSTEM.devebot || {port: 17779};
var configDevebot = config.system.default.devebot || {port: 17779};

@@ -19,0 +19,0 @@ config.APPINFO = appinfoLoader(appRootPath);

@@ -6,42 +6,11 @@ 'use strict';

var ElasticsearchHelper = require('../helpers/elasticsearch-helper.js');
var MongodbHelper = require('../helpers/mongodb-helper.js');
var SandboxManager = require('../services/sandbox-manager.js');
var ContextManager = require('../services/context-manager.js');
var ServiceManager = require('../services/service-manager.js');
var JobqueueAdapter = require('../services/jobqueue-adapter.js');
var MongodbTrigger = require('../triggers/mongodb-trigger.js');
var constx = require('../utils/constx.js');
var logger = require('../utils/logger.js');
function init(params) {
var elasticsearchHelper = new ElasticsearchHelper({
configuration: params.SERVER
});
var mongodbHelper = new MongodbHelper({
configuration: params.SERVER
});
var sandboxManager = new SandboxManager(params);
var contextManager = new ContextManager({
configuration: params.SERVER
});
var serviceManager = new ServiceManager({
configuration: params.SERVER
});
var jobqueueAdapter = new JobqueueAdapter({
configuration: params.SERVER,
contextManager: contextManager,
serviceManager: serviceManager
});
var mongodbTrigger = new MongodbTrigger({
configuration: params.SERVER,
jobqueueAdapter: jobqueueAdapter
});
mongodbTrigger.start();
var controller = {};

@@ -54,2 +23,19 @@

{
name: constx.CMDSET.SANDBOX_INFO,
description: 'Display the sandbox information (how many sandboxes, current sandbox name)',
options: []
},
{
name: constx.CMDSET.SANDBOX_USE,
description: 'Set the current sandbox to interaction',
options: [
{
abbr: 'n',
name: 'name',
description: 'Name of the new current sandbox',
required: true
}
]
},
{
name: constx.CMDSET.SYSTEM_INFO,

@@ -72,2 +58,7 @@ description: 'Display the system information (configuration, mongodb, elasticsearch, ...)',

{
name: constx.CMDSET.ES_INFO,
description: 'Display the elasticsearch information (settings, mappings)',
options: []
},
{
name: constx.CMDSET.ES_CLEAR,

@@ -89,3 +80,3 @@ description: 'Destroy all of current elasticsearch data/structure',

name: constx.CMDSET.ES_INDEX_ENTITY,
description: 'Indexing all of data from MongoDB to Elasticsearch',
description: 'Indexing all documents of an entity from MongoDB to Elasticsearch',
options: [

@@ -143,3 +134,29 @@ {

var elasticsearchHelper = sandboxManager.getSandbox('elasticsearchHelper');
var mongodbHelper = sandboxManager.getSandbox('mongodbHelper');
var jobqueueAdapter = sandboxManager.getSandbox('jobqueueAdapter');
switch(cmd.command) {
case constx.CMDSET.SANDBOX_INFO:
promixe = Promise.resolve({
currentContext: sandboxManager.getCurrentContext(),
elasticsearchHelper: elasticsearchHelper,
mongodbHelper: mongodbHelper,
jobqueueAdapter: jobqueueAdapter
});
finishSimpleCommand(promixe, socket);
break;
case constx.CMDSET.SANDBOX_USE:
var sandboxName = cmd.options['name'];
if (sandboxManager.isValidContext(sandboxName)) {
sandboxManager.setCurrentContext(sandboxName);
promixe = Promise.resolve({ currentContext: sandboxName });
} else {
promixe = Promise.reject('context_name_is_invalid');
}
finishSimpleCommand(promixe, socket);
break;
case constx.CMDSET.SYSTEM_INFO:

@@ -160,2 +177,10 @@ promixe = Promise.all([

case constx.CMDSET.ES_INFO:
promixe = Promise.all([
elasticsearchHelper.getIndexSettings(),
elasticsearchHelper.getIndexMappings()
]);
finishSimpleCommand(promixe, socket);
break;
case constx.CMDSET.ES_CLEAR:

@@ -162,0 +187,0 @@ promixe = elasticsearchHelper.dropIndex();

@@ -15,7 +15,13 @@ 'use strict';

params = params || {};
self.config = lodash.pick(params.configuration || {}, ['elasticsearch']);
var es_conf = self.config['elasticsearch'] || {};
var config = lodash.pick(params.configuration || {}, ['elasticsearch']);
var es_conf = config['elasticsearch'] || {};
self.es_url = util.format('%s://%s:%s/', es_conf.protocol || 'http', es_conf.host, es_conf.port);
self.es_index_url = self.es_url + es_conf.name + '/';
self.es_structure = es_conf.structure;
self.getSandboxName = function() {
return params.contextname;
};
};

@@ -34,6 +40,6 @@

if (err) {
logger.trace(' ->> request to cluster/stats is error: %s', err);
logger.trace('<%s> - request to cluster/stats is error: %s', self.getSandboxName(), err);
reject(err);
} else {
logger.trace(' ->> elasticsearch cluster is good: %s', res.status);
logger.trace('<%s> - elasticsearch cluster is good: %s', self.getSandboxName(), res.status);
resolve(res.body);

@@ -52,10 +58,10 @@ }

if (err) {
logger.trace(' ->> request to index is error: %s', err);
logger.trace('<%s> - request to index is error: %s', self.getSandboxName(), err);
reject(404);
} else {
if (res.status >= 400) {
logger.trace(' ->> index is not exist: %s', res.status);
logger.trace('<%s> - index is not exist: %s', self.getSandboxName(), res.status);
reject(res.status);
} else {
logger.trace(' ->> index is exist: %s', res.status);
logger.trace('<%s> - index is exist: %s', self.getSandboxName(), res.status);
resolve();

@@ -68,2 +74,41 @@ }

Service.prototype.getIndexSettings = function() {
var self = this;
return new Promise(function(resolve, reject) {
superagent
.get(self.es_index_url + '_settings')
.type(constx.MIME_JSON)
.accept(constx.MIME_JSON)
.end(function(err, res) {
if (err) {
logger.trace('<%s> - request to index/_settings is error: %s', self.getSandboxName(), err);
reject(err);
} else {
logger.trace('<%s> - success on getting index/_settings: %s', self.getSandboxName(), res.status);
resolve(res.body);
}
});
});
};
Service.prototype.getIndexMappings = function() {
var self = this;
return new Promise(function(resolve, reject) {
superagent
.get(self.es_index_url + '_mappings')
.type(constx.MIME_JSON)
.accept(constx.MIME_JSON)
.end(function(err, res) {
if (err) {
logger.trace('<%s> - request to index/_mappings is error: %s', self.getSandboxName(), err);
reject(err);
} else {
logger.trace('<%s> - success on getting index/_mappings: %s', self.getSandboxName(), res.status);
resolve(res.body);
}
});
});
};
Service.prototype.dropIndex = function() {

@@ -78,7 +123,7 @@ var self = this;

if (err) {
logger.trace(' ->> Error on drop index: %s', err);
logger.trace('<%s> - Error on drop index: %s', self.getSandboxName(), err);
reject(err);
} else {
var result = res.body;
logger.trace(' ->> Result of drop index: %s', JSON.stringify(result, null, 2));
logger.trace('<%s> - Result of drop index: %s', self.getSandboxName(), JSON.stringify(result, null, 2));
resolve();

@@ -92,3 +137,2 @@ }

var self = this;
var index_structure = self.config['elasticsearch'].structure;
return new Promise(function(resolve, reject) {

@@ -99,10 +143,10 @@ superagent

.accept(constx.MIME_JSON)
.send(index_structure)
.send(self.es_structure)
.end(function(err, res) {
if (err) {
logger.trace(' ->> Error on init index: %s', err);
logger.trace('<%s> - Error on init index: %s', self.getSandboxName(), err);
reject(err);
} else {
var result = res.body;
logger.trace(' ->> Result of index init: ' + JSON.stringify(result, null, 2));
logger.trace('<%s> - Result of index init: %s', self.getSandboxName(), JSON.stringify(result, null, 2));
resolve();

@@ -135,9 +179,9 @@ }

if (err) {
logger.trace(' ->> request to %s type is error: %s', type, err);
logger.trace('<%s> - request to %s type is error: %s', self.getSandboxName(), type, err);
done(404);
} else if (res.status >= 400) {
logger.trace(' ->> %s type is not exist: %s', type, res.status);
logger.trace('<%s> - %s type is not exist: %s', self.getSandboxName(), type, res.status);
done(res.status);
} else {
logger.trace(' ->> %s type is exist: %s', type, res.status);
logger.trace('<%s> - %s type is exist: %s', self.getSandboxName(), type, res.status);
done(null);

@@ -158,7 +202,7 @@ }

if (err) {
logger.trace(' ->> Error on delete elasticsearch type %s: %s', type, err);
logger.trace('<%s> - Error on delete elasticsearch type %s: %s', self.getSandboxName(), type, err);
reject(err);
} else {
var result = res.body;
logger.trace(' ->> Result of elasticsearch %s deletion: %s', type, JSON.stringify(result, null, 2));
logger.trace('<%s> - Result of elasticsearch %s deletion: %s', self.getSandboxName(), type, JSON.stringify(result, null, 2));
resolve();

@@ -174,3 +218,3 @@ }

mapping[type] = self.config['elasticsearch'].structure.mappings[type];
mapping[type] = self.es_structure.mappings[type];

@@ -185,7 +229,7 @@ return new Promise(function(resolve, reject) {

if (err) {
logger.trace(' ->> Error on mapping type %s: %s', type, err);
logger.trace('<%s> - Error on mapping type %s: %s', self.getSandboxName(), type, err);
reject(err);
} else {
var result = res.body;
logger.trace(' ->> Success on mapping type %s: %s', type, JSON.stringify(result, null, 2));
logger.trace('<%s> - Success on mapping type %s: %s', self.getSandboxName(), type, JSON.stringify(result, null, 2));
resolve();

@@ -213,3 +257,3 @@ }

return Promise.promisify(function(done) {
logger.trace(' -> find %s documents with queryObject: %s', type, JSON.stringify(queryObject));
logger.trace('<%s> + find %s documents with queryObject: %s', self.getSandboxName(), type, JSON.stringify(queryObject));
superagent

@@ -222,7 +266,7 @@ .post(self.es_index_url + type + '/_search')

if (err) {
logger.trace(' ->> Error on %s document finding: %s', type, err);
logger.trace('<%s> - Error on %s document finding: %s', self.getSandboxName(), type, err);
done(err, null);
} else {
var result = res.body;
logger.trace(' ->> Success on %s document finding: %s', type, JSON.stringify(result, null, 2));
logger.trace('<%s> - Success on %s document finding: %s', self.getSandboxName(), type, JSON.stringify(result, null, 2));
done(null, result);

@@ -241,9 +285,9 @@ }

if (err) {
logger.trace(' ->> request to document %s of %s type is error: %s', documentId, type, err);
logger.trace('<%s> - request to document %s of %s type is error: %s', self.getSandboxName(), documentId, type, err);
done(500);
} else if (res.status >= 400) {
logger.trace(' ->> Document %s of %s type is not exist: %s', documentId, type, res.status);
logger.trace('<%s> - Document %s of %s type is not exist: %s', self.getSandboxName(), documentId, type, res.status);
done(res.status);
} else {
logger.trace(' ->> Document %s of %s type is exist: %s', documentId, type, res.status);
logger.trace('<%s> - Document %s of %s type is exist: %s', self.getSandboxName(), documentId, type, res.status);
done(null);

@@ -258,3 +302,3 @@ }

return Promise.promisify(function(done) {
logger.trace(' -> %s document will be inserted: %s', type, JSON.stringify(document));
logger.trace('<%s> + %s document will be inserted: %s', self.getSandboxName(), type, JSON.stringify(document));
superagent

@@ -267,7 +311,7 @@ .put(self.es_index_url + type + '/' + document._id)

if (err) {
logger.trace(' ->> Error on %s document inserting: %s', type, err);
logger.trace('<%s> - Error on %s document inserting: %s', self.getSandboxName(), type, err);
done(err, null);
} else {
var result = res.body;
logger.trace(' ->> Success on %s document inserting: %s', type, JSON.stringify(result, null, 2));
logger.trace('<%s> - Success on %s document inserting: %s', self.getSandboxName(), type, JSON.stringify(result, null, 2));
done(null, result);

@@ -282,3 +326,3 @@ }

return Promise.promisify(function(done) {
logger.trace(' -> %s document will be updated: %s', type, JSON.stringify(document));
logger.trace('<%s> + %s document will be updated: %s', self.getSandboxName(), type, JSON.stringify(document));

@@ -294,7 +338,7 @@ superagent

if (err) {
logger.trace(' ->> Error on %s document updating: %s', type, err);
logger.trace('<%s> - Error on %s document updating: %s', self.getSandboxName(), type, err);
done(err);
} else {
var result = res.body;
logger.trace(' ->> Success on %s document updating: %s', type, JSON.stringify(result, null, 2));
logger.trace('<%s> - Success on %s document updating: %s', self.getSandboxName(), type, JSON.stringify(result, null, 2));
done(null, result);

@@ -309,3 +353,3 @@ }

return Promise.promisify(function(done) {
logger.trace(' -> %s document will be deleted: %s', type, JSON.stringify(document));
logger.trace('<%s> + %s document will be deleted: %s', self.getSandboxName(), type, JSON.stringify(document));
superagent

@@ -317,7 +361,7 @@ .del(self.es_index_url + type + '/' + document._id)

if (err) {
logger.trace(' ->> Error on %s document deleting: %s', type, err);
logger.trace('<%s> - Error on %s document deleting: %s', self.getSandboxName(), type, err);
done(err, null);
} else {
var result = res.body;
logger.trace(' ->> Success on %s document deleting: %s', type, JSON.stringify(result, null, 2));
logger.trace('<%s> - Success on %s document deleting: %s', self.getSandboxName(), type, JSON.stringify(result, null, 2));
done(null, result);

@@ -324,0 +368,0 @@ }

@@ -17,9 +17,13 @@ 'use strict';

self.config = lodash.pick(params.configuration || {}, ['mongodb']);
var mongo_conf = self.config['mongodb'] || {};
var config = lodash.pick(params.configuration || {}, ['mongodb']);
var mongo_conf = config['mongodb'] || {};
var mongo_connection_string = util.format('mongodb://%s:%s/%s',
mongo_conf.host, mongo_conf.port, mongo_conf.name);
self.mongo_cols = mongo_conf.cols;
self.mongodb = mongojs(mongo_connection_string, lodash.values(self.mongo_cols));
self.getSandboxName = function() {
return params.contextname;
};
};

@@ -51,7 +55,7 @@

if (err) {
logger.error(' + findOneDocument("%s", "%s") has error: %s', entity,
JSON.stringify(criteria), JSON.stringify(err));
logger.error('<%s> - findOneDocument("%s", "%s") has error: %s', self.getSandboxName(),
entity, JSON.stringify(criteria), JSON.stringify(err));
} else {
logger.trace(' + findOneDocument("%s", "%s") result: %s', entity,
JSON.stringify(criteria), JSON.stringify(obj));
logger.trace('<%s> - findOneDocument("%s", "%s") result: %s', self.getSandboxName(),
entity, JSON.stringify(criteria), JSON.stringify(obj));
}

@@ -77,5 +81,7 @@ callback(err, obj);

if (err) {
logger.error(' + getDocumentById("%s", "%s") has error: %s', entity, id, JSON.stringify(err));
logger.error('<%s> - getDocumentById("%s", "%s") has error: %s', self.getSandboxName(),
entity, id, JSON.stringify(err));
} else {
logger.trace(' + getDocumentById("%s", "%s") result: %s', entity, id, JSON.stringify(obj));
logger.trace('<%s> - getDocumentById("%s", "%s") result: %s', self.getSandboxName(),
entity, id, JSON.stringify(obj));
}

@@ -89,4 +95,4 @@ callback(err, obj);

var self = this;
logger.trace(' + getDocumentsByIds("%s", "%s")', entityName,
JSON.stringify(documentIds));
logger.trace('<%s> + getDocumentsByIds("%s", "%s")', self.getSandboxName(),
entityName, JSON.stringify(documentIds));

@@ -114,7 +120,7 @@ return Promise.promisify(function(callback) {

if (err) {
logger.error(' + getDocumentsByIds("%s", "%s") has error: %s', entityName,
JSON.stringify(documentIds), JSON.stringify(err));
logger.error('<%s> - getDocumentsByIds("%s", "%s") has error: %s', self.getSandboxName(),
entityName, JSON.stringify(documentIds), JSON.stringify(err));
} else {
logger.trace(' + getDocumentsByIds("%s", "%s") result: %s', entityName,
JSON.stringify(documentIds), JSON.stringify(objs));
logger.trace('<%s> - getDocumentsByIds("%s", "%s") result: %s', self.getSandboxName(),
entityName, JSON.stringify(documentIds), JSON.stringify(objs));
}

@@ -191,6 +197,6 @@ callback(err, objs);

if (err) {
logger.trace(' - > insert documents %s of %s error: %s',
logger.trace('<%s> - insert documents %s of %s error: %s', self.getSandboxName(),
JSON.stringify(documents), entity, err);
} else {
logger.trace(' - > insert documents %s of %s successful: ',
logger.trace('<%s> - insert documents %s of %s successful: ', self.getSandboxName(),
JSON.stringify(documents), entity, JSON.stringify(result));

@@ -209,6 +215,6 @@ }

if (err) {
logger.trace(' - update %s document: %s with options %s and criteria %s has error: %s',
logger.trace('<%s> - update %s document: %s with options %s and criteria %s has error: %s', self.getSandboxName(),
entity, JSON.stringify(data), JSON.stringify(options), JSON.stringify(criteria), err);
} else {
logger.trace(' - update %s document: %s with options %s and criteria %s successul: %s',
logger.trace('<%s> - update %s document: %s with options %s and criteria %s successul: %s', self.getSandboxName(),
entity, JSON.stringify(data), JSON.stringify(options), JSON.stringify(criteria), JSON.stringify(info));

@@ -227,6 +233,6 @@ }

if (err) {
logger.trace(' - delete %s document with criteria %s has error: %s',
logger.trace('<%s> - delete %s document with criteria %s has error: %s', self.getSandboxName(),
entityName, JSON.stringify(criteria), err);
} else {
logger.trace(' - delete %s document with criteria %s result: %s',
logger.trace('<%s> - delete %s document with criteria %s result: %s', self.getSandboxName(),
entityName, JSON.stringify(criteria), JSON.stringify(result));

@@ -233,0 +239,0 @@ }

@@ -7,44 +7,69 @@ 'use strict';

var fileutil = require('../utils/fileutil.js');
var chores = require('../utils/chores.js');
var logger = require('../utils/logger.js');
var loader = require('../utils/loader.js');
var NODE_ENV = process.env.NODE_DEVEBOT_ENV || process.env.NODE_ENV;
function init(configDir) {
var config = init.loadConfig(configDir);
init.deriveConfig(config.SERVER);
var config = init.loadContext(configDir);
return config;
}
init.loadConfig = function(configDir) {
init.loadContext = function(configDir) {
var config = {};
var configDefaultDir = path.join(__dirname, '../../config');
configDir = configDir || configDefaultDir;
logger.trace(' * CONFIG is loading from folder [%s] ...', configDir);
var files = fileutil.listConfigFiles(configDefaultDir);
logger.trace(' * list of config filenames: %s', JSON.stringify(files));
var contextFiles = chores.listFiles(configDir);
var contextArray = lodash.map(contextFiles, function(file) {
return file.split('.');
});
files.forEach(function(file) {
var configName = file.replace('.js', '').toUpperCase();
var defaultFile = path.join(configDefaultDir, file);
var defaultConfigDir = path.join(__dirname, '../../config');
var defaultFiles = chores.listFiles(defaultConfigDir);
defaultFiles.forEach(function(file) {
var configName = file.replace('.js', '');
var defaultFile = path.join(defaultConfigDir, file);
var customFile = path.join(configDir, file);
config[configName] = {};
config[configName]['default'] = lodash.defaultsDeep(loader(customFile), require(defaultFile));
logger.trace(' + load the default config: %s', defaultFile);
logger.trace(' - load the custom config: %s', customFile);
config[configName] = lodash.defaultsDeep(loader(customFile), require(defaultFile));
logger.debug(' - Config object (default): %s', JSON.stringify(config));
if (!lodash.isEmpty(NODE_ENV)) {
var customFileEnv = path.join(configDir, file.replace('.js', '') + '.' + NODE_ENV + '.js');
logger.trace(' - load the environment config: %s', customFileEnv);
config[configName] = lodash.defaultsDeep(loader(customFileEnv), config[configName]);
var includeNames = [];
if (lodash.isString(process.env.NODE_DEVEBOT_CTX) && process.env.NODE_DEVEBOT_CTX.length > 0) {
includeNames = process.env.NODE_DEVEBOT_CTX.split(',');
}
var contextNames = lodash.filter(contextArray, function(item) {
var found = (item.length == 3) &&
(item[0] == configName) &&
(item[1].length > 0) &&
(item[2] == 'js');
if (includeNames.length > 0) {
found = found && (lodash.indexOf(includeNames, item[1]) >= 0);
}
return found;
});
config[configName]['context'] ={};
lodash.forEach(contextNames, function(contextItem) {
var contextFile = path.join(configDir, contextItem.join('.'));
logger.trace(' - load the environment config: %s', contextFile);
var contextCfg = lodash.defaultsDeep(loader(contextFile), config[configName]['default']);
if (!(contextCfg.disabled)) {
var contextName = contextItem[1];
config[configName]['context'][contextName] = contextCfg;
if (configName == 'server') {
init.deriveConfig(config[configName]['context'][contextName]);
}
}
});
});
logger.trace(' * CONFIG object: %s', JSON.stringify(config, null, 2));
logger.debug(' * Config object (expanded): %s', JSON.stringify(config));
logger.trace(' * CONFIG load done!');
return config;

@@ -51,0 +76,0 @@ };

@@ -13,9 +13,12 @@ 'use strict';

var Service = function(params) {
var self = this;
params = params || {};
logger.trace(' * create a jobqueue-adapter instance with parameters %s',
JSON.stringify(params));
var self = this;
var config = params.configuration || {};
self.getSandboxName = function() {
return params.contextname;
};
logger.trace('<%s> + create a jobqueue-adapter instance', self.getSandboxName());
var jobqueueWorker = new JobqueueWorker(params);

@@ -35,5 +38,5 @@

job.on('enqueue', function(params) {
job.on('enqueue', function(queueName) {
logger.trace(constx.JOB.MSG_ON_EVENT['enqueue'],
routine, operation, entity, JSON.stringify(document), JSON.stringify(arguments));
self.getSandboxName(), routine, operation, entity, JSON.stringify(document), JSON.stringify(arguments));
if (inspectors.ws) {

@@ -47,3 +50,3 @@ inspectors.ws.send(JSON.stringify({

logger.trace(constx.JOB.MSG_ON_EVENT['progress'],
routine, operation, entity, JSON.stringify(document), progress, JSON.stringify(data));
self.getSandboxName(), routine, operation, entity, JSON.stringify(document), progress, JSON.stringify(data));
if (inspectors.ws) {

@@ -59,3 +62,3 @@ inspectors.ws.send(JSON.stringify({

logger.trace(constx.JOB.MSG_ON_EVENT['failed'],
routine, operation, entity, JSON.stringify(document), JSON.stringify(errorMessage));
self.getSandboxName(), routine, operation, entity, JSON.stringify(document), JSON.stringify(errorMessage));
if (inspectors.ws && inspectors.notifyFailure) {

@@ -70,3 +73,3 @@ inspectors.ws.send(JSON.stringify({

logger.trace(constx.JOB.MSG_ON_EVENT['failed'],
routine, operation, entity, JSON.stringify(document), JSON.stringify(errorMessage));
self.getSandboxName(), routine, operation, entity, JSON.stringify(document), JSON.stringify(errorMessage));
if (inspectors.ws && inspectors.notifyFailure) {

@@ -82,3 +85,3 @@ inspectors.ws.send(JSON.stringify({

logger.trace(constx.JOB.MSG_ON_EVENT['complete'],
routine, operation, entity, JSON.stringify(document), JSON.stringify(result));
self.getSandboxName(), routine, operation, entity, JSON.stringify(document), JSON.stringify(result));
if (inspectors.ws && inspectors.notifySuccess) {

@@ -106,2 +109,4 @@ inspectors.ws.send(JSON.stringify({

};
logger.trace('<%s> + create a jobqueue-adapter instance done!', self.getSandboxName());
};

@@ -108,0 +113,0 @@

@@ -8,4 +8,2 @@ 'use strict';

var ElasticsearchHelper = require('../helpers/elasticsearch-helper.js');
var MongodbHelper = require('../helpers/mongodb-helper.js');
var RunhookManager = require('../services/runhook-manager.js');

@@ -16,23 +14,14 @@ var constx = require('../utils/constx.js');

var Service = function(params) {
var self = this;
params = params || {};
var self = this;
self.getSandboxName = function() {
return params.contextname;
};
var config = params.configuration || {};
config = lodash.pick(config, ['elasticsearch', 'redis', 'mongodb', 'runhook', 'derivedConfig']);
var elasticsearchHelper = new ElasticsearchHelper(params);
var mongodbHelper = new MongodbHelper(params);
var runhookManager = new RunhookManager(lodash.defaultsDeep(config, {
runhook: {
context: {
elasticsearch_index_url: config.derivedConfig.es_index_url,
mongo_collection_names: config.derivedConfig.mongo_collection_names
},
service: {
elasticsearchHelper: elasticsearchHelper,
mongodbHelper: mongodbHelper
}
}
}));
var runhookManager = new RunhookManager(params);

@@ -44,2 +33,3 @@ self.getRunhookManager = function() {

var redis_conf = config.redis;
logger.trace('<%s> + create JobQueue with redis config: %s', self.getSandboxName(), JSON.stringify(redis_conf));
var jobQueue = JobQueue.createQueue({

@@ -60,14 +50,14 @@ prefix: redis_conf.name || 'devebotjq',

if (runhookManager.isRunhookAvailable(routine, entity, operation)) {
logger.trace(constx.RUNHOOK.MSG.BEGIN, routine, operation, entity, JSON.stringify(doc));
logger.trace(constx.RUNHOOK.MSG.BEGIN, self.getSandboxName(), routine, operation, entity, JSON.stringify(doc));
runhookManager.callRunhook(routine, entity, operation, doc).then(function(result) {
logger.trace(constx.RUNHOOK.MSG.RESULT, routine, operation, entity, JSON.stringify(doc), JSON.stringify(result));
logger.trace(constx.RUNHOOK.MSG.RESULT, self.getSandboxName(), routine, operation, entity, JSON.stringify(doc), JSON.stringify(result));
done && done(null, result);
}).catch(function(error) {
logger.error(constx.RUNHOOK.MSG.ERROR, routine, operation, entity, JSON.stringify(doc), JSON.stringify(error));
logger.error(constx.RUNHOOK.MSG.ERROR, self.getSandboxName(), routine, operation, entity, JSON.stringify(doc), JSON.stringify(error));
done && done(error, null);
}).finally(function() {
logger.trace(constx.RUNHOOK.MSG.END, routine, operation, entity, JSON.stringify(doc));
logger.trace(constx.RUNHOOK.MSG.END, self.getSandboxName(), routine, operation, entity, JSON.stringify(doc));
});
} else {
logger.trace(constx.RUNHOOK.MSG.NOOP, routine, operation, entity, JSON.stringify(doc));
logger.trace(constx.RUNHOOK.MSG.NOOP, self.getSandboxName(), routine, operation, entity, JSON.stringify(doc));
done && done(null, {});

@@ -78,9 +68,9 @@ }

var jobQueueOfRoutine = {};
jobQueueOfRoutine[constx.RUNHOOK.KEY.OPLOG] = 'oplog-handling-runner';
jobQueueOfRoutine[constx.RUNHOOK.KEY.MARKUP] = 'index-handling-runner';
jobQueueOfRoutine[constx.RUNHOOK.KEY.MOCKIT] = 'mockit-handling-runner';
jobQueueOfRoutine[constx.RUNHOOK.KEY.MARKUP] = 'index-handling-runner';
jobQueueOfRoutine[constx.RUNHOOK.KEY.OPLOG] = 'oplog-handling-runner';
var jobQueueEvents = lodash.uniq(lodash.values(jobQueueOfRoutine));
lodash.forEach(jobQueueEvents, function(event) {
jobQueue.process(event, jobQueueProcess);
jobQueue.process(self.getSandboxName() + '-' + event, jobQueueProcess);
});

@@ -93,3 +83,4 @@

self.getJobQueueOfRoutine = function(routine) {
return (jobQueueOfRoutine[routine] ? jobQueueOfRoutine[routine] : 'global-handling-runner');
var event = (jobQueueOfRoutine[routine] ? jobQueueOfRoutine[routine] : 'global-handling-runner');
return self.getSandboxName() + '-' + event;
};

@@ -96,0 +87,0 @@ };

@@ -9,3 +9,3 @@ 'use strict';

var fileutil = require('../utils/fileutil.js');
var chores = require('../utils/chores.js');
var constx = require('../utils/constx.js');

@@ -15,18 +15,41 @@ var logger = require('../utils/logger.js');

/**
* The constructor for RunhookManager class.
*
* @constructor
* @param {Object} params - The parameters of the constructor.
* @param {Object} params.runhook - The parameters that sent to Runhooks
*/
var Service = function(params) {
params = params || {};
var self = this;
self.config = params;
self.runhookInstance = params;
self.getSandboxName = function() {
return params.contextname;
};
var config = params.configuration;
logger.trace('<%s> + create a runhook-manager instance', self.getSandboxName());
var runhookRoot = {};
self.getRunhooks = function() {
return (runhookRoot[constx.RUNHOOK.ROOT_KEY] || {});
};
self.isContextPassedAtLoading = function() {
return config[constx.RUNHOOK.ROOT_KEY]['context_passed_at_loading'] == true;
};
self.isRunhookPathAsc = function() {
return true;
};
var mergeRunhookEntries = function(runhookStore) {
var runhookFiles = fileutil.listConfigFiles(runhookStore);
logger.trace(' + runhookStore: %s', runhookStore);
logger.trace(' + runhookFiles: %s', JSON.stringify(runhookFiles));
logger.trace('<%s> - runhookStore: %s', self.getSandboxName(), runhookStore);
var runhookFiles = chores.listFiles(runhookStore);
runhookFiles.forEach(function(file) {

@@ -39,3 +62,4 @@ mergeRunhookEntry(runhookStore, file);

var filepath = path.join(runhookStore, file);
var target = loader(filepath)(self.config.runhook);
var runhook_arguments = self.isContextPassedAtLoading() ? self.runhookInstance : {};
var target = loader(filepath)(runhook_arguments);
var entryPath = file.replace('.js', '').toLowerCase().split('_').reverse();

@@ -51,7 +75,3 @@ entryPath.unshift(target);

mergeRunhookEntries(self.config[constx.RUNHOOK.ROOT_KEY]['folder']);
self.isRunhookPathAsc = function() {
return true;
};
mergeRunhookEntries(config[constx.RUNHOOK.ROOT_KEY]['folder']);
};

@@ -116,11 +136,8 @@

var runhooks = self.getRunhooks();
logger.trace('<%s> * callRunhook("%s", "%s", "%s")', self.getSandboxName(), routine, entity, operation);
if (self.isRunhookAvailable(routine, entity, operation)) {
if (self.isRunhookPathAsc()) {
return Promise.resolve(runhooks[routine][entity][operation].call(self, document));
} else {
return Promise.resolve(runhooks[entity][routine][operation].call(self, document));
}
var runhookOp = self.isRunhookPathAsc() ? runhooks[routine][entity][operation] : runhooks[entity][routine][operation];
return Promise.resolve(self.isContextPassedAtLoading() ? runhookOp(document) : runhookOp.call(self.runhookInstance, document));
} else {
return Promise.reject({ name: 'runhook_is_not_available', routine: routine,
entity: entity, operation: operation});
return Promise.reject({ name: 'runhook_is_not_available', routine: routine, entity: entity, operation: operation});
}

@@ -127,0 +144,0 @@ };

@@ -5,3 +5,2 @@ 'use strict';

var util = require('util');
var lodash = require('lodash');
var MongoOplog = require('mongo-oplog');

@@ -12,5 +11,10 @@ var constx = require('../utils/constx.js');

var Service = function(params) {
params = params || {};
var self = this;
params = params || {};
self.getSandboxName = function() {
return params.contextname;
};
var config = params.configuration;

@@ -25,7 +29,7 @@ var jobqueueAdapter = params.jobqueueAdapter;

oplog.on('end', function () {
logger.trace('MongoDB oplog stream ended');
logger.trace('<%s> * MongoDB oplog stream ended', self.getSandboxName());
});
oplog.on('error', function (error) {
logger.error('MongoDB oplog has error: %s', JSON.stringify(error));
logger.error('<%s> * MongoDB oplog has error: %s', self.getSandboxName(), JSON.stringify(error));
});

@@ -38,9 +42,11 @@

runhookOperations.forEach(function(operation) {
opfilter.on(operation, function(doc) {
jobqueueAdapter.enqueueJob(constx.RUNHOOK.KEY.OPLOG, entity, operation, doc).then(function() {
logger.trace(' - MongodbTrigger pass the Job');
}, function() {
logger.error(' - MongodbTrigger fail the Job');
});
});
opfilter.on(operation, (function(jobqueueAdapter, entity, operation) {
return function(doc) {
jobqueueAdapter.enqueueJob(constx.RUNHOOK.KEY.OPLOG, entity, operation, doc).then(function() {
logger.trace('<%s> - MongodbTrigger pass the Job', self.getSandboxName());
}, function() {
logger.error('<%s> - MongodbTrigger fail the Job', self.getSandboxName());
});
};
})(jobqueueAdapter, entity, operation));
});

@@ -59,3 +65,3 @@ });

self.getOplog().tail(function() {
logger.trace(' - MongodbTrigger is started');
logger.trace('<%s> - MongodbTrigger is started', self.getSandboxName());
self.emit('started');

@@ -68,3 +74,3 @@ });

self.getOplog().stop(function() {
logger.trace(' - MongodbTrigger is stopped');
logger.trace('<%s> - MongodbTrigger is stopped', self.getSandboxName());
self.emit('stopped');

@@ -71,0 +77,0 @@ });

@@ -10,2 +10,5 @@ 'use strict';

SYSTEM_INFO: 'sysinfo',
SANDBOX_INFO: 'sb-info',
SANDBOX_USE: 'sb-use',
ES_INFO: 'es-info',
ES_CLEAR: 'es-clear',

@@ -21,6 +24,6 @@ ES_RESET: 'es-reset',

MSG_ON_EVENT: {
'enqueue': 'Job <%s>, to <%s> the <%s> document <%s>, has been started with parameters: <%s>',
'progress': 'Job <%s>, to <%s> the <%s> document <%s>, has been completed %s%%, with data: <%s>',
'failed': 'Job <%s>, to <%s> the <%s> document <%s>, has been failed with error message <%s>',
'complete': 'Job <%s>, to <%s> the <%s> document <%s>, has been completed with result <%s>'
'enqueue': '<%s> * Job <%s>, to <%s> the <%s> document <%s>, has been started with parameters: <%s>',
'progress': '<%s> * Job <%s>, to <%s> the <%s> document <%s>, has been completed %s%%, with data: <%s>',
'failed': '<%s> * Job <%s>, to <%s> the <%s> document <%s>, has been failed with error message <%s>',
'complete': '<%s> * Job <%s>, to <%s> the <%s> document <%s>, has been completed with result <%s>'
}

@@ -39,7 +42,7 @@ },

MSG: {
'BEGIN': ' - In <%s>, start to <%s> an item of <%s> document: %s',
'RESULT': ' -> in <%s>, <%s> the item <%s> document <%s>, oplog result: %s',
'ERROR': ' -> in <%s>, <%s> the item <%s> document <%s>, oplog error: %s',
'END': ' -> in <%s>, finish to <%s> the item <%s> document: %s',
'NOOP': ' -> in <%s>, operation <%s> on the item <%s> document: %s is not defined'
'BEGIN': '<%s> - In <%s>, start to <%s> an item of <%s> document: %s',
'RESULT': '<%s> -> in <%s>, <%s> the item <%s> document <%s>, oplog result: %s',
'ERROR': '<%s> -> in <%s>, <%s> the item <%s> document <%s>, oplog error: %s',
'END': '<%s> -> in <%s>, finish to <%s> the item <%s> document: %s',
'NOOP': '<%s> -> in <%s>, operation <%s> on the item <%s> document: %s is not defined'
}

@@ -46,0 +49,0 @@ },

@@ -9,3 +9,3 @@ 'use strict';

if (NODE_ENV && NODE_ENV != 'production') {
logConsoleLevel = 'debug';
logConsoleLevel = 'trace';
}

@@ -12,0 +12,0 @@

{
"name": "devebot",
"version": "0.0.7",
"version": "0.0.8",
"description": "Development support toolkit",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc