scanoss 0.2.8 → 0.2.12
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/CHANGELOG.md +2 -0
- package/LICENSE +20 -18
- package/README.md +6 -5
- package/build/main/bin/cli-bin.js +10 -3
- package/build/main/commands/dep.d.ts +1 -0
- package/build/main/commands/dep.js +26 -0
- package/build/main/commands/scan.js +20 -38
- package/build/main/index.d.ts +3 -1
- package/build/main/index.js +4 -2
- package/build/main/lib/dependencies/Dependency.d.ts +9 -0
- package/build/main/lib/dependencies/Dependency.js +50 -0
- package/build/main/lib/dependencies/DependencyTypes.d.ts +19 -0
- package/build/main/lib/dependencies/DependencyTypes.js +3 -0
- package/build/main/lib/dependencies/PurlGenerator.d.ts +2 -0
- package/build/main/lib/dependencies/PurlGenerator.js +39 -0
- package/build/main/lib/dependencies/parsers/golangParser.d.ts +0 -0
- package/build/main/lib/dependencies/parsers/golangParser.js +3 -0
- package/build/main/lib/dependencies/parsers/mavenParser.d.ts +2 -0
- package/build/main/lib/dependencies/parsers/mavenParser.js +44 -0
- package/build/main/lib/dependencies/parsers/npmParser.d.ts +3 -0
- package/build/main/lib/dependencies/parsers/npmParser.js +45 -0
- package/build/main/lib/dependencies/parsers/pyParser.d.ts +2 -0
- package/build/main/lib/dependencies/parsers/pyParser.js +51 -0
- package/build/main/lib/dependencies/parsers/rubyParser.d.ts +3 -0
- package/build/main/lib/dependencies/parsers/rubyParser.js +135 -0
- package/build/main/lib/dependencies/parsers/types.d.ts +15 -0
- package/build/main/lib/dependencies/parsers/types.js +33 -0
- package/build/main/lib/dependencies/parsers/utils.d.ts +2 -0
- package/build/main/lib/dependencies/parsers/utils.js +20 -0
- package/build/main/lib/dependencies/src/PurlGenerator.d.ts +2 -0
- package/build/main/lib/dependencies/src/PurlGenerator.js +62 -0
- package/build/main/lib/dependencies/src/parsers/golangParser.d.ts +0 -0
- package/build/main/lib/dependencies/src/parsers/golangParser.js +3 -0
- package/build/main/lib/dependencies/src/parsers/mavenParser.d.ts +2 -0
- package/build/main/lib/dependencies/src/parsers/mavenParser.js +44 -0
- package/build/main/lib/dependencies/src/parsers/npmParser.d.ts +3 -0
- package/build/main/lib/dependencies/src/parsers/npmParser.js +45 -0
- package/build/main/lib/dependencies/src/parsers/pyParser.d.ts +2 -0
- package/build/main/lib/dependencies/src/parsers/pyParser.js +51 -0
- package/build/main/lib/dependencies/src/parsers/rubyParser.d.ts +3 -0
- package/build/main/lib/dependencies/src/parsers/rubyParser.js +135 -0
- package/build/main/lib/dependencies/src/parsers/types.d.ts +15 -0
- package/build/main/lib/dependencies/src/parsers/types.js +33 -0
- package/build/main/lib/dependencies/src/parsers/utils.d.ts +2 -0
- package/build/main/lib/dependencies/src/parsers/utils.js +19 -0
- package/build/main/lib/dependencyScan/dependencyScan.d.ts +2 -0
- package/build/main/lib/dependencyScan/dependencyScan.js +37 -0
- package/build/main/lib/dependencyScan/parser.d.ts +7 -0
- package/build/main/lib/dependencyScan/parser.js +41 -0
- package/build/main/lib/dependencyScan/utils.d.ts +1 -0
- package/build/main/lib/dependencyScan/utils.js +16 -0
- package/build/main/lib/scanner/Dependency/dependency.d.ts +9 -0
- package/build/main/lib/scanner/Dependency/dependency.js +46 -0
- package/build/main/lib/scanner/Dependency/dependencyScan.d.ts +9 -0
- package/build/main/lib/scanner/Dependency/dependencyScan.js +48 -0
- package/build/main/lib/scanner/Dependency/parser.d.ts +7 -0
- package/build/main/lib/scanner/Dependency/parser.js +41 -0
- package/build/main/lib/scanner/Dependency/utils.d.ts +1 -0
- package/build/main/lib/scanner/Dependency/utils.js +16 -0
- package/build/main/lib/scanner/Dispatcher/DispatchableItem.js +1 -1
- package/build/main/lib/scanner/Dispatcher/Dispatcher.d.ts +3 -2
- package/build/main/lib/scanner/Dispatcher/Dispatcher.js +15 -13
- package/build/main/lib/scanner/Scannable/ScannableItem.d.ts +4 -3
- package/build/main/lib/scanner/Scannable/ScannableItem.js +6 -6
- package/build/main/lib/scanner/Scanner.d.ts +7 -6
- package/build/main/lib/scanner/Scanner.js +45 -42
- package/build/main/lib/scanner/ScannerTypes.d.ts +32 -0
- package/build/main/lib/scanner/ScannerTypes.js +35 -0
- package/build/main/lib/scanner/Winnower/Winnower.d.ts +5 -2
- package/build/main/lib/scanner/Winnower/Winnower.js +29 -24
- package/build/main/lib/scanner/Winnower/WinnowerResponse.d.ts +3 -0
- package/build/main/lib/scanner/Winnower/WinnowerResponse.js +7 -1
- package/build/main/lib/tree/Tree.js +4 -4
- package/build/module/bin/cli-bin.js +10 -3
- package/build/module/commands/dep.d.ts +1 -0
- package/build/module/commands/dep.js +19 -0
- package/build/module/commands/scan.js +16 -34
- package/build/module/index.d.ts +3 -1
- package/build/module/index.js +4 -2
- package/build/module/lib/dependencies/Dependency.d.ts +9 -0
- package/build/module/lib/dependencies/Dependency.js +45 -0
- package/build/module/lib/dependencies/DependencyTypes.d.ts +19 -0
- package/build/module/lib/dependencies/DependencyTypes.js +2 -0
- package/build/module/lib/dependencies/PurlGenerator.d.ts +2 -0
- package/build/module/lib/dependencies/PurlGenerator.js +32 -0
- package/build/module/lib/dependencies/parsers/golangParser.d.ts +0 -0
- package/build/module/lib/dependencies/parsers/golangParser.js +3 -0
- package/build/module/lib/dependencies/parsers/mavenParser.d.ts +2 -0
- package/build/module/lib/dependencies/parsers/mavenParser.js +37 -0
- package/build/module/lib/dependencies/parsers/npmParser.d.ts +3 -0
- package/build/module/lib/dependencies/parsers/npmParser.js +37 -0
- package/build/module/lib/dependencies/parsers/pyParser.d.ts +2 -0
- package/build/module/lib/dependencies/parsers/pyParser.js +44 -0
- package/build/module/lib/dependencies/parsers/rubyParser.d.ts +3 -0
- package/build/module/lib/dependencies/parsers/rubyParser.js +132 -0
- package/build/module/lib/dependencies/parsers/types.d.ts +15 -0
- package/build/module/lib/dependencies/parsers/types.js +32 -0
- package/build/module/lib/dependencies/parsers/utils.d.ts +2 -0
- package/build/module/lib/dependencies/parsers/utils.js +15 -0
- package/build/module/lib/dependencies/src/PurlGenerator.d.ts +2 -0
- package/build/module/lib/dependencies/src/PurlGenerator.js +55 -0
- package/build/module/lib/dependencies/src/parsers/golangParser.d.ts +0 -0
- package/build/module/lib/dependencies/src/parsers/golangParser.js +3 -0
- package/build/module/lib/dependencies/src/parsers/mavenParser.d.ts +2 -0
- package/build/module/lib/dependencies/src/parsers/mavenParser.js +37 -0
- package/build/module/lib/dependencies/src/parsers/npmParser.d.ts +3 -0
- package/build/module/lib/dependencies/src/parsers/npmParser.js +37 -0
- package/build/module/lib/dependencies/src/parsers/pyParser.d.ts +2 -0
- package/build/module/lib/dependencies/src/parsers/pyParser.js +44 -0
- package/build/module/lib/dependencies/src/parsers/rubyParser.d.ts +3 -0
- package/build/module/lib/dependencies/src/parsers/rubyParser.js +132 -0
- package/build/module/lib/dependencies/src/parsers/types.d.ts +15 -0
- package/build/module/lib/dependencies/src/parsers/types.js +32 -0
- package/build/module/lib/dependencies/src/parsers/utils.d.ts +2 -0
- package/build/module/lib/dependencies/src/parsers/utils.js +14 -0
- package/build/module/lib/dependencyScan/dependencyScan.d.ts +2 -0
- package/build/module/lib/dependencyScan/dependencyScan.js +29 -0
- package/build/module/lib/dependencyScan/parser.d.ts +7 -0
- package/build/module/lib/dependencyScan/parser.js +38 -0
- package/build/module/lib/dependencyScan/utils.d.ts +1 -0
- package/build/module/lib/dependencyScan/utils.js +12 -0
- package/build/module/lib/scanner/Dependency/dependency.d.ts +9 -0
- package/build/module/lib/scanner/Dependency/dependency.js +38 -0
- package/build/module/lib/scanner/Dependency/dependencyScan.d.ts +9 -0
- package/build/module/lib/scanner/Dependency/dependencyScan.js +40 -0
- package/build/module/lib/scanner/Dependency/parser.d.ts +7 -0
- package/build/module/lib/scanner/Dependency/parser.js +38 -0
- package/build/module/lib/scanner/Dependency/utils.d.ts +1 -0
- package/build/module/lib/scanner/Dependency/utils.js +12 -0
- package/build/module/lib/scanner/Dispatcher/DispatchableItem.js +1 -1
- package/build/module/lib/scanner/Dispatcher/Dispatcher.d.ts +3 -2
- package/build/module/lib/scanner/Dispatcher/Dispatcher.js +6 -4
- package/build/module/lib/scanner/Scannable/ScannableItem.d.ts +4 -3
- package/build/module/lib/scanner/Scannable/ScannableItem.js +7 -7
- package/build/module/lib/scanner/Scanner.d.ts +7 -6
- package/build/module/lib/scanner/Scanner.js +26 -22
- package/build/module/lib/scanner/ScannerTypes.d.ts +32 -0
- package/build/module/lib/scanner/ScannerTypes.js +32 -0
- package/build/module/lib/scanner/Winnower/Winnower.d.ts +5 -2
- package/build/module/lib/scanner/Winnower/Winnower.js +24 -18
- package/build/module/lib/scanner/Winnower/WinnowerResponse.d.ts +3 -0
- package/build/module/lib/scanner/Winnower/WinnowerResponse.js +8 -2
- package/build/module/lib/tree/Tree.js +4 -4
- package/build/tsconfig.module.tsbuildinfo +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package-lock.json +18277 -0
- package/package.json +2 -1
- package/src/bin/cli-bin.ts +12 -5
- package/src/commands/dep.ts +23 -0
- package/src/commands/scan.ts +15 -47
- package/src/index.ts +3 -2
- package/src/lib/dependencies/Dependency.ts +58 -0
- package/src/lib/dependencies/DependencyTypes.ts +22 -0
- package/src/lib/dependencies/PurlGenerator.ts +41 -0
- package/src/lib/dependencies/parsers/golangParser.ts +4 -0
- package/src/lib/dependencies/parsers/mavenParser.ts +48 -0
- package/src/lib/dependencies/parsers/npmParser.ts +44 -0
- package/src/lib/dependencies/parsers/pyParser.ts +46 -0
- package/src/lib/dependencies/parsers/rubyParser.ts +181 -0
- package/src/lib/dependencies/parsers/types.ts +50 -0
- package/src/lib/dependencies/parsers/utils.ts +16 -0
- package/src/lib/scanner/Dispatcher/DispatchableItem.ts +1 -1
- package/src/lib/scanner/Dispatcher/Dispatcher.ts +10 -6
- package/src/lib/scanner/Scannable/ScannableItem.ts +10 -7
- package/src/lib/scanner/Scanner.ts +31 -28
- package/src/lib/scanner/{ScannerEvents.ts → ScannerTypes.ts} +12 -0
- package/src/lib/scanner/Winnower/Winnower.ts +25 -17
- package/src/lib/scanner/Winnower/WinnowerResponse.ts +9 -1
- package/src/lib/tree/Tree.ts +3 -3
- package/yarn.lock +5214 -5127
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface Purl {
|
|
2
|
+
purl: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface FileDependency {
|
|
6
|
+
file: string;
|
|
7
|
+
purls: Array<Purl>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FileListDependency {
|
|
11
|
+
files: Array<FileDependency>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type ParserFuncType = (fileContent: string, filePath: string) => FileDependency;
|
|
15
|
+
|
|
16
|
+
export interface ParserDefinitions {
|
|
17
|
+
[key: string]: ParserFuncType;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
EXAMPLE
|
|
23
|
+
{
|
|
24
|
+
"files": [
|
|
25
|
+
{
|
|
26
|
+
"file": "./test/data/requirements.txt",
|
|
27
|
+
"purls": [
|
|
28
|
+
{
|
|
29
|
+
"purl": "pkg:pypi/requests"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"purl": "pkg:pypi/crc32c@2.2"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"purl": "pkg:pypi/binaryornot"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"purl": "pkg:pypi/progress"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"purl": "pkg:pypi/grpcio"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"purl": "pkg:pypi/protobuf"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { URL } from "url";
|
|
3
|
+
|
|
4
|
+
export function isValidUrl(string: string): boolean {
|
|
5
|
+
let url: URL;
|
|
6
|
+
try {
|
|
7
|
+
new URL(string);
|
|
8
|
+
} catch (_) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isValidPath(string: string): boolean {
|
|
15
|
+
return /^((?:\.\.?)|(?:[a-zA-Z]:\\)|(?:\/))/gm.test(string);
|
|
16
|
+
}
|
|
@@ -5,10 +5,11 @@ import fetch from 'node-fetch';
|
|
|
5
5
|
import PQueue from "p-queue";
|
|
6
6
|
import FormData from "form-data";
|
|
7
7
|
|
|
8
|
-
import { ScannerEvents } from "../
|
|
8
|
+
import { ScannerEvents } from "../ScannerTypes";
|
|
9
9
|
import { DispatcherResponse } from "./DispatcherResponse";
|
|
10
10
|
import { ScannerCfg } from "../ScannerCfg";
|
|
11
11
|
import { GlobalControllerAborter } from "./GlobalControllerAborter";
|
|
12
|
+
import { DispatchableItem } from './DispatchableItem';
|
|
12
13
|
|
|
13
14
|
export class Dispatcher extends EventEmitter {
|
|
14
15
|
private scannerCfg: ScannerCfg;
|
|
@@ -63,7 +64,7 @@ export class Dispatcher extends EventEmitter {
|
|
|
63
64
|
this.globalAbortController.abortAll();
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
dispatchItem(disptItem) {
|
|
67
|
+
public dispatchItem(disptItem: DispatchableItem): void {
|
|
67
68
|
this.pQueue.add(() => this.dispatch(disptItem));
|
|
68
69
|
|
|
69
70
|
if (
|
|
@@ -104,13 +105,17 @@ export class Dispatcher extends EventEmitter {
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
async dispatch(disptItem) {
|
|
108
|
+
async dispatch(disptItem: DispatchableItem) {
|
|
108
109
|
const timeoutController = this.globalAbortController.getAbortController();
|
|
109
110
|
const timeoutId = setTimeout(() => timeoutController.abort(), this.scannerCfg.TIMEOUT);
|
|
110
111
|
try {
|
|
111
112
|
const form = new FormData();
|
|
112
|
-
|
|
113
|
-
form.append('filename', Buffer.from(
|
|
113
|
+
|
|
114
|
+
form.append('filename', Buffer.from(disptItem.getContent()), 'data.wfp');
|
|
115
|
+
|
|
116
|
+
const engineFlag = disptItem.getWinnowerResponse().getEngineFlags();
|
|
117
|
+
if(engineFlag) form.append('flags', engineFlag);
|
|
118
|
+
|
|
114
119
|
this.emit(ScannerEvents.DISPATCHER_WFP_SENDED);
|
|
115
120
|
const response = await fetch(this.scannerCfg.API_URL, {
|
|
116
121
|
method: 'post',
|
|
@@ -141,7 +146,6 @@ export class Dispatcher extends EventEmitter {
|
|
|
141
146
|
this.globalAbortController.removeAbortController(timeoutController);
|
|
142
147
|
this.errorHandler(e, disptItem);
|
|
143
148
|
return Promise.resolve();
|
|
144
|
-
|
|
145
149
|
}
|
|
146
150
|
}
|
|
147
151
|
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
import { WinnowingMode } from "../ScannerTypes";
|
|
2
|
+
|
|
3
|
+
|
|
1
4
|
export class ScannableItem {
|
|
2
5
|
private contentSource: string;
|
|
3
6
|
|
|
4
7
|
private content: Buffer;
|
|
5
8
|
|
|
6
|
-
private
|
|
9
|
+
private winnowingMode: WinnowingMode;
|
|
7
10
|
|
|
8
11
|
private fingerprint: any;
|
|
9
12
|
|
|
10
13
|
private maxSizeWfp: any;
|
|
11
14
|
|
|
12
|
-
constructor(content: Buffer, contentSource: string,
|
|
15
|
+
constructor(content: Buffer, contentSource: string, winnowingMode: any, maxSizeWfp: number) {
|
|
13
16
|
this.contentSource = contentSource;
|
|
14
17
|
this.content = content;
|
|
15
|
-
this.
|
|
18
|
+
this.winnowingMode = winnowingMode;
|
|
16
19
|
this.maxSizeWfp = maxSizeWfp;
|
|
17
20
|
}
|
|
18
21
|
|
|
@@ -24,14 +27,14 @@ export class ScannableItem {
|
|
|
24
27
|
return this.contentSource;
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
public getScanMode() {
|
|
28
|
-
return this.scanMode;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
30
|
public getFingerprint() {
|
|
32
31
|
return this.fingerprint;
|
|
33
32
|
}
|
|
34
33
|
|
|
34
|
+
public getWinnowingMode(): WinnowingMode {
|
|
35
|
+
return this.winnowingMode;
|
|
36
|
+
}
|
|
37
|
+
|
|
35
38
|
public getMaxSizeWfp() {
|
|
36
39
|
return this.maxSizeWfp;
|
|
37
40
|
}
|
|
@@ -10,17 +10,13 @@ import { Dispatcher } from './Dispatcher/Dispatcher';
|
|
|
10
10
|
import { DispatchableItem } from './Dispatcher/DispatchableItem';
|
|
11
11
|
import { DispatcherResponse } from './Dispatcher/DispatcherResponse';
|
|
12
12
|
import { ScannerCfg } from './ScannerCfg';
|
|
13
|
-
import { ScannerEvents } from './
|
|
13
|
+
import { ScannerEvents, ScannerInput } from './ScannerTypes';
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
import sortPaths from 'sort-paths';
|
|
17
17
|
import { WinnowerResponse } from './Winnower/WinnowerResponse';
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
// TO DO:
|
|
21
|
-
// - Split ScannerEvents into ExternalEvents and InternalEvents
|
|
22
|
-
// - Implement a static atribute to keep track of the scannerId
|
|
23
|
-
|
|
24
20
|
let finishPromiseResolve;
|
|
25
21
|
let finishPromiseReject;
|
|
26
22
|
|
|
@@ -33,9 +29,9 @@ export class Scanner extends EventEmitter {
|
|
|
33
29
|
|
|
34
30
|
scannerId;
|
|
35
31
|
|
|
36
|
-
winnower: Winnower;
|
|
32
|
+
private winnower: Winnower;
|
|
37
33
|
|
|
38
|
-
dispatcher;
|
|
34
|
+
private dispatcher: Dispatcher;
|
|
39
35
|
|
|
40
36
|
resultFilePath;
|
|
41
37
|
|
|
@@ -57,6 +53,8 @@ export class Scanner extends EventEmitter {
|
|
|
57
53
|
|
|
58
54
|
finishPromise: Promise<void>;
|
|
59
55
|
|
|
56
|
+
private scannerInput: Array<ScannerInput>;
|
|
57
|
+
|
|
60
58
|
constructor(scannerCfg = new ScannerCfg()) {
|
|
61
59
|
super();
|
|
62
60
|
this.scannerCfg = scannerCfg;
|
|
@@ -89,6 +87,7 @@ export class Scanner extends EventEmitter {
|
|
|
89
87
|
this.winnower.on(ScannerEvents.WINNOWING_NEW_CONTENT, (winnowerResponse: WinnowerResponse) => {
|
|
90
88
|
this.emit(ScannerEvents.WINNOWING_NEW_CONTENT, winnowerResponse);
|
|
91
89
|
this.reportLog(`[ SCANNER ]: New WFP content`);
|
|
90
|
+
winnowerResponse.setEngineFlags(this.scannerInput[0].engineFlags);
|
|
92
91
|
const disptItem = new DispatchableItem(winnowerResponse);
|
|
93
92
|
this.dispatcher.dispatchItem(disptItem);
|
|
94
93
|
});
|
|
@@ -121,13 +120,13 @@ export class Scanner extends EventEmitter {
|
|
|
121
120
|
this.insertIntoBuffer(response);
|
|
122
121
|
if (this.bufferReachedLimit()) this.bufferToFiles();
|
|
123
122
|
this.processingNewData = false;
|
|
124
|
-
if (this.scanFinished) await this.
|
|
123
|
+
if (this.scanFinished) await this.finishJob();
|
|
125
124
|
});
|
|
126
125
|
|
|
127
126
|
this.dispatcher.on(ScannerEvents.DISPATCHER_FINISHED, async () => {
|
|
128
127
|
if (!this.winnower.hasPendingFiles()) {
|
|
129
128
|
if (this.processingNewData) this.scanFinished = true;
|
|
130
|
-
else await this.
|
|
129
|
+
else await this.finishJob();
|
|
131
130
|
}
|
|
132
131
|
});
|
|
133
132
|
|
|
@@ -197,12 +196,20 @@ export class Scanner extends EventEmitter {
|
|
|
197
196
|
return this.workDirectory;
|
|
198
197
|
}
|
|
199
198
|
|
|
200
|
-
cleanWorkDirectory() {
|
|
199
|
+
public cleanWorkDirectory(): void {
|
|
201
200
|
if (fs.existsSync(this.resultFilePath)) fs.unlinkSync(this.resultFilePath);
|
|
202
201
|
if (fs.existsSync(this.wfpFilePath)) fs.unlinkSync(this.wfpFilePath);
|
|
203
202
|
}
|
|
204
203
|
|
|
205
|
-
async
|
|
204
|
+
private async finishJob() {
|
|
205
|
+
this.scannerInput.shift();
|
|
206
|
+
this.reportLog(`[ SCANNER ]: Job finished. ${this.scannerInput.length} pendings`);
|
|
207
|
+
|
|
208
|
+
if(this.scannerInput.length) this.winnower.startWinnowing(this.scannerInput[0]);
|
|
209
|
+
else await this.finishScan();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private async finishScan() {
|
|
206
213
|
if (!this.isBufferEmpty()) this.bufferToFiles();
|
|
207
214
|
const results = JSON.parse(await fs.promises.readFile(this.resultFilePath, 'utf8'));
|
|
208
215
|
const sortedPaths = sortPaths(Object.keys(results), '/');
|
|
@@ -253,30 +260,26 @@ export class Scanner extends EventEmitter {
|
|
|
253
260
|
}
|
|
254
261
|
|
|
255
262
|
|
|
256
|
-
public
|
|
263
|
+
public scanFromWinnowingFile(wfpFilePath: string): Promise<void> {
|
|
257
264
|
this.init();
|
|
258
|
-
this.filesToScan = files;
|
|
259
|
-
this.scanRoot = scanRoot;
|
|
260
265
|
this.createOutputFiles();
|
|
261
|
-
|
|
262
|
-
this.finishScan();
|
|
263
|
-
return this.finishPromise;
|
|
264
|
-
}
|
|
265
|
-
this.winnower.startWinnowing(this.filesToScan, scanRoot);
|
|
266
|
+
this.winnower.startWinnowingFromFile(wfpFilePath);
|
|
266
267
|
return this.finishPromise;
|
|
267
268
|
}
|
|
268
269
|
|
|
269
270
|
|
|
270
|
-
public
|
|
271
|
+
public scan(scannerInput: Array<ScannerInput>): Promise<void> {
|
|
271
272
|
this.init();
|
|
272
273
|
this.createOutputFiles();
|
|
273
|
-
this.
|
|
274
|
-
return
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
this.scannerInput = scannerInput;
|
|
275
|
+
// If some jobs have no files to scan, we return
|
|
276
|
+
if (this.scannerInput.some((input) => !input.fileList.length)){
|
|
277
|
+
this.finishScan();
|
|
278
|
+
return this.finishPromise;
|
|
279
|
+
}
|
|
277
280
|
|
|
278
|
-
|
|
279
|
-
return
|
|
281
|
+
this.winnower.startWinnowing(this.scannerInput[0]);
|
|
282
|
+
return this.finishPromise;
|
|
280
283
|
}
|
|
281
284
|
|
|
282
285
|
|
|
@@ -289,13 +292,13 @@ export class Scanner extends EventEmitter {
|
|
|
289
292
|
pause() {
|
|
290
293
|
this.running = false;
|
|
291
294
|
this.winnower.pause();
|
|
292
|
-
this.dispatcher.pause();
|
|
295
|
+
// this.dispatcher.pause();
|
|
293
296
|
}
|
|
294
297
|
|
|
295
298
|
resume() {
|
|
296
299
|
this.running = true;
|
|
297
300
|
this.winnower.resume();
|
|
298
|
-
this.dispatcher.resume();
|
|
301
|
+
// this.dispatcher.resume();
|
|
299
302
|
}
|
|
300
303
|
|
|
301
304
|
stop() {
|
|
@@ -27,3 +27,15 @@ export enum ScannerEvents {
|
|
|
27
27
|
|
|
28
28
|
ERROR = 'error',
|
|
29
29
|
};
|
|
30
|
+
|
|
31
|
+
export enum WinnowingMode {
|
|
32
|
+
FULL_WINNOWING = 'FULL_WINNOWING',
|
|
33
|
+
WINNOWING_ONLY_MD5 = 'WINNOWING_ONLY_MD5',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export interface ScannerInput {
|
|
37
|
+
engineFlags?: number;
|
|
38
|
+
folderRoot?: string;
|
|
39
|
+
fileList: Array<string>;
|
|
40
|
+
winnowingMode?: WinnowingMode; // Enable winnowing algorithm, otherwise is scanned only MD5
|
|
41
|
+
};
|
|
@@ -4,7 +4,7 @@ import { Worker } from 'worker_threads';
|
|
|
4
4
|
|
|
5
5
|
import { ScannableItem } from '../Scannable/ScannableItem';
|
|
6
6
|
import { ScannerCfg } from '../ScannerCfg';
|
|
7
|
-
import { ScannerEvents } from '../
|
|
7
|
+
import { ScannerEvents, ScannerInput, WinnowingMode } from '../ScannerTypes';
|
|
8
8
|
import { WinnowerExtractor } from './WinnowerExtractor';
|
|
9
9
|
|
|
10
10
|
import { WinnowerResponse } from './WinnowerResponse';
|
|
@@ -17,7 +17,7 @@ const { parentPort } = require('worker_threads');
|
|
|
17
17
|
parentPort.on('message', async (scannableItem) => {
|
|
18
18
|
|
|
19
19
|
let fingerprint;
|
|
20
|
-
if ( scannableItem.
|
|
20
|
+
if ( scannableItem.winnowingMode === "FULL_WINNOWING") {
|
|
21
21
|
fingerprint = wfp_for_content(
|
|
22
22
|
scannableItem.content,
|
|
23
23
|
scannableItem.contentSource,
|
|
@@ -240,7 +240,7 @@ export class Winnower extends EventEmitter {
|
|
|
240
240
|
|
|
241
241
|
private fileListIndex: number;
|
|
242
242
|
|
|
243
|
-
private
|
|
243
|
+
private folderRoot: string;
|
|
244
244
|
|
|
245
245
|
private wfp: string;
|
|
246
246
|
|
|
@@ -250,6 +250,8 @@ export class Winnower extends EventEmitter {
|
|
|
250
250
|
|
|
251
251
|
private isRunning: boolean;
|
|
252
252
|
|
|
253
|
+
private winnowingMode: WinnowingMode;
|
|
254
|
+
|
|
253
255
|
private readingFromFile: boolean;
|
|
254
256
|
|
|
255
257
|
private winnowingExtractor: WinnowerExtractor;
|
|
@@ -257,18 +259,17 @@ export class Winnower extends EventEmitter {
|
|
|
257
259
|
constructor(scannerCfg = new ScannerCfg()) {
|
|
258
260
|
super();
|
|
259
261
|
this.scannerCfg = scannerCfg;
|
|
260
|
-
this.init();
|
|
261
|
-
this.prepareWorker();
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
init() {
|
|
265
265
|
this.wfp = '';
|
|
266
|
-
this.
|
|
266
|
+
this.folderRoot = '';
|
|
267
267
|
this.continue = true;
|
|
268
268
|
this.isRunning = false;
|
|
269
269
|
this.readingFromFile = false;
|
|
270
270
|
this.fileList = [];
|
|
271
271
|
this.fileListIndex = 0;
|
|
272
|
+
this.winnowingMode = WinnowingMode.FULL_WINNOWING;
|
|
272
273
|
}
|
|
273
274
|
|
|
274
275
|
prepareWorker() {
|
|
@@ -281,11 +282,11 @@ export class Winnower extends EventEmitter {
|
|
|
281
282
|
|
|
282
283
|
recoveryIndex() {
|
|
283
284
|
// Files: contains all files winnowed but not packed yet
|
|
284
|
-
const files = new WinnowerResponse(this.wfp, this.
|
|
285
|
+
const files = new WinnowerResponse(this.wfp, this.folderRoot).getFilesWinnowed();
|
|
285
286
|
if (files.length) {
|
|
286
287
|
const lastFileWinnowed = files[files.length - 1];
|
|
287
288
|
let i = 0;
|
|
288
|
-
while (i <= files.length && lastFileWinnowed !== this.fileList[this.fileListIndex - i]
|
|
289
|
+
while (i <= files.length && lastFileWinnowed !== this.fileList[this.fileListIndex - i]) {
|
|
289
290
|
i += 1;
|
|
290
291
|
}
|
|
291
292
|
// If file already winnowed cannot be found in fileList emit an error.
|
|
@@ -294,7 +295,7 @@ export class Winnower extends EventEmitter {
|
|
|
294
295
|
return -1;
|
|
295
296
|
}
|
|
296
297
|
this.fileListIndex -= i;
|
|
297
|
-
if (this.fileList[this.fileListIndex]
|
|
298
|
+
if (this.fileList[this.fileListIndex] === lastFileWinnowed) this.fileListIndex += 1;
|
|
298
299
|
}
|
|
299
300
|
return 0;
|
|
300
301
|
}
|
|
@@ -332,18 +333,17 @@ export class Winnower extends EventEmitter {
|
|
|
332
333
|
}
|
|
333
334
|
|
|
334
335
|
processPackedWfp(content) {
|
|
335
|
-
const wnRsp = new WinnowerResponse(content, this.
|
|
336
|
+
const wnRsp = new WinnowerResponse(content, this.folderRoot);
|
|
336
337
|
this.emit(ScannerEvents.WINNOWING_NEW_CONTENT, wnRsp);
|
|
337
338
|
}
|
|
338
339
|
|
|
339
340
|
async getNextScannableItem() {
|
|
340
341
|
if (this.fileListIndex >= this.fileList.length) return null;
|
|
341
|
-
const path = this.fileList[this.fileListIndex]
|
|
342
|
-
const
|
|
343
|
-
const contentSource = path.replace(`${this.scanRoot}`, '');
|
|
342
|
+
const path = this.fileList[this.fileListIndex];
|
|
343
|
+
const contentSource = path.replace(`${this.folderRoot}`, '');
|
|
344
344
|
const content = await fs.promises.readFile(path);
|
|
345
345
|
this.fileListIndex += 1;
|
|
346
|
-
const scannable = new ScannableItem(content, contentSource,
|
|
346
|
+
const scannable = new ScannableItem(content, contentSource, this.winnowingMode, this.scannerCfg.WFP_FILE_MAX_SIZE);
|
|
347
347
|
return scannable;
|
|
348
348
|
}
|
|
349
349
|
|
|
@@ -377,12 +377,17 @@ export class Winnower extends EventEmitter {
|
|
|
377
377
|
if(winBlock === '') this.finishWinnowing();
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
-
public async startWinnowing(
|
|
380
|
+
public async startWinnowing(scanInput: ScannerInput): Promise<void> {
|
|
381
381
|
this.emit(ScannerEvents.WINNOWER_LOG, '[ SCANNER ]: Starting Winnowing...');
|
|
382
|
+
|
|
383
|
+
this.init();
|
|
384
|
+
this.prepareWorker();
|
|
385
|
+
|
|
386
|
+
if(scanInput.winnowingMode) this.setWinnowingMode(scanInput.winnowingMode);
|
|
382
387
|
this.readingFromFile = false;
|
|
383
|
-
this.scanRoot = scanRoot;
|
|
384
388
|
this.isRunning = true;
|
|
385
|
-
this.
|
|
389
|
+
this.folderRoot = scanInput.folderRoot;
|
|
390
|
+
this.fileList = scanInput.fileList;
|
|
386
391
|
this.nextStepMachine();
|
|
387
392
|
}
|
|
388
393
|
|
|
@@ -428,4 +433,7 @@ export class Winnower extends EventEmitter {
|
|
|
428
433
|
return this.isRunning;
|
|
429
434
|
}
|
|
430
435
|
|
|
436
|
+
public setWinnowingMode(mode: WinnowingMode): void {
|
|
437
|
+
this.winnowingMode = mode;
|
|
438
|
+
}
|
|
431
439
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export class WinnowerResponse {
|
|
2
2
|
private wfpContent: string;
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
private engineFlags: number;
|
|
5
5
|
|
|
6
6
|
private scanRoot: string;
|
|
7
7
|
|
|
@@ -18,6 +18,14 @@ export class WinnowerResponse {
|
|
|
18
18
|
return this.wfpContent;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
public setEngineFlags(engineFlags: number): void {
|
|
22
|
+
this.engineFlags = engineFlags;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public getEngineFlags(): number {
|
|
26
|
+
return this.engineFlags;
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
public getFilesWinnowed() {
|
|
22
30
|
const files = [];
|
|
23
31
|
const regExp = new RegExp(/,(\/.*)/g);
|
package/src/lib/tree/Tree.ts
CHANGED
|
@@ -21,7 +21,7 @@ export class Tree {
|
|
|
21
21
|
|
|
22
22
|
constructor(path: string) {
|
|
23
23
|
const pathParts = path.split(pathLib.sep);
|
|
24
|
-
this.rootName =
|
|
24
|
+
this.rootName = pathLib.basename(path);
|
|
25
25
|
this.rootPath = path;
|
|
26
26
|
this.rootFolder = new Folder('/', this.rootName);
|
|
27
27
|
}
|
|
@@ -44,7 +44,7 @@ export class Tree {
|
|
|
44
44
|
for (const dirEntry of dirEntries) {
|
|
45
45
|
const fullPath = `${path}/${dirEntry.name}`;
|
|
46
46
|
const relativePath = `${path}/${dirEntry.name}`.replace(this.rootPath, '');
|
|
47
|
-
if (this.filter
|
|
47
|
+
if (!this.filter || this.filter.include(fullPath))
|
|
48
48
|
if (dirEntry.isDirectory()) {
|
|
49
49
|
const f: Folder = new Folder(relativePath, dirEntry.name);
|
|
50
50
|
const subTree = this.buildTreeRec(`${path}/${dirEntry.name}`, f);
|
|
@@ -82,7 +82,7 @@ export class Tree {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
public getFileList(): Array<string> {
|
|
85
|
-
const rootPath = this.rootPath.substring(0, this.rootPath.length
|
|
85
|
+
const rootPath = this.rootPath.substring(0, this.rootPath.length);
|
|
86
86
|
const fList = this.rootFolder.getFiles();
|
|
87
87
|
return fList.map((fileRelativePath: string) => {return (rootPath + fileRelativePath)});
|
|
88
88
|
}
|