-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmsdo.ts
More file actions
113 lines (98 loc) · 4.46 KB
/
msdo.ts
File metadata and controls
113 lines (98 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import tl = require('azure-pipelines-task-lib/task');
import { CommandType } from './msdo-helpers';
import { IMicrosoftSecurityDevOps } from './msdo-interface';
import * as client from '@microsoft/security-devops-azdevops-task-lib/msdo-client';
import * as msdoCommon from '@microsoft/security-devops-azdevops-task-lib/msdo-common';
/*
* Class for Container Mapping functionality in Code to Cloud Decorator task.
*/
export class MicrosoftSecurityDevOps implements IMicrosoftSecurityDevOps {
private readonly commandType: CommandType;
readonly succeedOnError: boolean;
constructor(commandType: CommandType) {
this.succeedOnError = false;
this.commandType = commandType;
}
private async runMsdo() {
let args: string[] = [];
let config: string = tl.getInput('config');
if (!msdoCommon.isNullOrWhiteSpace(config)) {
args.push('-c');
args.push(config);
}
let policy: string = tl.getInput('policy');
if (!msdoCommon.isNullOrWhiteSpace(policy)) {
if (policy === 'none') {
args.push('--no-policy');
} else {
// Use the defined policy
args.push('-p');
args.push(policy);
}
} else {
// If the policy is not user defined, default to azuredevops
args.push('-p');
args.push('azuredevops');
}
let categoriesString: string = tl.getInput('categories');
if (!msdoCommon.isNullOrWhiteSpace(categoriesString)) {
args.push('--categories');
let categories = categoriesString.split(',');
for (let i = 0; i < categories.length; i++) {
let category = categories[i];
if (category.toLowerCase() == "secrets" && categories.length == 1) {
console.log('------------------------------------------------------------------------------');
console.log('Effective September 20th 2023, the Secret Scanning option (CredScan) within Microsoft Security DevOps (MSDO) Extension for Azure DevOps is deprecated. MSDO Secret Scanning is replaced by the Configure GitHub Advanced Security for Azure DevOps features - https://learn.microsoft.com/en-us/azure/devops/repos/security/configure-github-advanced-security-features#set-up-secret-scanning.');
console.log('------------------------------------------------------------------------------');
return;
} else if (!msdoCommon.isNullOrWhiteSpace(category)) {
args.push(category.trim());
}
}
}
let languagesString: string = tl.getInput('languages');
if (!msdoCommon.isNullOrWhiteSpace(languagesString)) {
args.push('--languages');
let languages = languagesString.split(',');
for (let i = 0; i < languages.length; i++) {
let language = languages[i];
if (!msdoCommon.isNullOrWhiteSpace(language)) {
args.push(language.trim());
}
}
}
let toolsString: string = tl.getInput('tools');
if (!msdoCommon.isNullOrWhiteSpace(toolsString)) {
args.push('--tool');
let tools = toolsString.split(',');
for (let i = 0; i < tools.length; i++) {
let tool = tools[i];
if (!msdoCommon.isNullOrWhiteSpace(tool)) {
args.push(tool.trim());
}
}
}
let publish: boolean = tl.getBoolInput('publish');
let artifactName: string = tl.getInput('artifactName');
let successfulExitCodes: number[] = [0];
let breakEnabled: boolean = tl.getBoolInput('break');
if (!breakEnabled) {
// allow break
successfulExitCodes.push(8);
}
args.push('--rich-exit-code');
await client.run(args, successfulExitCodes, publish, artifactName);
}
/*
* Run the specified function based on the task type
*/
async run() {
switch (this.commandType) {
case CommandType.Run:
await this.runMsdo();
break;
default:
throw new Error(`Invalid command type: ${this.commandType}`);
}
}
}