From 4ec71cc300999dec2a7c928c7f623f582dfdbbc4 Mon Sep 17 00:00:00 2001 From: Jason Zou Date: Sun, 22 Oct 2023 18:48:05 -0400 Subject: [PATCH] Added artifact directory assessing functionality to start.mjs --- lib/commands/path_detect.mjs | 3 +-- lib/commands/start.mjs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/commands/path_detect.mjs b/lib/commands/path_detect.mjs index 98db1ddf..f0fa9c0a 100644 --- a/lib/commands/path_detect.mjs +++ b/lib/commands/path_detect.mjs @@ -39,9 +39,8 @@ export function isSystemDirectory(dirPath) { '/srv/' ]; - // Combine both lists + const systemDirs = windowsSystemDirs.concat(linuxSystemDirs); - // Check if the directory path is an exact match to any known system directory return systemDirs.includes(dirPath); } diff --git a/lib/commands/start.mjs b/lib/commands/start.mjs index c7d7973b..9a44c12b 100644 --- a/lib/commands/start.mjs +++ b/lib/commands/start.mjs @@ -12,9 +12,15 @@ import {decoratedError, ErrorType} from "../browserup_errors.mjs"; import {WebConsoleClient} from "../services/webconsole_client.mjs"; import {calculateSHA256Hash} from "../utils/hash_utils.mjs"; import FormData from "form-data"; +import {getDirectorySize} from "../commands/detect_dir_size.mjs" +import {isSystemDirectory} from "../commands/path_detect.mjs"; +import { exit } from "process"; +const MAX_DIR_SIZE = 200*124*124 + export async function start(options, programOpts) { - log.info("Running Start"); + + log.info("Running Start!"); const configRepo = new ConfigRepository(programOpts.config); const scenarioName = configRepo.config.model.scenario.name; const config = configRepo.config; @@ -22,7 +28,7 @@ export async function start(options, programOpts) { log.info(`Starting scenario ${scenarioName}...`); let credentials; - if (options.redeploy) { + if (options.redeploy) {cd await destroy(options); } @@ -89,11 +95,31 @@ async function uploadArtifacts(apiToken, scenario, workingDir) { if (profile.artifactDir) { log.debug(`Uploading artifact for profile: ${profile.name}`) const artifactDir = path.join(workingDir, profile.artifactDir); + assessArtifactDirectoryValidity(artifactDir) profile.artifactSha = await uploadArtifactIfNeeded(apiToken, artifactDir); } } + + + +async function assessArtifactDirectoryValidity(artifact_dir) { + let directorySize= getDirectorySize(artifact_dir); + let isSysDir = isSystemDirectory(artifact_dir); + + + if(directorySize>MAX_DIR_SIZE){ + log.info("WARNING. The current directory exceeds 200MB in size. Please ensure that you are using the correct directory."); + process.exit(1); + } + + if(isSysDir == true){ + log.info("WARNING. You are currently in a system directory(ex: /bin,sys32), please switch to a subdirectory before proceeding."); + process.exit(1); + } + return; } + async function uploadArtifactIfNeeded(apiToken, artifactDir) { const zippedFilepath = await zipArtifactDir(artifactDir); const sha256 = await calculateSHA256Hash(zippedFilepath) @@ -152,3 +178,4 @@ async function getArtifactStatus(apiToken, artifactDir, sha) { } } +} \ No newline at end of file