UNPKG

jspurefix

Version:
64 lines 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TlsOptionsFactory = void 0; const path = require('path'); const fs = require('fs'); class TlsOptionsFactory { static read(filePath) { const root = path.join(__dirname, '../../../'); const fullPath = path.join(root, filePath); return fs.readFileSync(fullPath, { encoding: 'utf8', flag: 'r' }); } static getTlsOptions(tls) { let tlsOptions = null; if (tls) { tlsOptions = { requestCert: tls.requestCert, rejectUnauthorized: tls.rejectUnauthorized }; if (tls.key) { tlsOptions.key = TlsOptionsFactory.read(tls.key); tlsOptions.cert = (tls === null || tls === void 0 ? void 0 : tls.cert) ? TlsOptionsFactory.read(tls === null || tls === void 0 ? void 0 : tls.cert) : undefined; } if (tls.ca && tls.ca.length > 0) { tlsOptions.ca = tls.ca.map(i => TlsOptionsFactory.read(i)); } if (tls.nodeTlsServerOptions) { tlsOptions = Object.assign(Object.assign({}, tlsOptions), tls.nodeTlsServerOptions); } } return tlsOptions; } static getTlsConnectionOptions(tcp) { var _a, _b, _c, _d; let connectionOptions = null; const tls = tcp.tls; if (tls) { connectionOptions = { port: tcp.port, host: tcp.host }; if (tls.key) { connectionOptions.key = TlsOptionsFactory.read((_b = (_a = tcp.tls) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : ''); connectionOptions.cert = ((_c = tcp.tls) === null || _c === void 0 ? void 0 : _c.cert) ? TlsOptionsFactory.read((_d = tcp === null || tcp === void 0 ? void 0 : tcp.tls) === null || _d === void 0 ? void 0 : _d.cert) : undefined; } if (tcp.tls.ca && tcp.tls.ca.length > 0) { connectionOptions.ca = tcp.tls.ca.map(i => TlsOptionsFactory.read(i)); } if (tcp.tls.timeout) { connectionOptions.timeout = tcp.tls.timeout; } if (tcp.tls.sessionTimeout) { connectionOptions.sessionTimeout = tcp.tls.sessionTimeout; } if (tls.nodeTlsConnectionOptions) { connectionOptions = Object.assign(Object.assign({}, connectionOptions), tls.nodeTlsConnectionOptions); } } return connectionOptions; } } exports.TlsOptionsFactory = TlsOptionsFactory; //# sourceMappingURL=tls-options-factory.js.map