Skip to content

Commit 2cc7798

Browse files
author
Seth Rait
committed
Cleanup code
1 parent c23429e commit 2cc7798

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

lib/main.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
3535
const core = __importStar(require("@actions/core"));
3636
const msdo_1 = require("./msdo");
3737
const msdo_interface_1 = require("./msdo-interface");
38+
const common = __importStar(require("@microsoft/security-devops-actions-toolkit/msdo-common"));
39+
const msdo_helpers_1 = require("./msdo-helpers");
3840
function runMain() {
3941
return __awaiter(this, void 0, void 0, function* () {
40-
yield (0, msdo_interface_1.getExecutor)(msdo_1.MicrosoftSecurityDevOps).runMain();
42+
if (shouldRunMain()) {
43+
yield (0, msdo_interface_1.getExecutor)(msdo_1.MicrosoftSecurityDevOps).runMain();
44+
}
45+
else {
46+
console.log("Scanning is not enabled. Skipping...");
47+
}
4148
});
4249
}
4350
runMain().catch(error => {
4451
core.setFailed(error);
4552
});
53+
function shouldRunMain() {
54+
let toolsString = core.getInput('tools');
55+
if (!common.isNullOrWhiteSpace(toolsString)) {
56+
let tools = toolsString.split(',');
57+
if (tools.length == 1 && tools[0].trim() == msdo_helpers_1.Tools.ContainerMapping) {
58+
return false;
59+
}
60+
return true;
61+
}
62+
}

src/main.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
import * as core from '@actions/core';
22
import { MicrosoftSecurityDevOps } from './msdo';
33
import { getExecutor } from './msdo-interface';
4+
import * as common from '@microsoft/security-devops-actions-toolkit/msdo-common';
5+
import { Tools } from './msdo-helpers';
46

57
async function runMain() {
6-
await getExecutor(MicrosoftSecurityDevOps).runMain();
8+
if (shouldRunMain())
9+
{
10+
await getExecutor(MicrosoftSecurityDevOps).runMain();
11+
}
12+
else {
13+
console.log("Scanning is not enabled. Skipping...");
14+
}
715
}
816

917
runMain().catch(error => {
1018
core.setFailed(error);
11-
});
19+
});
20+
21+
/**
22+
* Returns false if the 'tools' input is specified and the only tool on the list is 'container-mapping'.
23+
* This is because the MicrosoftSecurityDevOps executer does not have a workload for the container-mapping tool.
24+
*/
25+
function shouldRunMain() {
26+
let toolsString: string = core.getInput('tools');
27+
if (!common.isNullOrWhiteSpace(toolsString)) {
28+
let tools = toolsString.split(',');
29+
if (tools.length == 1 && tools[0].trim() == Tools.ContainerMapping) {
30+
return false;
31+
}
32+
return true;
33+
}
34+
}

src/msdo-helpers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os from 'os';
22
import { Writable } from "stream";
3-
import { IMicrosoftSecurityDevOps, IMicrosoftSecurityDevOpsFactory } from './msdo-interface';
43

54
/**
65
* Enum for the possible inputs for the task (specified in action.yml)

src/msdo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class MicrosoftSecurityDevOps implements IMicrosoftSecurityDevOps {
7373
let tool = tools[i];
7474
let toolTrimmed = tool.trim();
7575
if (!common.isNullOrWhiteSpace(tool)
76-
&& tool != Tools.ContainerMapping
76+
&& tool != Tools.ContainerMapping // This tool is not handled by this executor
7777
&& includedTools.indexOf(toolTrimmed) == -1) {
7878
if (includedTools.length == 0) {
7979
args.push('--tool');

0 commit comments

Comments
 (0)