Skip to content

Commit

Permalink
Merge pull request #199 from Optum/master
Browse files Browse the repository at this point in the history
R0.6.0
  • Loading branch information
jdweeks authored Dec 7, 2018
2 parents 2d77fa4 + c85b22b commit 35ae5d4
Show file tree
Hide file tree
Showing 43 changed files with 10,084 additions and 561 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ specs
.nyc_output
*.DS_store
public/js/bower_components
package-lock.json
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,3 @@ Formerly known as a "system under test", a group is a convenient way to organize

The service owner is the person who created the service. If Mockiato is running with the LDAP authentication strategy, then the non-ID fields for the owner model are simply a username and email address. These are pulled from AD automatically on your first login.


## Original Contributors

+ Rahul Vashishth
+ Grace Clark
+ Zak Parks
+ JD Weeks

## Maintainers

+ Zak Parks
+ JD Weeks
57 changes: 49 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ const app = express();
const compression = require('compression');
const debug = require('debug')('default');
const path = require('path');
const logger = require('morgan');
//const logger = require('morgan');
const morgan = require('morgan')
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const helmet = require('helmet');
const actuator = require('express-actuator');


var logger = require('./winston');


// connect to database
const db = require('./models/db');
db.on('error', function(err) {throw err; });
db.once('open', function() {
debug(`Successfully connected to Mongo (${process.env.MONGODB_HOST})`);
logger.info(`Successfully connected to Mongo (${process.env.MONGODB_HOST})`);
// ready to start
app.emit('ready');
});
Expand All @@ -31,7 +37,8 @@ function init() {
// register middleware
app.use(helmet());
app.use(compression());
app.use(logger('dev'));
//app.use(logger('dev'));
app.use(morgan('combined'));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

Expand Down Expand Up @@ -65,12 +72,14 @@ function init() {
// setup local authentication
if (authType === 'local') {
debug('Using local auth strategy');
logger.info('Using local auth strategy');
const local = require('./lib/auth/local');
app.use('/register', local);
}
// setup ldap authentication
else if (authType === 'ldapauth') {
debug('Using LDAP auth strategy');
logger.info('Using LDAP auth strategy');
require('./lib/auth/ldap');
}

Expand Down Expand Up @@ -101,6 +110,7 @@ function init() {
return;
}
debug('New user created: ' + newUser.uid);
logger.info('New user created: ' + newUser.uid);
});
}
});
Expand All @@ -118,6 +128,19 @@ function init() {
});
});

// expose MQ info
const MQInfo = require('./models/mq/MQInfo');
app.get('/api/admin/mq/info', function(req, res) {
MQInfo.find({}, function(err, infoArr) {
if (err) {
handleError(err, res, 500);
return;
}

res.json(infoArr);
});
});

// expose API and virtual SOAP / REST services
const virtual = require('./routes/virtual');
const api = require('./routes/services');
Expand All @@ -131,13 +154,14 @@ function init() {
if (process.env.MOCKIATO_MODE !== 'single') {
process.on('message', function(message) {
const msg = message.data;
debug(msg);
const service = msg.service;
const action = msg.action;
debug(action);

if (msg.action === 'register') {
virtual.registerById(msg.serviceId);
}
else {
virtual.deregisterById(msg.serviceId);
virtual.deregisterService(service);

if (action === 'register') {
virtual.registerService(service);
}
});
}
Expand All @@ -149,6 +173,23 @@ function init() {
const users = require('./routes/users');
app.use('/api/users', users);

// handle no match responses
app.use(function(req, res, next) {
if (!req.msgContainer) {
req.msgContainer = {};
req.msgContainer.reqMatched = false;
req.msgContainer.reason = `Path ${req.path} could not be found`;
}

return res.status(404).json(req.msgContainer);
});

// handle internal errors
app.use(function(err, req, res) {
debug(err.message);
return res.status(500).send(err.message);
});

// ready for testing (see test/test.js)
app.emit('started');
}
Expand Down
68 changes: 67 additions & 1 deletion controllers/rrpairController.js
Original file line number Diff line number Diff line change
@@ -1 +1,67 @@
const RRPair = require('../models/RRPair');
const Service = require('../models/http/Service');
const MQService = require('../models/mq/MQService');

const xml2js = require('xml2js');
const xmlBuilder = new xml2js.Builder();

function getPairsByServiceId(req, res) {
Service.findById(req.params.serviceId, function(err, service) {
if (err) {
handleError(err, res, 500);
return;
}

if (service) {
res.json(service.rrpairs);
}
else {
MQService.findById(req.params.serviceId, function(error, mqService) {
if (error) {
handleError(error, res, 500);
return;
}

return res.json(mqService.rrpairs);
});
}
});
}

function trimRequestData(template, rrpair) {
if (!template || !rrpair) {
return;
}

xml2js.parseString(template, function(err, xmlTemplate) {
if (err) {
debug(err);
return;
}
template = xmlTemplate;
});

let reqData;
xml2js.parseString(rrpair.reqData, function(err, data) {
reqData = data;
});

// flatten request data
const flatTemplate = flattenObject(template);
const flatReqData = flattenObject(reqData);
const trimmedReqData = {};

// pull out the fields specified in the template
for (let field in flatTemplate) {
trimmedReqData[field] = flatReqData[field];
}

// unflatten the trimmed request data
const unflatReqData = unflattenObject(trimmedReqData);

return xmlBuilder.buildObject(unflatReqData);
}

module.exports = {
getPairsByServiceId: getPairsByServiceId,
trimRequestData: trimRequestData
};
Loading

0 comments on commit 35ae5d4

Please sign in to comment.