@aikidosec/ci-api-client 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +18 -18
- package/.env +1 -1
- package/.prettierrc +10 -10
- package/CONTRIBUTING.md +30 -30
- package/LICENSE +21 -21
- package/README.md +80 -78
- package/RELEASING.md +26 -26
- package/lib/aikidoApi.d.ts +60 -60
- package/lib/aikidoApi.js +52 -52
- package/lib/commands/apiKey.d.ts +8 -8
- package/lib/commands/apiKey.js +20 -18
- package/lib/commands/scan.d.ts +36 -36
- package/lib/commands/scan.js +188 -188
- package/lib/commands/upload.d.ts +23 -23
- package/lib/commands/upload.js +94 -94
- package/lib/configuration.d.ts +4 -4
- package/lib/configuration.js +13 -13
- package/lib/index.d.ts +12 -13
- package/lib/index.js +31 -39
- package/lib/output.d.ts +7 -7
- package/lib/output.js +53 -53
- package/package.json +51 -51
- package/src/aikidoApi.ts +148 -148
- package/src/commands/apiKey.ts +33 -30
- package/src/commands/scan.ts +370 -371
- package/src/commands/upload.ts +184 -184
- package/src/configuration.ts +21 -21
- package/src/index.ts +64 -74
- package/src/output.ts +87 -87
- package/tsconfig.json +27 -27
package/src/commands/scan.ts
CHANGED
|
@@ -1,371 +1,370 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
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
|
-
) => void | null;
|
|
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
|
-
let
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
userCliOptions.pollInterval
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
.
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
'
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
'
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
'
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
.
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
.
|
|
326
|
-
|
|
327
|
-
)
|
|
328
|
-
.option('--pull-request-
|
|
329
|
-
.
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
'
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
'
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
'
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
'
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
'
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
'
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
'
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
.
|
|
366
|
-
|
|
367
|
-
)
|
|
368
|
-
.
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
export default { cli, cliSetup, scan };
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Argument, Command, InvalidArgumentError, Option } from 'commander';
|
|
3
|
+
import { Ora } from 'ora';
|
|
4
|
+
import {
|
|
5
|
+
TPollIsScanningResult,
|
|
6
|
+
TPollScanCompletedDefaultBranchResult,
|
|
7
|
+
TPollScanFeatureBranchCompletedResult,
|
|
8
|
+
TScanApiOptions,
|
|
9
|
+
TStartScanResult,
|
|
10
|
+
pollScanStatus,
|
|
11
|
+
startScan,
|
|
12
|
+
} from '../aikidoApi.js';
|
|
13
|
+
import { getApiKey } from '../configuration.js';
|
|
14
|
+
import {
|
|
15
|
+
outputError,
|
|
16
|
+
outputHttpError,
|
|
17
|
+
outputLog,
|
|
18
|
+
startSpinner,
|
|
19
|
+
} from '../output.js';
|
|
20
|
+
|
|
21
|
+
type TScanArguments = {
|
|
22
|
+
repoId: string | number;
|
|
23
|
+
baseCommitId: string;
|
|
24
|
+
headCommitId: string;
|
|
25
|
+
branchName: string;
|
|
26
|
+
options: TScanApiOptions;
|
|
27
|
+
pollInterval: number;
|
|
28
|
+
onStart?: () => void | null;
|
|
29
|
+
onStartComplete?: (startResult: any) => void | null;
|
|
30
|
+
onStartFail?: (error: any) => void | null;
|
|
31
|
+
onScanStart?: (
|
|
32
|
+
startResult:
|
|
33
|
+
| TPollIsScanningResult
|
|
34
|
+
| TPollScanFeatureBranchCompletedResult
|
|
35
|
+
| TPollScanCompletedDefaultBranchResult
|
|
36
|
+
) => void | null;
|
|
37
|
+
onNextPoll?: (
|
|
38
|
+
pollResult:
|
|
39
|
+
| TPollIsScanningResult
|
|
40
|
+
| TPollScanFeatureBranchCompletedResult
|
|
41
|
+
| TPollScanCompletedDefaultBranchResult
|
|
42
|
+
) => void | null;
|
|
43
|
+
onScanComplete?: (
|
|
44
|
+
pollResult:
|
|
45
|
+
| TPollIsScanningResult
|
|
46
|
+
| TPollScanFeatureBranchCompletedResult
|
|
47
|
+
| TPollScanCompletedDefaultBranchResult
|
|
48
|
+
) => void | null;
|
|
49
|
+
onScanFail?: (error: any) => void | null;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type TScanCliOptions = {
|
|
53
|
+
pollInterval: number;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
type TScanUserCliOptions = {
|
|
57
|
+
pullRequestTitle?: string;
|
|
58
|
+
pullRequestUrl?: string;
|
|
59
|
+
selfManagedScanners?: string[];
|
|
60
|
+
failOnDependencyScan?: boolean;
|
|
61
|
+
failOnSastScan?: boolean;
|
|
62
|
+
failOnIacScan?: boolean;
|
|
63
|
+
minimumSeverityLevel?: string;
|
|
64
|
+
pollInterval?: number;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
async function cli(
|
|
68
|
+
repoId: string,
|
|
69
|
+
baseCommitId: string,
|
|
70
|
+
headCommitId: string,
|
|
71
|
+
branchName: string,
|
|
72
|
+
options: TScanUserCliOptions,
|
|
73
|
+
command: string
|
|
74
|
+
) {
|
|
75
|
+
const apiKey = getApiKey();
|
|
76
|
+
|
|
77
|
+
if (!apiKey) {
|
|
78
|
+
outputError('Please set an api key using: aikido-cli apikey <key>');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Process command options and group them into apiOptions hash
|
|
82
|
+
const { apiOptions, cliOptions } = parseCliOptions(options);
|
|
83
|
+
|
|
84
|
+
let loader: Ora | null;
|
|
85
|
+
let pollCount: number = 1;
|
|
86
|
+
|
|
87
|
+
// Setup different scan() event handlers
|
|
88
|
+
const onStart = () => {
|
|
89
|
+
loader = startSpinner('Starting Aikido Security scan');
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const onStartComplete = (startResult: TStartScanResult) => {
|
|
93
|
+
loader?.succeed(
|
|
94
|
+
`Aikido Security scan started (id: ${startResult.scan_id})`
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const onNextPoll = () => {
|
|
99
|
+
if (loader) {
|
|
100
|
+
loader.text = `Polling for Aikido Security scan to complete (${pollCount})`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
pollCount += 1;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const onScanStart = () => {
|
|
107
|
+
loader = startSpinner('Waiting for scan to complete');
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const onScanComplete = (pollResult: any) => {
|
|
111
|
+
if (pollResult.gate_passed === true) {
|
|
112
|
+
loader?.succeed('Scan completed, no new issues found');
|
|
113
|
+
} else {
|
|
114
|
+
loader?.fail('Scan completed with issues');
|
|
115
|
+
|
|
116
|
+
if (pollResult.open_issues_found) {
|
|
117
|
+
outputLog(
|
|
118
|
+
chalk.gray(
|
|
119
|
+
chalk.bold('Open issues found: ') + pollResult.open_issues_found
|
|
120
|
+
)
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (pollResult.issue_links) {
|
|
125
|
+
outputLog(
|
|
126
|
+
chalk.gray(
|
|
127
|
+
pollResult.issue_links
|
|
128
|
+
.map((issueLink: string) => '- ' + issueLink)
|
|
129
|
+
.join('\n')
|
|
130
|
+
)
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (pollResult.diff_url) {
|
|
135
|
+
outputLog(chalk.gray(`* Diff url: ${pollResult.diff_url}`));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
process.exit(10);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const onFail = (error: any) => {
|
|
143
|
+
loader?.fail();
|
|
144
|
+
|
|
145
|
+
if (error.response?.status && error.response?.status === 404) {
|
|
146
|
+
outputError(
|
|
147
|
+
'Please verify your repoId, baseCommitId, headCommitId and branchName'
|
|
148
|
+
);
|
|
149
|
+
} else {
|
|
150
|
+
outputHttpError(error);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
process.exit(1);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
await scan({
|
|
157
|
+
repoId,
|
|
158
|
+
baseCommitId,
|
|
159
|
+
headCommitId,
|
|
160
|
+
branchName,
|
|
161
|
+
options: apiOptions,
|
|
162
|
+
pollInterval: cliOptions.pollInterval,
|
|
163
|
+
onStart,
|
|
164
|
+
onStartComplete,
|
|
165
|
+
onStartFail: onFail,
|
|
166
|
+
onNextPoll,
|
|
167
|
+
onScanStart,
|
|
168
|
+
onScanComplete,
|
|
169
|
+
onScanFail: onFail,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export const scan = async ({
|
|
174
|
+
repoId,
|
|
175
|
+
baseCommitId,
|
|
176
|
+
headCommitId,
|
|
177
|
+
branchName,
|
|
178
|
+
options,
|
|
179
|
+
pollInterval = 5,
|
|
180
|
+
onStart,
|
|
181
|
+
onStartComplete,
|
|
182
|
+
onStartFail,
|
|
183
|
+
onScanStart,
|
|
184
|
+
onNextPoll,
|
|
185
|
+
onScanComplete,
|
|
186
|
+
onScanFail,
|
|
187
|
+
}: TScanArguments): Promise<void> => {
|
|
188
|
+
onStart?.();
|
|
189
|
+
|
|
190
|
+
let result: any | null = null;
|
|
191
|
+
|
|
192
|
+
// Initialize a scan and call onStartComplete, onStartFail
|
|
193
|
+
// handlers where needed
|
|
194
|
+
try {
|
|
195
|
+
result = await startScan({
|
|
196
|
+
repository_id: repoId,
|
|
197
|
+
base_commit_id: baseCommitId,
|
|
198
|
+
head_commit_id: headCommitId,
|
|
199
|
+
branch_name: branchName,
|
|
200
|
+
...options,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
if (result.scan_id) {
|
|
204
|
+
onStartComplete?.(result);
|
|
205
|
+
} else {
|
|
206
|
+
onStartFail?.(result);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
} catch (error) {
|
|
210
|
+
onStartFail?.(error);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
onScanStart?.(result);
|
|
215
|
+
let pollResult;
|
|
216
|
+
|
|
217
|
+
// Poll status with a setTimeout
|
|
218
|
+
const pollStatus = async () => {
|
|
219
|
+
try {
|
|
220
|
+
pollResult = await pollScanStatus(result.scan_id);
|
|
221
|
+
|
|
222
|
+
// If "all_scans_completed" returns true, call the onScanComplete
|
|
223
|
+
// handler, if not, re poll with `pollInterval`
|
|
224
|
+
// Note that onScanComplete can return a successfull or
|
|
225
|
+
// unsuccessfull scan result
|
|
226
|
+
if (pollResult.all_scans_completed === false) {
|
|
227
|
+
onNextPoll?.(pollResult);
|
|
228
|
+
setTimeout(pollStatus, pollInterval * 1000);
|
|
229
|
+
} else {
|
|
230
|
+
onScanComplete?.(pollResult);
|
|
231
|
+
}
|
|
232
|
+
} catch (error) {
|
|
233
|
+
onScanFail?.(error);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// Start polling
|
|
238
|
+
pollStatus();
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const parseCliOptions = (userCliOptions: TScanUserCliOptions) => {
|
|
242
|
+
// Version provided to the API corresponds with the version in package.json
|
|
243
|
+
// of the cli client
|
|
244
|
+
const apiOptions: TScanApiOptions = { version: '1.0.5' };
|
|
245
|
+
const cliOptions: TScanCliOptions = { pollInterval: 5 };
|
|
246
|
+
|
|
247
|
+
if (userCliOptions.pullRequestTitle) {
|
|
248
|
+
apiOptions.pull_request_metadata = {
|
|
249
|
+
...(apiOptions.pull_request_metadata ?? {}),
|
|
250
|
+
title: userCliOptions.pullRequestTitle,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (userCliOptions.pullRequestUrl) {
|
|
254
|
+
apiOptions.pull_request_metadata = {
|
|
255
|
+
...(apiOptions.pull_request_metadata ?? {}),
|
|
256
|
+
url: userCliOptions.pullRequestUrl,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
if (userCliOptions.selfManagedScanners) {
|
|
260
|
+
apiOptions.self_managed_scanners = userCliOptions.selfManagedScanners;
|
|
261
|
+
}
|
|
262
|
+
if (userCliOptions.failOnDependencyScan != undefined) {
|
|
263
|
+
apiOptions.fail_on_dependency_scan = userCliOptions.failOnDependencyScan;
|
|
264
|
+
}
|
|
265
|
+
if (userCliOptions.failOnSastScan != undefined) {
|
|
266
|
+
apiOptions.fail_on_sast_scan = userCliOptions.failOnSastScan;
|
|
267
|
+
}
|
|
268
|
+
if (userCliOptions.failOnIacScan != undefined) {
|
|
269
|
+
apiOptions.fail_on_iac_scan = userCliOptions.failOnIacScan;
|
|
270
|
+
}
|
|
271
|
+
if (userCliOptions.minimumSeverityLevel) {
|
|
272
|
+
apiOptions.minimum_severity = userCliOptions.minimumSeverityLevel;
|
|
273
|
+
}
|
|
274
|
+
if (
|
|
275
|
+
userCliOptions.pollInterval &&
|
|
276
|
+
(isNaN(userCliOptions.pollInterval) || userCliOptions.pollInterval <= 0)
|
|
277
|
+
) {
|
|
278
|
+
outputError('Please provide a valid poll interval');
|
|
279
|
+
} else if (userCliOptions.pollInterval) {
|
|
280
|
+
cliOptions.pollInterval = userCliOptions.pollInterval;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return { apiOptions, cliOptions };
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const validateCommitId = (value: string) => {
|
|
287
|
+
const testCommitId = (commitId: string): boolean =>
|
|
288
|
+
commitId.length === 40 && /^[0-9a-f]{40}$/.test(commitId);
|
|
289
|
+
|
|
290
|
+
if (testCommitId(value) === false) {
|
|
291
|
+
throw new InvalidArgumentError('Please provide a valid commit ID');
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return value;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export const cliSetup = (program: Command) =>
|
|
298
|
+
program
|
|
299
|
+
.command('scan')
|
|
300
|
+
.addArgument(
|
|
301
|
+
new Argument(
|
|
302
|
+
'<repository_id>',
|
|
303
|
+
'The internal GitHub/Gitlab/Bitbucket/.. repository id you want to scan.'
|
|
304
|
+
).argRequired()
|
|
305
|
+
)
|
|
306
|
+
.addArgument(
|
|
307
|
+
new Argument(
|
|
308
|
+
'<base_commit_id>',
|
|
309
|
+
'The base commit of the code you want to scan (e.g. the commit where you branched from for your PR or the initial commit of your repo)'
|
|
310
|
+
)
|
|
311
|
+
.argRequired()
|
|
312
|
+
.argParser(validateCommitId)
|
|
313
|
+
)
|
|
314
|
+
.addArgument(
|
|
315
|
+
new Argument(
|
|
316
|
+
'<head_commit_id>',
|
|
317
|
+
'The latest commit you want to include in your scan (e.g. the latest commit id of your pull request)'
|
|
318
|
+
)
|
|
319
|
+
.argRequired()
|
|
320
|
+
.argParser(validateCommitId)
|
|
321
|
+
)
|
|
322
|
+
.addArgument(
|
|
323
|
+
new Argument('<branch_name>', 'The branch name')
|
|
324
|
+
.argOptional()
|
|
325
|
+
.default('main')
|
|
326
|
+
)
|
|
327
|
+
.option('--pull-request-title <title>', 'Your pull request title')
|
|
328
|
+
.option('--pull-request-url <url>', 'Your pull request URL')
|
|
329
|
+
.addOption(
|
|
330
|
+
new Option(
|
|
331
|
+
'--self-managed-scanners <scanners...>',
|
|
332
|
+
'Set the minimum severity level. Accepted options are: LOW, MEDIUM, HIGH and CRITICAL.'
|
|
333
|
+
).choices(['checkov', 'json-sbom'])
|
|
334
|
+
)
|
|
335
|
+
.option(
|
|
336
|
+
'--expected-amount-json-sboms <amount>',
|
|
337
|
+
'The expected amount of json sbombs'
|
|
338
|
+
)
|
|
339
|
+
.addOption(
|
|
340
|
+
new Option(
|
|
341
|
+
'--no-fail-on-dependency-scan',
|
|
342
|
+
"Don't fail when scanning depedencies..."
|
|
343
|
+
)
|
|
344
|
+
)
|
|
345
|
+
.option(
|
|
346
|
+
'--fail-on-sast-scan',
|
|
347
|
+
'Let Aikido fail when new static code analysis issues have been detected...'
|
|
348
|
+
)
|
|
349
|
+
.option(
|
|
350
|
+
'--fail-on-iac-scan',
|
|
351
|
+
'Let Aikido fail when new infrastructure as code issues have been detected...'
|
|
352
|
+
)
|
|
353
|
+
.addOption(
|
|
354
|
+
new Option(
|
|
355
|
+
'--minimum-severity-level <level>',
|
|
356
|
+
'Set the minimum severity level. Accepted options are: LOW, MEDIUM, HIGH and CRITICAL.'
|
|
357
|
+
).choices(['LOW', 'MEDIUM', 'HIGH', 'CRITICAL'])
|
|
358
|
+
)
|
|
359
|
+
.addOption(
|
|
360
|
+
new Option(
|
|
361
|
+
'--poll-interval [interval]',
|
|
362
|
+
'The poll interval when checking for an updated scan result'
|
|
363
|
+
)
|
|
364
|
+
.preset(5)
|
|
365
|
+
.argParser(parseFloat)
|
|
366
|
+
)
|
|
367
|
+
.description('Run a scan of an Aikido repo.')
|
|
368
|
+
.action(cli);
|
|
369
|
+
|
|
370
|
+
export default { cli, cliSetup, scan };
|