openhim-core
Version:
The OpenHIM core application that provides logging and routing of http requests
74 lines (53 loc) • 2.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.restart = restart;
var _winston = require('winston');
var _winston2 = _interopRequireDefault(_winston);
var _authorisation = require('../api/authorisation');
var authorisation = _interopRequireWildcard(_authorisation);
var _server = require('../server');
var server = _interopRequireWildcard(_server);
var _config = require('../config');
var _keystore = require('../api/keystore');
var KeystoreAPI = _interopRequireWildcard(_keystore);
var _utils = require('../utils');
var utils = _interopRequireWildcard(_utils);
var _util = require('util');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
_config.config.router = _config.config.get('router');
_config.config.api = _config.config.get('api');
_config.config.rerun = _config.config.get('rerun');
_config.config.polling = _config.config.get('polling');
_config.config.tcpAdapter = _config.config.get('tcpAdapter');
/*
* restart the server
*/
async function restart(ctx, next) {
// Test if the user is authorised
if (authorisation.inGroup('admin', ctx.authenticated) === false) {
utils.logAndSetResponse(ctx, 403, `User ${ctx.authenticated.email} is not an admin, API access to restart the server denied.`, 'info');
return;
}
try {
const emailAddr = ctx.authenticated.email;
const result = await (0, _util.promisify)(KeystoreAPI.getCertKeyStatus)();
// valid certificate/key
if (result) {
server.startRestartServerTimeout(() => _winston2.default.info(`User ${emailAddr} has requested a Server Restart. Proceeding to restart servers...`));
// All ok! So set the result
ctx.body = 'Server being restarted';
ctx.status = 200;
} else {
// Not valid
_winston2.default.info(`User ${emailAddr} has requested a Server Restart with invalid certificate details. Cancelling restart...`);
ctx.body = 'Certificates and Key did not match. Cancelling restart...';
ctx.status = 400;
}
} catch (e) {
utils.logAndSetResponse(ctx, 400, `Could not restart the servers via the API: ${e}`, 'error');
}
}
//# sourceMappingURL=restart.js.map