mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Update main.js code flow so proxy always gets stopped + add comment on why exit status is handled in bin/aikido-(tool).js
This commit is contained in:
parent
ccaa7934ee
commit
3ef4ed8bad
2 changed files with 30 additions and 16 deletions
|
|
@ -16,16 +16,17 @@ export async function main(args) {
|
||||||
args = initializeCliArguments(args);
|
args = initializeCliArguments(args);
|
||||||
|
|
||||||
if (shouldScanCommand(args)) {
|
if (shouldScanCommand(args)) {
|
||||||
await scanCommand(args);
|
const resultCode = await scanCommand(args);
|
||||||
|
|
||||||
|
// Returning the exit code back to the caller allows the promise
|
||||||
|
// to be awaited in the bin files and return the correct exit code
|
||||||
|
if (resultCode !== 0) {
|
||||||
|
return resultCode;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
ui.writeError("Failed to check for malicious packages:", error.message);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = await getPackageManager().runCommand(args);
|
var result = await getPackageManager().runCommand(args);
|
||||||
|
|
||||||
await proxy.stopServer();
|
|
||||||
proxy.verifyNoMaliciousPackages();
|
proxy.verifyNoMaliciousPackages();
|
||||||
|
|
||||||
ui.emptyLine();
|
ui.emptyLine();
|
||||||
|
|
@ -35,5 +36,16 @@ export async function main(args) {
|
||||||
)} Safe-chain: Command completed, no malicious packages found.`
|
)} Safe-chain: Command completed, no malicious packages found.`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Returning the exit code back to the caller allows the promise
|
||||||
|
// to be awaited in the bin files and return the correct exit code
|
||||||
return result.status;
|
return result.status;
|
||||||
|
} catch (error) {
|
||||||
|
ui.writeError("Failed to check for malicious packages:", error.message);
|
||||||
|
|
||||||
|
// Returning the exit code back to the caller allows the promise
|
||||||
|
// to be awaited in the bin files and return the correct exit code
|
||||||
|
return 1;
|
||||||
|
} finally {
|
||||||
|
await proxy.stopServer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,11 @@ export async function scanCommand(args) {
|
||||||
|
|
||||||
if (!audit || audit.isAllowed) {
|
if (!audit || audit.isAllowed) {
|
||||||
spinner.stop();
|
spinner.stop();
|
||||||
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
printMaliciousChanges(audit.disallowedChanges, spinner);
|
printMaliciousChanges(audit.disallowedChanges, spinner);
|
||||||
await onMalwareFound();
|
await onMalwareFound();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue