@mdf.js/openc2
Version:
MMS - API - Observability
54 lines • 2.82 kB
JavaScript
"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.GatewayFactory = void 0;
const tslib_1 = require("tslib");
const crash_1 = require("@mdf.js/crash");
const openc2_core_1 = require("@mdf.js/openc2-core");
const cluster_1 = tslib_1.__importDefault(require("cluster"));
const Adapters = tslib_1.__importStar(require("../adapters"));
class GatewayFactory {
/**
* Create an instance of OpenC2 Gateway, Redis (Consumer) to WebSocketIO (Producer)
* @param options - Gateway configuration options
* @param socketOptions - SocketIO configuration options
* @param redisOptions - Redis configuration options
*/
static RedisToWebSocketIO(options, socketOptions, redisOptions) {
var _a;
if (cluster_1.default.isWorker) {
throw new crash_1.Crash('OpenC2 Gateway can not be instantiated in a worker process');
}
else {
const consumerAdapter = new Adapters.Redis.RedisConsumerAdapter({ id: options.id }, redisOptions);
const producerAdapter = new Adapters.SocketIO.SocketIOProducerAdapter({ id: options.id }, socketOptions);
const register = (_a = options.registry) !== null && _a !== void 0 ? _a : new openc2_core_1.Registry(options.id, options.maxInactivityTime, options.registerLimit);
return new openc2_core_1.Gateway(consumerAdapter, producerAdapter, { ...options, registry: register });
}
}
/**
* Create an instance of OpenC2 Gateway, WebSocketIO (Consumer) to Redis (Producer)
* @param options - Gateway configuration options
* @param socketOptions - SocketIO configuration options
* @param redisOptions - Redis configuration options
*/
static SocketIOToRedis(options, socketOptions, redisOptions) {
var _a;
if (cluster_1.default.isWorker) {
throw new crash_1.Crash('OpenC2 Gateway can not be instantiated in a worker process');
}
else {
const consumerAdapter = new Adapters.SocketIO.SocketIOConsumerAdapter({ id: options.id }, socketOptions);
const producerAdapter = new Adapters.Redis.RedisProducerAdapter({ id: options.id }, redisOptions);
const register = (_a = options.registry) !== null && _a !== void 0 ? _a : new openc2_core_1.Registry(options.id, options.maxInactivityTime, options.registerLimit);
return new openc2_core_1.Gateway(consumerAdapter, producerAdapter, { ...options, registry: register });
}
}
}
exports.GatewayFactory = GatewayFactory;
//# sourceMappingURL=GatewayFactory.js.map