From 4efa94ec1072743b31cd94d346d79f7d7ac4330a Mon Sep 17 00:00:00 2001 From: BluJ Date: Fri, 7 Apr 2023 15:06:55 -0600 Subject: [PATCH] chore: UPdate the shell --- lib/health/checkFns/checkPortListening.ts | 11 +++++++++-- lib/types.ts | 4 ---- lib/util/index.ts | 2 +- lib/util/{shell.ts => parseCommand.ts} | 5 ++++- package-lock.json | 4 ++-- package.json | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) rename lib/util/{shell.ts => parseCommand.ts} (87%) diff --git a/lib/health/checkFns/checkPortListening.ts b/lib/health/checkFns/checkPortListening.ts index 0d736e0..b939114 100644 --- a/lib/health/checkFns/checkPortListening.ts +++ b/lib/health/checkFns/checkPortListening.ts @@ -1,4 +1,5 @@ import { Effects } from "../../types"; +import { parseCommand } from "../../util/parseCommand"; import { CheckResult } from "./CheckResult"; export function containsAddress(x: string, port: number) { const readPorts = x @@ -25,8 +26,14 @@ export async function checkPortListening( } = {} ): Promise { const hasAddress = - containsAddress(await effects.shell("cat /proc/net/tcp"), port) || - containsAddress(await effects.shell("cat /proc/net/udp"), port); + containsAddress( + await effects.runCommand(parseCommand("cat /proc/net/tcp")), + port + ) || + containsAddress( + await effects.runCommand(parseCommand("cat /proc/net/udp")), + port + ); if (hasAddress) { return { status: "passing", message }; } diff --git a/lib/types.ts b/lib/types.ts index f45de66..3ce899e 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -129,10 +129,6 @@ export type Effects = { path: string; }): Promise>; - shell( - command: string, - options?: { timeoutMillis?: number | null } - ): Promise; runCommand(input: { command: string; args?: string[]; diff --git a/lib/util/index.ts b/lib/util/index.ts index c09b0a9..fcb833d 100644 --- a/lib/util/index.ts +++ b/lib/util/index.ts @@ -3,7 +3,7 @@ import * as T from "../types"; export { guardAll, typeFromProps } from "./propertiesMatcher"; export { default as nullIfEmpty } from "./nullIfEmpty"; export { FileHelper } from "./fileHelper"; -export { sh } from "./shell"; +export { parseCommand as sh } from "./parseCommand"; /** Used to check if the file exists before hand */ export const exists = ( diff --git a/lib/util/shell.ts b/lib/util/parseCommand.ts similarity index 87% rename from lib/util/shell.ts rename to lib/util/parseCommand.ts index 68522bf..062fbb3 100644 --- a/lib/util/shell.ts +++ b/lib/util/parseCommand.ts @@ -46,7 +46,10 @@ const quoteSeperated = (s: string, quote: typeof quotes) => { return values; }; -export function sh(shellCommand: string) { +type ValidIfNoStupidEscape = A extends `${string}'"'"'${string}` ? never : A; +export function parseCommand( + shellCommand: ValidIfNoStupidEscape +) { const [command, ...args] = quoteSeperated(shellCommand, quotes).filter( Boolean ); diff --git a/package-lock.json b/package-lock.json index d90d4a2..d0d53f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "start-sdk", - "version": "0.4.0-lib0.charlie8", + "version": "0.4.0-lib0.charlie9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "start-sdk", - "version": "0.4.0-lib0.charlie8", + "version": "0.4.0-lib0.charlie9", "license": "MIT", "dependencies": { "@iarna/toml": "^2.2.5", diff --git a/package.json b/package.json index 37fab68..01c397e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "start-sdk", - "version": "0.4.0-lib0.charlie8", + "version": "0.4.0-lib0.charlie9", "description": "For making the patterns that are wanted in making services for the startOS.", "main": "./lib/index.js", "types": "./lib/index.d.ts",