UNPKG

openhim-core

Version:

The OpenHIM core application that provides logging and routing of http requests

61 lines (44 loc) 1.45 kB
var Client, Q, SDC, application, config, domain, dummyClient, logger, os, sdc, statsdServer; Q = require("q"); Client = require("../model/clients").Client; logger = require("winston"); config = require('../config/config'); statsdServer = config.get('statsd'); application = config.get('application'); SDC = require('statsd-client'); os = require('os'); domain = (os.hostname()) + "." + application.name + ".appMetrics"; sdc = new SDC(statsdServer); dummyClient = new Client({ clientID: 'DUMMY-POLLING-USER', clientDomain: 'openhim.org', name: 'DUMMY-POLLING-USER', roles: ['polling'] }); exports.authenticateUser = function(ctx, done) { ctx.authenticated = dummyClient; return done(null, dummyClient); }; /* * Koa middleware for bypassing authentication for polling requests */ exports.koaMiddleware = function*(next) { var authenticateUser, startTime; if (statsdServer.enabled) { startTime = new Date(); } authenticateUser = Q.denodeify(exports.authenticateUser); (yield authenticateUser(this)); if (this.authenticated != null) { if (statsdServer.enabled) { sdc.timing(domain + ".pollingBypassAuthenticationMiddleware", startTime); } return (yield next); } else { this.response.status = 401; if (statsdServer.enabled) { return sdc.timing(domain + ".pollingBypassAuthenticationMiddleware", startTime); } } }; //# sourceMappingURL=pollingBypassAuthentication.js.map