UNPKG

@mdf.js/openc2

Version:

MMS - API - Observability

82 lines 3.14 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.RedisAdapter = void 0; const core_1 = require("@mdf.js/core"); const crash_1 = require("@mdf.js/crash"); const redis_provider_1 = require("@mdf.js/redis-provider"); const Adapter_1 = require("../Adapter"); class RedisAdapter extends Adapter_1.Adapter { /** * Create a new OpenC2 adapter for Redis * @param adapterOptions - Adapter configuration options * @param redisOptions - Redis configuration options * @param type - component type */ constructor(adapterOptions, type, redisOptions) { super(adapterOptions, type); this.publisher = redis_provider_1.Redis.Factory.create({ config: { ...redisOptions, connectionName: `${this.name}-publisher` }, name: `${this.name}-publisher`, }); this.subscriber = redis_provider_1.Redis.Factory.create({ config: { ...redisOptions, connectionName: `${this.name}-subscriber`, disableChecks: true }, name: `${this.name}-subscriber`, }); } /** Adapter health status */ get status() { return core_1.Health.overallStatus(this.checks); } /** Component checks */ get checks() { return { ...this.publisher.checks, ...this.subscriber.checks, }; } /** Connect the OpenC2 Adapter to the underlayer transport system */ async start() { try { await this.publisher.start(); await this.subscriber.start(); await this.subscriber.client.psubscribe(...this.subscriptions); } catch (rawError) { const error = crash_1.Crash.from(rawError); throw new crash_1.Crash(`Error performing the subscription to OpenC2 topics: ${error.message}`, error.uuid, { cause: error }); } } /** Connect the OpenC2 Adapter to the underlayer transport system */ async stop() { try { await this.publisher.stop(); await this.subscriber.client.punsubscribe(...this.subscriptions); await this.subscriber.stop(); } catch (rawError) { const error = crash_1.Crash.from(rawError); throw new crash_1.Crash(`Error performing the unsubscription to OpenC2 topics: ${error.message}`, error.uuid, { cause: error }); } } /** Disconnect the OpenC2 Adapter to the underlayer transport system */ async close() { try { await this.publisher.close(); await this.subscriber.close(); } catch (rawError) { const error = crash_1.Crash.from(rawError); throw new crash_1.Crash(`Error closing the OpenC2 adapter: ${error.message}`, error.uuid, { cause: error, }); } } } exports.RedisAdapter = RedisAdapter; //# sourceMappingURL=RedisAdapter.js.map