UNPKG

@mdf.js/openc2-core

Version:

MMS - API Core - OpenC2

196 lines 7.26 kB
/** * 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. */ import { Health, Layer } from '@mdf.js/core'; import { Crash, Links } from '@mdf.js/crash'; import EventEmitter from 'events'; import express from 'express'; import { Registry } from '../../modules'; import { ConsumerAdapter, GatewayOptions, ProducerAdapter } from '../../types'; import { ConsumerMap } from '../Producer/ConsumerMap'; export declare interface Gateway { /** * Add a listener for the `error` event, emitted when the component detects an error. * @param event - `error` event * @param listener - Error event listener * @event */ on(event: 'error', listener: (error: Crash | Error) => void): this; /** * Add a listener for the `error` event, emitted when the component detects an error. * @param event - `error` event * @param listener - Error event listener * @event */ addListener(event: 'error', listener: (error: Crash | Error) => void): this; /** * Add a listener for the `error` event, emitted when the component detects an error. This is a * one-time event, the listener will be removed after the first emission. * @param event - `error` event * @param listener - Error event listener * @event */ once(event: 'error', listener: (error: Crash | Error) => void): this; /** * Removes the specified listener from the listener array for the `error` event. * @param event - `error` event * @param listener - Error event listener * @event */ off(event: 'error', listener: (error: Crash | Error) => void): this; /** * Removes the specified listener from the listener array for the `error` event. * @param event - `error` event * @param listener - Error event listener * @event */ removeListener(event: 'error', listener: (error: Crash | Error) => void): this; /** * Removes all listeners, or those of the specified event. * @param event - `error` event */ removeAllListeners(event?: 'error'): this; /** * Add a listener for the `status` event, emitted when the component changes its status. * @param event - `status` event * @param listener - Status event listener * @event */ on(event: 'status', listener: (status: Health.Status) => void): this; /** * Add a listener for the `status` event, emitted when the component changes its status. * @param event - `status` event * @param listener - Status event listener * @event */ addListener(event: 'status', listener: (status: Health.Status) => void): this; /** * Add a listener for the `status` event, emitted when the component changes its status. This is a * one-time event, the listener will be removed after the first emission. * @param event - `status` event * @param listener - Status event listener * @event */ once(event: 'status', listener: (status: Health.Status) => void): this; /** * Removes the specified listener from the listener array for the `status` event. * @param event - `status` event * @param listener - Status event listener * @event */ off(event: 'status', listener: (status: Health.Status) => void): this; /** * Removes the specified listener from the listener array for the `status` event. * @param event - `status` event * @param listener - Status event listener * @event */ removeListener(event: 'status', listener: (status: Health.Status) => void): this; } export declare class Gateway extends EventEmitter implements Layer.App.Service { private readonly options; /** Component identification */ readonly componentId: string; /** Component commands and message register */ protected readonly register: Registry; /** Health wrapper instance */ private readonly health; /** Logger instance */ private readonly logger; /** Component started flag */ private started; /** Upstream Consumer */ private readonly consumer; /** Downstream Producer */ private readonly producer; /** Registry router */ private readonly _router; /** * Regular OpenC2 gateway implementation. * @param upstream - upstream consumer adapter interface * @param downstream - downstream producer adapter interface * @param options - configuration options */ constructor(upstream: ConsumerAdapter, downstream: ProducerAdapter, options: GatewayOptions); /** Component name */ get name(): string; /** Component status */ get status(): Health.Status; /** * Return the status of the Consumer in a standard format * @returns _check object_ as defined in the draft standard * https://datatracker.ietf.org/doc/html/draft-inadarei-api-health-check-05 */ get checks(): Health.Checks; /** Return an Express router with access to errors registry */ get router(): express.Router; /** Return links offered by this service */ get links(): Links; /** Connect the OpenC2 underlayer component and perform the startup of the component */ start(): Promise<void>; /** Disconnect the OpenC2 underlayer component and perform the startup of the component */ stop(): Promise<void>; /** Close the OpenC2 gateway */ close(): Promise<void>; /** Consumer Map */ get consumerMap(): ConsumerMap; /** * Check the lookup time fix them if area wrong * @param options - configuration options * @returns */ private checkLookupTimes; /** * Check if the value is higher than the limit, it not returns the limit * @param value - value to be checked * @param limit - limit * @returns */ private isHigherThan; /** * Check if the value is lower than the limit, it not returns the limit * @param value - value to be checked * @param limit - limit * @returns */ private isLowerThan; /** * Forward the command to the downstream producer * @param job - job to be processed */ private readonly onUpstreamCommandHandler; /** * Adapt the command to be forwarded * @param command - command to be processed * @returns */ private adaptCommand; /** * Get the update args for command execution * @param command - command to be processed * @returns */ private getArgs; /** * Get the addresses to forward the command * @param command - command to be forwarded * @returns */ private getForwardAddresses; /** Update the features of the upstream consumer based in the upstream consumer map */ private readonly updateConsumerOptions; /** * Manage the error in the producer interface * @param error - error to be processed */ protected onErrorHandler(error: unknown): void; /** * Manage the status change in the producer interface * @param status - status to be processed */ private onStatusHandler; } //# sourceMappingURL=Gateway.d.ts.map