Skip to content

Commit

Permalink
Added artifact directory assessing functionality to start.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujas committed Oct 22, 2023
1 parent 11580fa commit 4ec71cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/commands/path_detect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
31 changes: 29 additions & 2 deletions lib/commands/start.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ 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;

log.info(`Starting scenario ${scenarioName}...`);

let credentials;
if (options.redeploy) {
if (options.redeploy) {cd
await destroy(options);
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -152,3 +178,4 @@ async function getArtifactStatus(apiToken, artifactDir, sha) {
}
}

}

0 comments on commit 4ec71cc

Please sign in to comment.