From 39e1e4caa89a871f4d04119fa6cf20e541e5b54c Mon Sep 17 00:00:00 2001 From: Ruslan Panamarenka Date: Thu, 9 Jan 2025 18:52:12 +0100 Subject: [PATCH] fix: configure command (#640) --- src/Commands/Configure.ts | 9 ---- src/Wizard/Connectivity/TCPConnectivity.ts | 54 ---------------------- src/Wizard/Connectivity/index.ts | 1 - src/Wizard/Readline/ReadlinePlatform.ts | 4 +- src/Wizard/TestType.ts | 1 - src/container.ts | 8 ---- 6 files changed, 1 insertion(+), 76 deletions(-) delete mode 100644 src/Wizard/Connectivity/TCPConnectivity.ts diff --git a/src/Commands/Configure.ts b/src/Commands/Configure.ts index 7dc94205..d633f3cd 100644 --- a/src/Commands/Configure.ts +++ b/src/Commands/Configure.ts @@ -20,11 +20,6 @@ export class Configure implements CommandModule { public builder(argv: Argv): Argv { return argv - .option(TestType.TCP, { - hidden: true, - requiresArg: true, - describe: `Bright application base URL` - }) .option(TestType.HTTP, { hidden: true, requiresArg: true, @@ -70,10 +65,6 @@ export class Configure implements CommandModule { }) .register(ConnectivityUrls, { useValue: new Map([ - Configure.getMapEntryOrThrow( - TestType.TCP, - (args[TestType.TCP] ?? args.api) as string - ), Configure.getMapEntryOrThrow( TestType.HTTP, (args[TestType.HTTP] ?? args.api) as string diff --git a/src/Wizard/Connectivity/TCPConnectivity.ts b/src/Wizard/Connectivity/TCPConnectivity.ts deleted file mode 100644 index 1bd912e3..00000000 --- a/src/Wizard/Connectivity/TCPConnectivity.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Connectivity } from './Connectivity'; -import { logger } from '../../Utils'; -import { TestType } from '../TestType'; -import { injectable } from 'tsyringe'; -import { Socket } from 'node:net'; -import { once } from 'node:events'; - -@injectable() -export class TCPConnectivity implements Connectivity { - public readonly type = TestType.TCP; - private readonly CONNECTION_TIMEOUT = 10 * 1000; // 10 seconds - private readonly PROTOCOL_DEFAULT_PORTS = { - 'http:': 80, - 'https:': 443, - 'ftp:': 21, - 'sftp:': 22, - 'smtp:': 25, - 'ldap:': 389, - 'ldaps:': 636 - } as const; - - public async test({ hostname, port, protocol }: URL): Promise { - port ??= this.PROTOCOL_DEFAULT_PORTS[protocol] ?? 0; - - const socket: Socket = new Socket(); - - socket.setNoDelay(false); - - try { - logger.debug( - `TCP connectivity test. Opening socket to %s:%s`, - hostname, - +port - ); - socket.setTimeout(this.CONNECTION_TIMEOUT, () => - socket.destroy(new Error(`Reached socket timeout.`)) - ); - process.nextTick(() => socket.connect(+port, hostname)); - await once(socket, 'connect'); - - logger.debug('TCP connectivity test. Connection succesfull.'); - - return true; - } catch (err) { - logger.debug(`TCP connectivity test. Connection failed: %s`, err.message); - - return false; - } finally { - if (!socket.destroyed) { - socket.destroy(); - } - } - } -} diff --git a/src/Wizard/Connectivity/index.ts b/src/Wizard/Connectivity/index.ts index 89f72c71..fc571b10 100644 --- a/src/Wizard/Connectivity/index.ts +++ b/src/Wizard/Connectivity/index.ts @@ -3,5 +3,4 @@ export * from './Connectivity'; export * from './ConnectivityAnalyzer'; export * from './DefaultConnectivityAnalyzer'; export * from './HTTPConnectivity'; -export * from './TCPConnectivity'; export * from './TracerouteConnectivity'; diff --git a/src/Wizard/Readline/ReadlinePlatform.ts b/src/Wizard/Readline/ReadlinePlatform.ts index 76b423e9..db636654 100644 --- a/src/Wizard/Readline/ReadlinePlatform.ts +++ b/src/Wizard/Readline/ReadlinePlatform.ts @@ -108,7 +108,7 @@ export class ReadlinePlatform implements Platform { const url = this.urls.get(type); return this.process( - `Validating that the connection to ${url.host} at port ${url.port} is open`, + `Validating the ${type} connection to ${url.toString()}`, () => this.connectivityService.verifyAccess(type, url) ); } @@ -117,8 +117,6 @@ export class ReadlinePlatform implements Platform { // eslint-disable-next-line no-console console.log(`Starting EXTERNAL communication diagnostics:${EOL}`); - await this.processConnectivity(TestType.TCP); - await this.processConnectivity(TestType.HTTP); await this.process('Verifying provided Token and Repeater ID', () => diff --git a/src/Wizard/TestType.ts b/src/Wizard/TestType.ts index 0306cc4d..abbf5747 100644 --- a/src/Wizard/TestType.ts +++ b/src/Wizard/TestType.ts @@ -1,6 +1,5 @@ export enum TestType { HTTP = 'http', - TCP = 'tcp', AUTH = 'auth', TRACEROUTE = 'traceroute' } diff --git a/src/container.ts b/src/container.ts index 4a93fd01..093f06ef 100644 --- a/src/container.ts +++ b/src/container.ts @@ -22,7 +22,6 @@ import { HTTPConnectivity, Platform, ReadlinePlatform, - TCPConnectivity, TracerouteConnectivity, Tokens } from './Wizard'; @@ -139,13 +138,6 @@ container }, { lifecycle: Lifecycle.Singleton } ) - .register( - Connectivity, - { - useClass: TCPConnectivity - }, - { lifecycle: Lifecycle.Singleton } - ) .register( Connectivity, { useClass: TracerouteConnectivity },