Skip to content

Commit

Permalink
fix: knoxctl command
Browse files Browse the repository at this point in the history
  • Loading branch information
swarit-pandey committed Sep 9, 2024
1 parent 1d7a034 commit b8e58bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
10 changes: 3 additions & 7 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ async function runKnoxctlScan(): Promise<void> {
const knoxctlOptions = [
{ name: "all", flag: "--all", type: "boolean" },
{ name: "system", flag: "--system", type: "boolean" },
{ name: "output", flag: "--output", type: "string" },
{ name: "ignore-alerts", flag: "--ignore-alerts", type: "string" },
{ name: "min-severity", flag: "--min-severity", type: "string" },
];
Expand Down Expand Up @@ -165,11 +164,12 @@ async function runKnoxctlScan(): Promise<void> {
policyCommand.push("--policies", policies);
}

// Run the policy command first
await exec.exec(policyCommand[0], policyCommand.slice(1));

const scanCommand: string[] = ["knoxctl", "scan"];
let outputDir = getOutputDir();
const outputDir = path.join(getOutputDir(), "knoxctl-results");

scanCommand.push("--output", outputDir);

for (const option of knoxctlOptions) {
let value: boolean | string;
Expand All @@ -182,15 +182,11 @@ async function runKnoxctlScan(): Promise<void> {
} else if (option.type === "string") {
value = core.getInput(option.name);
if (value) {
if (option.name === "output") {
outputDir = value;
}
scanCommand.push(option.flag, value);
}
}
}

// Ensure the output directory exists
if (!fs.existsSync(outputDir)) {
log(`Creating output directory: ${outputDir}`);
fs.mkdirSync(outputDir, { recursive: true });
Expand Down
37 changes: 2 additions & 35 deletions src/post/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,41 +212,8 @@ async function run(): Promise<void> {
// Increase wait time and add file system sync
await new Promise((resolve) => setTimeout(resolve, 15000));
fs.readdirSync(getOutputDir()); // Force a file system sync

// List contents of current working directory
const currentDir = process.cwd();
log(`Current working directory: ${currentDir}`);
log("Contents of current working directory:");
const currentDirFiles = fs.readdirSync(currentDir);
for (const file of currentDirFiles) {
const filePath = path.join(currentDir, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
log(`- [DIR] ${file}`);
// List contents of subdirectories
const subDirFiles = fs.readdirSync(filePath);
for (const subFile of subDirFiles) {
log(` - ${subFile}`);
}
} else {
log(`- ${file}`);
}
}

// List contents of expected output directory
const outputDir = getOutputDir();
log(`\nExpected output directory: ${outputDir}`);
log("Contents of expected output directory:");
if (fs.existsSync(outputDir)) {
const outputDirFiles = fs.readdirSync(outputDir);
for (const file of outputDirFiles) {
log(`- ${file}`);
}
} else {
log("Output directory does not exist.");
}

await processResults();

await processResults();

await uploadArtifacts(outputDir);

Expand Down

0 comments on commit b8e58bc

Please sign in to comment.