From 267ee6d3389b1e71139c53830179563f5b9eccb6 Mon Sep 17 00:00:00 2001 From: butlerx Date: Wed, 2 Sep 2020 17:40:57 +0100 Subject: [PATCH] Fix liniting errors --- src/server/login.ts | 14 +++++++------- src/shared/config.ts | 21 +++++++++++---------- src/shared/interfaces.ts | 2 ++ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/server/login.ts b/src/server/login.ts index 54671d6..bc634ed 100644 --- a/src/server/login.ts +++ b/src/server/login.ts @@ -1,9 +1,13 @@ import pty from 'node-pty'; -import { dirname, resolve } from 'path'; +import { dirname, resolve as resolvePath } from 'path'; import { fileURLToPath } from 'url'; import { xterm } from './shared/xterm.js'; -const __dirname = resolve(dirname(fileURLToPath(import.meta.url)), '..'); +const executable = resolvePath( + dirname(fileURLToPath(import.meta.url)), + '..', + 'buffer.js', +); export function login(socket: SocketIO.Socket): Promise { // Check request-header for username @@ -16,11 +20,7 @@ export function login(socket: SocketIO.Socket): Promise { // Request carries no username information // Create terminal and ask user for username - const term = pty.spawn( - '/usr/bin/env', - ['node', `${__dirname}/buffer.js`], - xterm, - ); + const term = pty.spawn('/usr/bin/env', ['node', executable], xterm); let buf = ''; return new Promise((resolve, reject) => { term.on('exit', () => { diff --git a/src/shared/config.ts b/src/shared/config.ts index 0db8daf..9bc4701 100644 --- a/src/shared/config.ts +++ b/src/shared/config.ts @@ -3,7 +3,7 @@ import path from 'path'; import JSON5 from 'json5'; import isUndefined from 'lodash/isUndefined.js'; -import type { Config, SSH, Server } from './interfaces'; +import type { Config, SSH, Server, SSL } from './interfaces'; import { sshDefault, serverDefault, @@ -11,13 +11,14 @@ import { defaultCommand, } from './defaults.js'; +type confValue = boolean | string | number | undefined | SSH | Server | SSL; /** * Cast given value to boolean * * @param value - variable to cast * @returns variable cast to boolean */ -function ensureBoolean(value: any): boolean { +function ensureBoolean(value: confValue): boolean { switch (value) { case true: case 'true': @@ -73,15 +74,15 @@ export async function loadConfigFile(filepath?: string): Promise { * */ const objectAssign = ( - target: Record, - source: Record, -): Record => + target: SSH | Server, + source: Record, +): SSH | Server => Object.fromEntries( Object.entries(source).map(([key, value]) => [ key, isUndefined(source[key]) ? target[key] : value, ]), - ); + ) as SSH | Server; /** * Merge cli arguemens with config object @@ -92,14 +93,14 @@ const objectAssign = ( * */ export function mergeCliConf( - opts: Record, + opts: Record, config: Config, ): Config { const ssl = { key: opts['ssl-key'], cert: opts['ssl-cert'], ...config.ssl, - }; + } as SSL; return { ssh: objectAssign(config.ssh, { user: opts['ssh-user'], @@ -117,10 +118,10 @@ export function mergeCliConf( title: opts.title, bypassHelmet: opts['bypass-helmet'], }) as Server, - command: isUndefined(opts.command) ? config.command : opts.command, + command: isUndefined(opts.command) ? config.command : `${opts.command}`, forceSSH: isUndefined(opts['force-ssh']) ? config.forceSSH - : opts['force-ssh'], + : ensureBoolean(opts['force-ssh']), ssl: isUndefined(ssl.key) || isUndefined(ssl.cert) ? undefined : ssl, }; } diff --git a/src/shared/interfaces.ts b/src/shared/interfaces.ts index 3cee8cc..0d6a984 100644 --- a/src/shared/interfaces.ts +++ b/src/shared/interfaces.ts @@ -1,4 +1,5 @@ export interface SSH { + [s: string]: string | number | boolean | undefined; user: string; host: string; auth: string; @@ -19,6 +20,7 @@ export interface SSLBuffer { } export interface Server { + [s: string]: string | number | boolean; port: number; host: string; title: string;