UNPKG

openhim-core

Version:

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

64 lines (47 loc) 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.restart = restart; var _winston = _interopRequireDefault(require("winston")); var authorisation = _interopRequireWildcard(require("../api/authorisation")); var server = _interopRequireWildcard(require("../server")); var _config = require("../config"); var KeystoreAPI = _interopRequireWildcard(require("../api/keystore")); var utils = _interopRequireWildcard(require("../utils")); var _util = require("util"); function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } 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(() => _winston.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 _winston.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