UNPKG

@mdf.js/openc2

Version:

MMS - API - Observability

54 lines 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Check = void 0; /** * Copyright 2024 Mytra Control S.L. All rights reserved. * * Use of this source code is governed by an MIT-style license that can be found in the LICENSE file * or at https://opensource.org/licenses/MIT. */ const crash_1 = require("@mdf.js/crash"); const uuid_1 = require("uuid"); const __1 = require(".."); /** * Check the token of the request * @param role - role to be checked * @returns */ function check() { return (socket, next) => { const auth = socket.handshake.auth; const isValidType = auth['type'] === 'producer' || auth['type'] === 'consumer'; const isValidId = typeof auth['nodeId'] === 'string'; let isValidActuators = true; if (auth['actuators']) { isValidActuators = Array.isArray(auth['actuators']) && auth['actuators'].every(actuator => typeof actuator === 'string'); } if (isValidType && isValidId && isValidActuators) { socket.data['openC2Id'] = socket.handshake.auth['nodeId']; socket.data['type'] = socket.handshake.auth['type']; if (auth['actuators']) { socket.data['actuators'] = auth['actuators']; } next(); } else { next((0, __1.transformError)(crash_1.BoomHelpers.badRequest(`Malformed request, malformed authorization token`, (0, uuid_1.v4)()))); } return isValidType && isValidId && isValidActuators; }; } /** Check */ class Check { /** * Check if the client has request the connection with valid credentials * @returns */ static handler() { return check(); } } exports.Check = Check; //# sourceMappingURL=check.js.map