UNPKG

@mdf.js/openc2-core

Version:

MMS - API Core - OpenC2

118 lines 3.94 kB
"use strict"; /** * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Accessors = void 0; const lodash_1 = require("lodash"); const Constants_1 = require("./Constants"); class Accessors { /** * Return the target of the actual message * @param command - message to be processed * @returns target */ static getTargetFromCommandMessage(command) { return Object.keys(command.content.target)[0]; } /** * Return the target of the actual command * @param command - command to be processed * @returns target */ static getTargetFromCommand(command) { return Object.keys(command.target)[0]; } /** * Return the action of the actual message * @param command - message to be processed * @returns action */ static getActionFromCommandMessage(command) { return command.content.action; } /** * Return the action of the actual command * @param command - command to be processed * @returns action */ static getActionFromCommand(command) { return command.action; } /** * Return the actuators in the command message * @param command - message to be processed * @returns actuators */ static getActuatorsFromCommandMessage(command) { return this.getActuatorsFromCommand(command.content); } /** * Return the actuators in the command * @param command - command to be processed * @returns actuators */ static getActuatorsFromCommand(command) { const actuators = (0, lodash_1.get)(command, 'actuator', {}); return Object.keys(actuators); } /** * Return the a property from actuators in the command * @param command - command to be processed * @param profile - actuator profile to find * @returns property value */ static getActuatorAssetId(command, profile) { return (0, lodash_1.get)(command, ['actuator', profile, 'asset_id'], undefined); } /** * Return the delay allowed from command message * @param command - message to be processed * @returns delay in milliseconds */ static getDelayFromCommandMessage(command) { return this.getDelayFromCommand(command.content); } /** * Return the delay allowed from command * @param command - message to be processed * @returns delay in milliseconds */ static getDelayFromCommand(command) { const startTime = (0, lodash_1.get)(command, 'args.start_time', undefined); const stopTime = (0, lodash_1.get)(command, 'args.stop_time', undefined); const duration = (0, lodash_1.get)(command, 'args.duration', undefined); let delay; if (stopTime !== undefined) { delay = stopTime - Date.now(); } else if (startTime !== undefined && duration !== undefined) { delay = startTime + duration - Date.now(); } else { delay = duration !== null && duration !== void 0 ? duration : Constants_1.Constants.DEFAULT_MAX_RESPONSE_COMMAND_DELAY; } return delay > 0 ? delay : Constants_1.Constants.DEFAULT_MAX_RESPONSE_COMMAND_DELAY; } /** * Convert consumer status to Subcomponent status * @param response - response message to be processed * @returns Subcomponent status */ static getStatusFromResponseMessage(response) { if (response.status >= 500) { return 'fail'; } else if (response.status >= 200) { return 'pass'; } else { return 'warn'; } } } exports.Accessors = Accessors; //# sourceMappingURL=Accessors.js.map