scanoss 0.2.10 → 0.2.11

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.
Files changed (150) hide show
  1. package/LICENSE +20 -18
  2. package/build/main/bin/cli-bin.js +7 -1
  3. package/build/main/commands/dep.d.ts +1 -0
  4. package/build/main/commands/dep.js +26 -0
  5. package/build/main/index.d.ts +2 -0
  6. package/build/main/index.js +3 -1
  7. package/build/main/lib/dependencies/Dependency.d.ts +9 -0
  8. package/build/main/lib/dependencies/Dependency.js +50 -0
  9. package/build/main/lib/dependencies/DependencyTypes.d.ts +19 -0
  10. package/build/main/lib/dependencies/DependencyTypes.js +3 -0
  11. package/build/main/lib/dependencies/PurlGenerator.d.ts +2 -0
  12. package/build/main/lib/dependencies/PurlGenerator.js +39 -0
  13. package/build/main/lib/dependencies/parsers/golangParser.d.ts +0 -0
  14. package/build/main/lib/dependencies/parsers/golangParser.js +3 -0
  15. package/build/main/lib/dependencies/parsers/mavenParser.d.ts +2 -0
  16. package/build/main/lib/dependencies/parsers/mavenParser.js +44 -0
  17. package/build/main/lib/dependencies/parsers/npmParser.d.ts +3 -0
  18. package/build/main/lib/dependencies/parsers/npmParser.js +45 -0
  19. package/build/main/lib/dependencies/parsers/pyParser.d.ts +2 -0
  20. package/build/main/lib/dependencies/parsers/pyParser.js +51 -0
  21. package/build/main/lib/dependencies/parsers/rubyParser.d.ts +3 -0
  22. package/build/main/lib/dependencies/parsers/rubyParser.js +135 -0
  23. package/build/main/lib/dependencies/parsers/types.d.ts +15 -0
  24. package/build/main/lib/dependencies/parsers/types.js +33 -0
  25. package/build/main/lib/dependencies/parsers/utils.d.ts +2 -0
  26. package/build/main/lib/dependencies/parsers/utils.js +20 -0
  27. package/build/main/lib/dependencies/src/PurlGenerator.d.ts +2 -0
  28. package/build/main/lib/dependencies/src/PurlGenerator.js +62 -0
  29. package/build/main/lib/dependencies/src/parsers/golangParser.d.ts +0 -0
  30. package/build/main/lib/dependencies/src/parsers/golangParser.js +3 -0
  31. package/build/main/lib/dependencies/src/parsers/mavenParser.d.ts +2 -0
  32. package/build/main/lib/dependencies/src/parsers/mavenParser.js +44 -0
  33. package/build/main/lib/dependencies/src/parsers/npmParser.d.ts +3 -0
  34. package/build/main/lib/dependencies/src/parsers/npmParser.js +45 -0
  35. package/build/main/lib/dependencies/src/parsers/pyParser.d.ts +2 -0
  36. package/build/main/lib/dependencies/src/parsers/pyParser.js +51 -0
  37. package/build/main/lib/dependencies/src/parsers/rubyParser.d.ts +3 -0
  38. package/build/main/lib/dependencies/src/parsers/rubyParser.js +135 -0
  39. package/build/main/lib/dependencies/src/parsers/types.d.ts +15 -0
  40. package/build/main/lib/dependencies/src/parsers/types.js +33 -0
  41. package/build/main/lib/dependencies/src/parsers/utils.d.ts +2 -0
  42. package/build/main/lib/dependencies/src/parsers/utils.js +19 -0
  43. package/build/main/lib/dependencyScan/dependencyScan.d.ts +2 -0
  44. package/build/main/lib/dependencyScan/dependencyScan.js +37 -0
  45. package/build/main/lib/dependencyScan/parser.d.ts +7 -0
  46. package/build/main/lib/dependencyScan/parser.js +41 -0
  47. package/build/main/lib/dependencyScan/utils.d.ts +1 -0
  48. package/build/main/lib/dependencyScan/utils.js +16 -0
  49. package/build/main/lib/scanner/Dependency/dependency.d.ts +9 -0
  50. package/build/main/lib/scanner/Dependency/dependency.js +46 -0
  51. package/build/main/lib/scanner/Dependency/dependencyScan.d.ts +9 -0
  52. package/build/main/lib/scanner/Dependency/dependencyScan.js +48 -0
  53. package/build/main/lib/scanner/Dependency/parser.d.ts +7 -0
  54. package/build/main/lib/scanner/Dependency/parser.js +41 -0
  55. package/build/main/lib/scanner/Dependency/utils.d.ts +1 -0
  56. package/build/main/lib/scanner/Dependency/utils.js +16 -0
  57. package/build/main/lib/tree/Tree.js +2 -2
  58. package/build/module/bin/cli-bin.js +7 -1
  59. package/build/module/commands/dep.d.ts +1 -0
  60. package/build/module/commands/dep.js +19 -0
  61. package/build/module/index.d.ts +2 -0
  62. package/build/module/index.js +3 -1
  63. package/build/module/lib/dependencies/Dependency.d.ts +9 -0
  64. package/build/module/lib/dependencies/Dependency.js +45 -0
  65. package/build/module/lib/dependencies/DependencyTypes.d.ts +19 -0
  66. package/build/module/lib/dependencies/DependencyTypes.js +2 -0
  67. package/build/module/lib/dependencies/PurlGenerator.d.ts +2 -0
  68. package/build/module/lib/dependencies/PurlGenerator.js +32 -0
  69. package/build/module/lib/dependencies/parsers/golangParser.d.ts +0 -0
  70. package/build/module/lib/dependencies/parsers/golangParser.js +3 -0
  71. package/build/module/lib/dependencies/parsers/mavenParser.d.ts +2 -0
  72. package/build/module/lib/dependencies/parsers/mavenParser.js +37 -0
  73. package/build/module/lib/dependencies/parsers/npmParser.d.ts +3 -0
  74. package/build/module/lib/dependencies/parsers/npmParser.js +37 -0
  75. package/build/module/lib/dependencies/parsers/pyParser.d.ts +2 -0
  76. package/build/module/lib/dependencies/parsers/pyParser.js +44 -0
  77. package/build/module/lib/dependencies/parsers/rubyParser.d.ts +3 -0
  78. package/build/module/lib/dependencies/parsers/rubyParser.js +132 -0
  79. package/build/module/lib/dependencies/parsers/types.d.ts +15 -0
  80. package/build/module/lib/dependencies/parsers/types.js +32 -0
  81. package/build/module/lib/dependencies/parsers/utils.d.ts +2 -0
  82. package/build/module/lib/dependencies/parsers/utils.js +15 -0
  83. package/build/module/lib/dependencies/src/PurlGenerator.d.ts +2 -0
  84. package/build/module/lib/dependencies/src/PurlGenerator.js +55 -0
  85. package/build/module/lib/dependencies/src/parsers/golangParser.d.ts +0 -0
  86. package/build/module/lib/dependencies/src/parsers/golangParser.js +3 -0
  87. package/build/module/lib/dependencies/src/parsers/mavenParser.d.ts +2 -0
  88. package/build/module/lib/dependencies/src/parsers/mavenParser.js +37 -0
  89. package/build/module/lib/dependencies/src/parsers/npmParser.d.ts +3 -0
  90. package/build/module/lib/dependencies/src/parsers/npmParser.js +37 -0
  91. package/build/module/lib/dependencies/src/parsers/pyParser.d.ts +2 -0
  92. package/build/module/lib/dependencies/src/parsers/pyParser.js +44 -0
  93. package/build/module/lib/dependencies/src/parsers/rubyParser.d.ts +3 -0
  94. package/build/module/lib/dependencies/src/parsers/rubyParser.js +132 -0
  95. package/build/module/lib/dependencies/src/parsers/types.d.ts +15 -0
  96. package/build/module/lib/dependencies/src/parsers/types.js +32 -0
  97. package/build/module/lib/dependencies/src/parsers/utils.d.ts +2 -0
  98. package/build/module/lib/dependencies/src/parsers/utils.js +14 -0
  99. package/build/module/lib/dependencyScan/dependencyScan.d.ts +2 -0
  100. package/build/module/lib/dependencyScan/dependencyScan.js +29 -0
  101. package/build/module/lib/dependencyScan/parser.d.ts +7 -0
  102. package/build/module/lib/dependencyScan/parser.js +38 -0
  103. package/build/module/lib/dependencyScan/utils.d.ts +1 -0
  104. package/build/module/lib/dependencyScan/utils.js +12 -0
  105. package/build/module/lib/scanner/Dependency/dependency.d.ts +9 -0
  106. package/build/module/lib/scanner/Dependency/dependency.js +38 -0
  107. package/build/module/lib/scanner/Dependency/dependencyScan.d.ts +9 -0
  108. package/build/module/lib/scanner/Dependency/dependencyScan.js +40 -0
  109. package/build/module/lib/scanner/Dependency/parser.d.ts +7 -0
  110. package/build/module/lib/scanner/Dependency/parser.js +38 -0
  111. package/build/module/lib/scanner/Dependency/utils.d.ts +1 -0
  112. package/build/module/lib/scanner/Dependency/utils.js +12 -0
  113. package/build/module/lib/tree/Tree.js +2 -2
  114. package/package.json +2 -1
  115. package/.circleci/config.yml +0 -64
  116. package/.cspell.json +0 -34
  117. package/.editorconfig +0 -15
  118. package/.eslintrc.json +0 -37
  119. package/.gitignore +0 -11
  120. package/.prettierignore +0 -2
  121. package/.vscode/extensions.json +0 -8
  122. package/.vscode/launch.json +0 -29
  123. package/.vscode/settings.json +0 -7
  124. package/build/tsconfig.module.tsbuildinfo +0 -1
  125. package/build/tsconfig.tsbuildinfo +0 -1
  126. package/examples/defaultFilter.json +0 -203
  127. package/package-lock.json +0 -18266
  128. package/src/bin/cli-bin.ts +0 -52
  129. package/src/commands/scan.ts +0 -97
  130. package/src/index.ts +0 -4
  131. package/src/lib/filters/defaultFilter.ts +0 -207
  132. package/src/lib/filters/filtering.ts +0 -234
  133. package/src/lib/scanner/Dispatcher/DispatchableItem.ts +0 -29
  134. package/src/lib/scanner/Dispatcher/Dispatcher.ts +0 -151
  135. package/src/lib/scanner/Dispatcher/DispatcherResponse.ts +0 -40
  136. package/src/lib/scanner/Dispatcher/GlobalControllerAborter.ts +0 -33
  137. package/src/lib/scanner/Scannable/ScannableItem.ts +0 -43
  138. package/src/lib/scanner/Scanner.ts +0 -319
  139. package/src/lib/scanner/ScannerCfg.ts +0 -29
  140. package/src/lib/scanner/ScannerTypes.ts +0 -41
  141. package/src/lib/scanner/Winnower/Winnower.ts +0 -439
  142. package/src/lib/scanner/Winnower/WinnowerExtractor.ts +0 -38
  143. package/src/lib/scanner/Winnower/WinnowerResponse.ts +0 -38
  144. package/src/lib/tree/File.ts +0 -20
  145. package/src/lib/tree/Folder.ts +0 -50
  146. package/src/lib/tree/Node.ts +0 -34
  147. package/src/lib/tree/Tree.ts +0 -89
  148. package/tsconfig.json +0 -47
  149. package/tsconfig.module.json +0 -11
  150. package/yarn.lock +0 -5670
@@ -1,52 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { program } from 'commander';
4
- import { scanHandler } from '../commands/scan';
5
-
6
- function CLIErrorHandler(e: Error) {
7
- console.error(' ');
8
- console.error(e);
9
- process.exit(1);
10
- }
11
-
12
-
13
-
14
-
15
- async function main() {
16
- program
17
- .version("0.2.9")
18
- .description('The SCANOSS JS package provides a simple, easy to consume module for interacting with SCANOSS APIs/Engine.')
19
-
20
- program
21
- .command('scan <source>')
22
- .description('Scan a folder/file')
23
- //.option('-w, --wfp', 'Scan a .wfp file instead of a folder') // In progress
24
- .option('-c, --concurrency <number>', 'Number of concurrent connections to use while scanning (optional -default 10)')
25
- .option('--filter <path>', 'Loads an user defined filter (optional)')
26
- .option('-o, --output <filename>', 'Output result file name (optional - default stdout)')
27
- .option('-F, --flags <flags>', 'Scanning engine flags (1: disable snippet matching, 2 enable snippet ids, 4: disable dependencies, 8: disable licenses, 16: disable copyrights,32: disable vulnerabilities, 64: disable quality, 128: disable cryptography,256: disable best match, 512: Report identified files)')
28
- .option('-P, --post-size <postsize>', 'Number of kilobytes to limit the post to while scanning (optional - default 64)')
29
- .option('-R, --max-retry <retry>', 'Max number of retries for each POST (optional -default 5)')
30
- .option('-M, --timeout <timeout>', 'Timeout (in seconds) for API communication (optional -default 120)')
31
- .option('-a, --apiurl <apiurl>', 'SCANOSS API URL (optional - default: https://osskb.org/api/scan/direct)')
32
- .option('-k, --key <key>', 'SCANOSS API Key token (optional - not required for default OSSKB URL)')
33
- .option('-v, --verbose', 'Makes scan operation verbose')
34
- .action((source, options) => {scanHandler(source, options).catch((e) => {CLIErrorHandler(e)})})
35
- .addHelpText('after', `
36
- Examples:
37
- $ scanoss-js scan -o scan-output.json <source-folder>`
38
- );
39
-
40
-
41
- await program.parseAsync(process.argv);
42
-
43
-
44
- }
45
-
46
-
47
- try {
48
- main();
49
- } catch (e) {
50
- console.error(e);
51
- process.exit(1);
52
- }
@@ -1,97 +0,0 @@
1
- import { Scanner } from '../lib/scanner/Scanner';
2
- import { ScannerEvents, ScannerInput } from '../lib/scanner/ScannerTypes';
3
- import { ScannerCfg } from '../lib/scanner/ScannerCfg';
4
- import { Tree } from '../lib/tree/Tree';
5
-
6
- import cliProgress from 'cli-progress';
7
- import { DispatcherResponse } from '../lib/scanner/Dispatcher/DispatcherResponse';
8
- import { defaultFilter } from '../lib/filters/defaultFilter';
9
- import { FilterList } from '../lib/filters/filtering';
10
-
11
- import fs from 'fs';
12
-
13
- // Async function that verify if a path is a folder. If the path is not valid the promise will be rejected
14
- const isFolder = (path: string): Promise<boolean> => {
15
- return new Promise((resolve, reject) => {
16
- fs.stat(path, (err, stats) => {
17
- if (err) {
18
- reject(err);
19
- } else {
20
- resolve(stats.isDirectory());
21
- }
22
- });
23
- });
24
- }
25
-
26
- export async function scanHandler(rootPath: string, options: any): Promise<void> {
27
-
28
- let scannerInput: ScannerInput = {fileList: []};
29
-
30
- rootPath = rootPath.replace(/\/$/, ''); // Remove trailing slash if exists
31
- rootPath = rootPath.replace(/^\./, process.env.PWD); // Convert relative path to absolute path.
32
- const pathIsFolder = await isFolder(rootPath);
33
-
34
- // Create scanner and set connections parameters
35
- const scannerCfg = new ScannerCfg();
36
- if(options.concurrency) scannerCfg.CONCURRENCY_LIMIT = parseInt(options.concurrency);
37
- if(options.postSize) scannerCfg.WFP_FILE_MAX_SIZE = parseInt(options.postSize) * 1024;
38
- if(options.apiurl) scannerCfg.API_URL = options.apiurl;
39
- if(options.key) scannerCfg.API_KEY = options.key;
40
- if(options.timeout) scannerCfg.TIMEOUT = options.timeout * 1000;
41
- if(options.maxRetry) scannerCfg.MAX_RETRIES_FOR_RECOVERABLES_ERRORS = options.maxRetry;
42
- const scanner = new Scanner(scannerCfg);
43
-
44
- scannerInput.folderRoot = rootPath + '/'; // This will remove the project root path from the results.
45
- if(options.flags) scannerInput.engineFlags = options.flags;
46
-
47
- if(!options.wfp) {
48
- if(pathIsFolder) {
49
- const tree = new Tree(rootPath);
50
- const filter = new FilterList('');
51
-
52
- if (options.filter) {
53
- console.error('Loading filter from file: ' + options.filter);
54
- filter.loadFromFile(options.filter);
55
- } else {
56
- console.error('Loading default filters...');
57
- filter.load(defaultFilter as FilterList);
58
- }
59
- console.error('Reading directory... ');
60
- tree.loadFilter(filter);
61
- tree.buildTree();
62
- scannerInput.fileList = tree.getFileList();
63
- } else {
64
- scannerInput.fileList = [rootPath];
65
- }
66
- } else {
67
- const winnowing = fs.readFileSync(rootPath, {encoding: 'utf-8'});
68
- //filesCounter = [...winnowing.matchAll(/file=/g)].length;
69
- }
70
-
71
- if (!options.verbose) {
72
- const optBar1 = { format: 'Scan Progress: [{bar}] {percentage}% | Scanned {value} files of {total}' };
73
- const bar1 = new cliProgress.SingleBar(optBar1, cliProgress.Presets.shades_classic);
74
- bar1.start(scannerInput.fileList.length, 0);
75
-
76
- scanner.on(ScannerEvents.DISPATCHER_NEW_DATA, (dispResp: DispatcherResponse) => {
77
- bar1.increment(dispResp.getFilesScanned().length);
78
- });
79
-
80
- scanner.on(ScannerEvents.SCAN_DONE, async (resultPath) => {bar1.stop();});
81
- } else {
82
- scanner.on(ScannerEvents.SCANNER_LOG, (logText) => console.error(logText));
83
- }
84
-
85
- scanner.on(ScannerEvents.SCAN_DONE, async (resultPath) => {
86
- if(options.output)
87
- await fs.promises.copyFile(resultPath, options.output);
88
- else
89
- console.log(await fs.promises.readFile(resultPath, 'utf8'));
90
- });
91
-
92
- if (options.wfp) await scanner.scanFromWinnowingFile(rootPath);
93
- else await scanner.scan([scannerInput]);
94
-
95
- }
96
-
97
-
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './lib/scanner/ScannerTypes';
2
- export * from './lib/scanner/ScannerCfg'
3
- export * from './lib/scanner/Scanner'
4
-
@@ -1,207 +0,0 @@
1
- // ------ FILTERS SYNC WITH PYTHON CLIENT 06/10/2021 ------ //
2
- import { FilterListType } from "./filtering";
3
-
4
-
5
- export const defaultFilter = {
6
- name: 'Default',
7
- type: FilterListType.BANNED,
8
- filters: [
9
- { condition: '=', value: '0', ftype: 'SIZE', scope: 'FILE' },
10
-
11
- //Folders and files filters
12
- { condition: 'starts', value: '.', ftype: 'NAME' },
13
-
14
- //Folder filters
15
- { condition: 'ends', value: '.egg-info', ftype: 'NAME', scope: 'FOLDER' },
16
-
17
- { condition: 'fullmatch', value: 'nbproject', ftype: 'NAME', scope: 'FOLDER' },
18
- { condition: 'fullmatch', value: 'nbbuild', ftype: 'NAME', scope: 'FOLDER' },
19
- { condition: 'fullmatch', value: 'nbdist', ftype: 'NAME', scope: 'FOLDER' },
20
- { condition: 'fullmatch', value: '__pycache__', ftype: 'NAME', scope: 'FOLDER' },
21
- { condition: 'fullmatch', value: 'venv', ftype: 'NAME', scope: 'FOLDER' },
22
- { condition: 'fullmatch', value: '_yardoc', ftype: 'NAME', scope: 'FOLDER' },
23
- { condition: 'fullmatch', value: 'eggs', ftype: 'NAME', scope: 'FOLDER' },
24
- { condition: 'fullmatch', value: 'wheels', ftype: 'NAME', scope: 'FOLDER' },
25
- { condition: 'fullmatch', value: 'htmlcov', ftype: 'NAME', scope: 'FOLDER' },
26
- { condition: 'fullmatch', value: '__pypackages__', ftype: 'NAME', scope: 'FOLDER' },
27
-
28
-
29
- //Files filters
30
-
31
- { condition: 'fullmatch', value: 'gradlew', ftype: 'NAME', scope: 'FILE' },
32
- { condition: 'fullmatch', value: 'gradlew.bat', ftype: 'NAME', scope: 'FILE' },
33
- { condition: 'fullmatch', value: 'mvnw', ftype: 'NAME', scope: 'FILE' },
34
- { condition: 'fullmatch', value: 'mvnw.cmd', ftype: 'NAME', scope: 'FILE' },
35
- { condition: 'fullmatch', value: 'gradle-wrapper.jar', ftype: 'NAME', scope: 'FILE' },
36
- { condition: 'fullmatch', value: 'maven-wrapper.jar', ftype: 'NAME', scope: 'FILE' },
37
- { condition: 'fullmatch', value: 'thumbs.db', ftype: 'NAME', scope: 'FILE' },
38
- { condition: 'fullmatch', value: 'babel.config.js', ftype: 'NAME', scope: 'FILE' },
39
- { condition: 'fullmatch', value: 'license.txt', ftype: 'NAME', scope: 'FILE' },
40
- { condition: 'fullmatch', value: 'license.md', ftype: 'NAME', scope: 'FILE' },
41
- { condition: 'fullmatch', value: 'copying.lib', ftype: 'NAME', scope: 'FILE' },
42
- { condition: 'fullmatch', value: 'makefile', ftype: 'NAME', scope: 'FILE' },
43
-
44
-
45
- { condition: 'starts', value: '.asar', ftype: 'NAME', scope: 'FILE' },
46
-
47
-
48
- { condition: 'ends', value: 'news', ftype: 'NAME', scope: 'FILE' },
49
- { condition: 'ends', value: 'authors', ftype: 'NAME', scope: 'FILE' },
50
-
51
-
52
- { condition: 'ends', value: '-doc', ftype: 'NAME', scope: 'FILE' },
53
- { condition: 'ends', value: 'changelog', ftype: 'NAME', scope: 'FILE' },
54
- { condition: 'ends', value: 'config', ftype: 'NAME', scope: 'FILE' },
55
- { condition: 'ends', value: 'copying', ftype: 'NAME', scope: 'FILE' },
56
- { condition: 'ends', value: 'license', ftype: 'NAME', scope: 'FILE' },
57
- { condition: 'ends', value: 'licenses', ftype: 'NAME', scope: 'FILE' },
58
- { condition: 'ends', value: 'notice', ftype: 'NAME', scope: 'FILE' },
59
- { condition: 'ends', value: 'readme', ftype: 'NAME', scope: 'FILE' },
60
- { condition: 'ends', value: 'swiftdoc', ftype: 'NAME', scope: 'FILE' },
61
- { condition: 'ends', value: 'texidoc', ftype: 'NAME', scope: 'FILE' },
62
- { condition: 'ends', value: 'todo', ftype: 'NAME', scope: 'FILE' },
63
- { condition: 'ends', value: 'version', ftype: 'NAME', scope: 'FILE' },
64
- { condition: 'ends', value: 'ignore', ftype: 'NAME', scope: 'FILE' },
65
- { condition: 'ends', value: 'manifest', ftype: 'NAME', scope: 'FILE' },
66
- { condition: 'ends', value: 'sqlite', ftype: 'NAME', scope: 'FILE' },
67
- { condition: 'ends', value: 'sqlite3', ftype: 'NAME', scope: 'FILE' },
68
-
69
- { condition: '=', value: '.1', ftype: 'EXTENSION', scope: 'FILE' },
70
- { condition: '=', value: '.2', ftype: 'EXTENSION', scope: 'FILE' },
71
- { condition: '=', value: '.3', ftype: 'EXTENSION', scope: 'FILE' },
72
- { condition: '=', value: '.4', ftype: 'EXTENSION', scope: 'FILE' },
73
- { condition: '=', value: '.5', ftype: 'EXTENSION', scope: 'FILE' },
74
- { condition: '=', value: '.6', ftype: 'EXTENSION', scope: 'FILE' },
75
- { condition: '=', value: '.7', ftype: 'EXTENSION', scope: 'FILE' },
76
- { condition: '=', value: '.8', ftype: 'EXTENSION', scope: 'FILE' },
77
- { condition: '=', value: '.9', ftype: 'EXTENSION', scope: 'FILE' },
78
- { condition: '=', value: '.ac', ftype: 'EXTENSION', scope: 'FILE' },
79
- { condition: '=', value: '.adoc', ftype: 'EXTENSION', scope: 'FILE' },
80
- { condition: '=', value: '.am', ftype: 'EXTENSION', scope: 'FILE' },
81
- { condition: '=', value: '.asciidoc', ftype: 'EXTENSION', scope: 'FILE' },
82
- { condition: '=', value: '.bmp', ftype: 'EXTENSION', scope: 'FILE' },
83
- { condition: '=', value: '.build', ftype: 'EXTENSION', scope: 'FILE' },
84
- { condition: '=', value: '.cfg', ftype: 'EXTENSION', scope: 'FILE' },
85
- { condition: '=', value: '.chm', ftype: 'EXTENSION', scope: 'FILE' },
86
- { condition: '=', value: '.class', ftype: 'EXTENSION', scope: 'FILE' },
87
- { condition: '=', value: '.cmake', ftype: 'EXTENSION', scope: 'FILE' },
88
- { condition: '=', value: '.cnf', ftype: 'EXTENSION', scope: 'FILE' },
89
- { condition: '=', value: '.conf', ftype: 'EXTENSION', scope: 'FILE' },
90
- { condition: '=', value: '.config', ftype: 'EXTENSION', scope: 'FILE' },
91
- { condition: '=', value: '.contributors', ftype: 'EXTENSION', scope: 'FILE' },
92
- { condition: '=', value: '.copying', ftype: 'EXTENSION', scope: 'FILE' },
93
- { condition: '=', value: '.crt', ftype: 'EXTENSION', scope: 'FILE' },
94
- { condition: '=', value: '.csproj', ftype: 'EXTENSION', scope: 'FILE' },
95
- { condition: '=', value: '.css', ftype: 'EXTENSION', scope: 'FILE' },
96
- { condition: '=', value: '.csv', ftype: 'EXTENSION', scope: 'FILE' },
97
- { condition: '=', value: '.dat', ftype: 'EXTENSION', scope: 'FILE' },
98
- { condition: '=', value: '.data', ftype: 'EXTENSION', scope: 'FILE' },
99
- { condition: '=', value: '.doc', ftype: 'EXTENSION', scope: 'FILE' },
100
- { condition: '=', value: '.docx', ftype: 'EXTENSION', scope: 'FILE' },
101
- { condition: '=', value: '.dtd', ftype: 'EXTENSION', scope: 'FILE' },
102
- { condition: '=', value: '.dts', ftype: 'EXTENSION', scope: 'FILE' },
103
- { condition: '=', value: '.iws', ftype: 'EXTENSION', scope: 'FILE' },
104
- { condition: '=', value: '.c9', ftype: 'EXTENSION', scope: 'FILE' },
105
- { condition: '=', value: '.c9revisions', ftype: 'EXTENSION', scope: 'FILE' },
106
- { condition: '=', value: '.dtsi', ftype: 'EXTENSION', scope: 'FILE' },
107
- { condition: '=', value: '.dump', ftype: 'EXTENSION', scope: 'FILE' },
108
- { condition: '=', value: '.eot', ftype: 'EXTENSION', scope: 'FILE' },
109
- { condition: '=', value: '.eps', ftype: 'EXTENSION', scope: 'FILE' },
110
- { condition: '=', value: '.geojson', ftype: 'EXTENSION', scope: 'FILE' },
111
- { condition: '=', value: '.gdoc', ftype: 'EXTENSION', scope: 'FILE' },
112
- { condition: '=', value: '.gif', ftype: 'EXTENSION', scope: 'FILE' },
113
- { condition: '=', value: '.glif', ftype: 'EXTENSION', scope: 'FILE' },
114
- { condition: '=', value: '.gmo', ftype: 'EXTENSION', scope: 'FILE' },
115
- { condition: '=', value: '.gradle', ftype: 'EXTENSION', scope: 'FILE' },
116
- { condition: '=', value: '.guess', ftype: 'EXTENSION', scope: 'FILE' },
117
- { condition: '=', value: '.hex', ftype: 'EXTENSION', scope: 'FILE' },
118
- { condition: '=', value: '.htm', ftype: 'EXTENSION', scope: 'FILE' },
119
- { condition: '=', value: '.html', ftype: 'EXTENSION', scope: 'FILE' },
120
- { condition: '=', value: '.ico', ftype: 'EXTENSION', scope: 'FILE' },
121
- { condition: '=', value: '.iml', ftype: 'EXTENSION', scope: 'FILE' },
122
- { condition: '=', value: '.in', ftype: 'EXTENSION', scope: 'FILE' },
123
- { condition: '=', value: '.inc', ftype: 'EXTENSION', scope: 'FILE' },
124
- { condition: '=', value: '.info', ftype: 'EXTENSION', scope: 'FILE' },
125
- { condition: '=', value: '.ini', ftype: 'EXTENSION', scope: 'FILE' },
126
- { condition: '=', value: '.ipynb', ftype: 'EXTENSION', scope: 'FILE' },
127
- { condition: '=', value: '.jpeg', ftype: 'EXTENSION', scope: 'FILE' },
128
- { condition: '=', value: '.jpg', ftype: 'EXTENSION', scope: 'FILE' },
129
- { condition: '=', value: '.json', ftype: 'EXTENSION', scope: 'FILE' },
130
- { condition: '=', value: '.jsonld', ftype: 'EXTENSION', scope: 'FILE' },
131
- { condition: '=', value: '.lock', ftype: 'EXTENSION', scope: 'FILE' },
132
- { condition: '=', value: '.log', ftype: 'EXTENSION', scope: 'FILE' },
133
- { condition: '=', value: '.m4', ftype: 'EXTENSION', scope: 'FILE' },
134
- { condition: '=', value: '.map', ftype: 'EXTENSION', scope: 'FILE' },
135
- { condition: '=', value: '.markdown', ftype: 'EXTENSION', scope: 'FILE' },
136
- { condition: '=', value: '.md', ftype: 'EXTENSION', scope: 'FILE' },
137
- { condition: '=', value: '.md5', ftype: 'EXTENSION', scope: 'FILE' },
138
- { condition: '=', value: '.meta', ftype: 'EXTENSION', scope: 'FILE' },
139
- { condition: '=', value: '.mk', ftype: 'EXTENSION', scope: 'FILE' },
140
- { condition: '=', value: '.mxml', ftype: 'EXTENSION', scope: 'FILE' },
141
- { condition: '=', value: '.o', ftype: 'EXTENSION', scope: 'FILE' },
142
- { condition: '=', value: '.otf', ftype: 'EXTENSION', scope: 'FILE' },
143
- { condition: '=', value: '.out', ftype: 'EXTENSION', scope: 'FILE' },
144
- { condition: '=', value: '.pbtxt', ftype: 'EXTENSION', scope: 'FILE' },
145
- { condition: '=', value: '.pdf', ftype: 'EXTENSION', scope: 'FILE' },
146
- { condition: '=', value: '.pem', ftype: 'EXTENSION', scope: 'FILE' },
147
- { condition: '=', value: '.phtml', ftype: 'EXTENSION', scope: 'FILE' },
148
- { condition: '=', value: '.plist', ftype: 'EXTENSION', scope: 'FILE' },
149
- { condition: '=', value: '.png', ftype: 'EXTENSION', scope: 'FILE' },
150
- { condition: '=', value: '.po', ftype: 'EXTENSION', scope: 'FILE' },
151
- { condition: '=', value: '.ppt', ftype: 'EXTENSION', scope: 'FILE' },
152
- { condition: '=', value: '.prefs', ftype: 'EXTENSION', scope: 'FILE' },
153
- { condition: '=', value: '.properties', ftype: 'EXTENSION', scope: 'FILE' },
154
- { condition: '=', value: '.pyc', ftype: 'EXTENSION', scope: 'FILE' },
155
- { condition: '=', value: '.qdoc', ftype: 'EXTENSION', scope: 'FILE' },
156
- { condition: '=', value: '.result', ftype: 'EXTENSION', scope: 'FILE' },
157
- { condition: '=', value: '.rgb', ftype: 'EXTENSION', scope: 'FILE' },
158
- { condition: '=', value: '.rst', ftype: 'EXTENSION', scope: 'FILE' },
159
- { condition: '=', value: '.scss', ftype: 'EXTENSION', scope: 'FILE' },
160
- { condition: '=', value: '.sha', ftype: 'EXTENSION', scope: 'FILE' },
161
- { condition: '=', value: '.sha1', ftype: 'EXTENSION', scope: 'FILE' },
162
- { condition: '=', value: '.sha2', ftype: 'EXTENSION', scope: 'FILE' },
163
- { condition: '=', value: '.sha256', ftype: 'EXTENSION', scope: 'FILE' },
164
- { condition: '=', value: '.sln', ftype: 'EXTENSION', scope: 'FILE' },
165
- { condition: '=', value: '.spec', ftype: 'EXTENSION', scope: 'FILE' },
166
- { condition: '=', value: '.sql', ftype: 'EXTENSION', scope: 'FILE' },
167
- { condition: '=', value: '.sub', ftype: 'EXTENSION', scope: 'FILE' },
168
- { condition: '=', value: '.svg', ftype: 'EXTENSION', scope: 'FILE' },
169
- { condition: '=', value: '.svn-base', ftype: 'EXTENSION', scope: 'FILE' },
170
- { condition: '=', value: '.tab', ftype: 'EXTENSION', scope: 'FILE' },
171
- { condition: '=', value: '.template', ftype: 'EXTENSION', scope: 'FILE' },
172
- { condition: '=', value: '.test', ftype: 'EXTENSION', scope: 'FILE' },
173
- { condition: '=', value: '.tex', ftype: 'EXTENSION', scope: 'FILE' },
174
- { condition: '=', value: '.tiff', ftype: 'EXTENSION', scope: 'FILE' },
175
- { condition: '=', value: '.toml', ftype: 'EXTENSION', scope: 'FILE' },
176
- { condition: '=', value: '.ttf', ftype: 'EXTENSION', scope: 'FILE' },
177
- { condition: '=', value: '.txt', ftype: 'EXTENSION', scope: 'FILE' },
178
- { condition: '=', value: '.utf-8', ftype: 'EXTENSION', scope: 'FILE' },
179
- { condition: '=', value: '.vim', ftype: 'EXTENSION', scope: 'FILE' },
180
- { condition: '=', value: '.wav', ftype: 'EXTENSION', scope: 'FILE' },
181
- { condition: '=', value: '.whl', ftype: 'EXTENSION', scope: 'FILE' },
182
- { condition: '=', value: '.woff', ftype: 'EXTENSION', scope: 'FILE' },
183
- { condition: '=', value: '.xht', ftype: 'EXTENSION', scope: 'FILE' },
184
- { condition: '=', value: '.xhtml', ftype: 'EXTENSION', scope: 'FILE' },
185
- { condition: '=', value: '.xls', ftype: 'EXTENSION', scope: 'FILE' },
186
- { condition: '=', value: '.xlsx', ftype: 'EXTENSION', scope: 'FILE' },
187
- { condition: '=', value: '.xml', ftype: 'EXTENSION', scope: 'FILE' },
188
- { condition: '=', value: '.xpm', ftype: 'EXTENSION', scope: 'FILE' },
189
- { condition: '=', value: '.xsd', ftype: 'EXTENSION', scope: 'FILE' },
190
- { condition: '=', value: '.xul', ftype: 'EXTENSION', scope: 'FILE' },
191
- { condition: '=', value: '.yaml', ftype: 'EXTENSION', scope: 'FILE' },
192
- { condition: '=', value: '.yml', ftype: 'EXTENSION', scope: 'FILE' },
193
- { condition: '=', value: '.wfp', ftype: 'EXTENSION', scope: 'FILE' },
194
- { condition: '=', value: '.editorconfig', ftype: 'EXTENSION', scope: 'FILE' },
195
- { condition: '=', value: '.dotcover', ftype: 'EXTENSION', scope: 'FILE' },
196
- { condition: '=', value: '.pid', ftype: 'EXTENSION', scope: 'FILE' },
197
- { condition: '=', value: '.lcov', ftype: 'EXTENSION', scope: 'FILE' },
198
- { condition: '=', value: '.egg', ftype: 'EXTENSION', scope: 'FILE' },
199
- { condition: '=', value: '.manifest', ftype: 'EXTENSION', scope: 'FILE' },
200
- { condition: '=', value: '.cache', ftype: 'EXTENSION', scope: 'FILE' },
201
- { condition: '=', value: '.coverage', ftype: 'EXTENSION', scope: 'FILE' },
202
- { condition: '=', value: '.cover', ftype: 'EXTENSION', scope: 'FILE' },
203
- { condition: '=', value: '.gem', ftype: 'EXTENSION', scope: 'FILE' },
204
- { condition: '=', value: '.lst', ftype: 'EXTENSION', scope: 'FILE' },
205
- ],
206
- };
207
-
@@ -1,234 +0,0 @@
1
- import fs from 'fs';
2
- import * as fpath from 'path';
3
- import { isBinaryFileSync } from 'isbinaryfile';
4
-
5
- export enum FilterType {
6
- NAME = 'NAME',
7
- CONTENT = 'CONTENT',
8
- EXTENSION = 'EXTENSION',
9
- SIZE = 'SIZE',
10
- DATE = 'DATE',
11
- };
12
-
13
- export enum FilterListType {
14
- BANNED = 'BANNED',
15
- WHITELIST = 'WHITELIST',
16
- };
17
-
18
- class AbstractFilter {
19
- condition: string;
20
-
21
- value: string;
22
-
23
- ftype: string;
24
-
25
- scope: string;
26
-
27
- constructor(condition: string, value: string) {
28
- this.condition = condition;
29
- this.value = value;
30
- this.ftype = 'NONE';
31
- this.scope = 'ALL';
32
- }
33
-
34
- evaluate(path: string): boolean {
35
- return true;
36
- }
37
- }
38
- class NameFilter extends AbstractFilter {
39
- constructor(condition: string, value: string, scope: string) {
40
- super(condition, value);
41
- this.ftype = 'NAME';
42
- this.scope = scope || super.scope;
43
- }
44
-
45
- evaluate(path: string): boolean {
46
- this.value = this.value.toLowerCase();
47
- path = path.toLowerCase();
48
-
49
- if (this.condition === 'contains') {
50
- return !(path.indexOf(this.value) >= 0);
51
- }
52
- if (this.condition === 'fullmatch') return fpath.basename(path) !== this.value;
53
- if (this.condition === 'starts') {
54
- let filename: string;
55
- filename = fpath.basename(path);
56
- return !filename.startsWith(this.value);
57
- }
58
- if (this.condition === 'ends') {
59
- let filename: string;
60
- filename = fpath.basename(path);
61
- return !filename.endsWith(this.value);
62
- }
63
-
64
- return true;
65
- }
66
- }
67
-
68
- class ContentFilter extends AbstractFilter {
69
- constructor(condition: string, value: string, scope: string) {
70
- super(condition, value);
71
- this.ftype = 'CONTENT';
72
- this.scope = scope || super.scope; // Verificar
73
- }
74
-
75
- evaluate(path: string): boolean {
76
- const binary = isBinaryFileSync(path);
77
-
78
- if (this.condition === '=' && this.value === 'BINARY' && binary) return false;
79
- if (this.condition === '!=' && this.value === 'TEXT' && binary) return false;
80
- if (this.condition === '=' && this.value === 'TEXT' && !binary) return false;
81
- if (this.condition === '!=' && this.value === 'BINARY' && !binary) return false;
82
- return true;
83
- }
84
- }
85
-
86
- class ExtensionFilter extends AbstractFilter {
87
- constructor(condition: string, value: string, scope: string) {
88
- super(condition, value);
89
- this.ftype = 'EXTENSION';
90
- this.scope = scope || super.scope; // Verificar
91
- }
92
-
93
- evaluate(path: string): boolean {
94
- path = path.toLowerCase();
95
- this.value = this.value.toLowerCase();
96
- return !path.endsWith(this.value);
97
- }
98
- }
99
-
100
- class SizeFilter extends AbstractFilter {
101
- constructor(condition: string, value: string, scope: string) {
102
- super(condition, value);
103
- this.ftype = 'SIZE';
104
- this.scope = scope || super.scope; // Verificar
105
- }
106
-
107
- evaluate(path: string): boolean {
108
- const stat = fs.statSync(path);
109
-
110
- if (this.condition === '>') {
111
- if (stat.size > parseInt(this.value, 10)) {
112
- // console.log("NO aceptado por que NO es mayor");
113
- return false;
114
- }
115
- return true;
116
- }
117
- if (this.condition === '<') {
118
- if (stat.size < parseInt(this.value, 10)) {
119
- return false;
120
- }
121
- return true;
122
- }
123
- if (this.condition === '=') {
124
- if (stat.size === parseInt(this.value, 10)) {
125
- return false;
126
- }
127
-
128
- return true;
129
- }
130
-
131
- return true;
132
- }
133
- }
134
- class DateFilter extends AbstractFilter {
135
- constructor(condition: string, value: string, scope: string) {
136
- super(condition, value);
137
- this.ftype = 'DATE';
138
- this.scope = scope || super.scope; // Verificar
139
- }
140
-
141
- evaluate(path: string): boolean {
142
- const stats = fs.statSync(path);
143
-
144
- modified = stats.mtime;
145
-
146
- const lDate = new Date(this.value);
147
-
148
- const ms: number = stats.mtimeMs;
149
- var modified = new Date(ms);
150
- // console.log(lDate);
151
- // console.log(modified);
152
- if (this.condition === '>') {
153
- if (modified > lDate) {
154
- return false;
155
- }
156
- return true;
157
- }
158
- if (this.condition === '<') {
159
- if (modified < lDate) {
160
- return false;
161
- }
162
- return true;
163
- }
164
- return true;
165
- }
166
- }
167
-
168
- export class FilterList {
169
- type: FilterListType;
170
-
171
- name: string;
172
-
173
- filters: AbstractFilter[];
174
-
175
- constructor(name: string) {
176
- this.name = name;
177
- this.filters = [];
178
- }
179
-
180
- addFilter(filter: AbstractFilter): void {
181
- this.filters.push(filter);
182
- }
183
-
184
- // Returns false if the path match with some filter in the list
185
- evaluate(path: string): boolean {
186
- const pathStat = fs.lstatSync(path);
187
-
188
- let i: number;
189
- for (i = 0; i < this.filters.length; i += 1) {
190
- const evaluation = this.filters[i].evaluate(path);
191
-
192
- if (this.filters[i].scope === 'FOLDER' && pathStat.isDirectory() && !evaluation) return false;
193
-
194
- if (this.filters[i].scope === 'FILE' && pathStat.isFile() && !evaluation) return false;
195
-
196
- if (this.filters[i].scope === 'ALL' && !evaluation) return false;
197
- }
198
- return true;
199
- }
200
-
201
- public include(path: string): boolean {
202
- if(this.type === FilterListType.BANNED) return this.evaluate(path);
203
- return !this.evaluate(path);
204
- }
205
-
206
- save(path: string) {
207
- fs.writeFileSync(path, JSON.stringify(this.filters).toString());
208
- }
209
-
210
- loadFromFile(path: string) {
211
- const json = fs.readFileSync(path, 'utf8');
212
- const filters = JSON.parse(json);
213
- this.load(filters);
214
- }
215
-
216
- load(fList: FilterList) {
217
- this.name = fList.name;
218
- this.type = fList.type;
219
-
220
- const a = fList.filters;
221
-
222
- let i: number;
223
- for (i = 0; i < a.length; i += 1) {
224
- const scope = a[i].scope || 'ALL';
225
- if (a[i].ftype === 'NAME') this.addFilter(new NameFilter(a[i].condition, a[i].value, scope));
226
- if (a[i].ftype === 'DATE') this.addFilter(new DateFilter(a[i].condition, a[i].value, scope));
227
- if (a[i].ftype === 'SIZE') this.addFilter(new SizeFilter(a[i].condition, a[i].value, scope));
228
- if (a[i].ftype === 'EXTENSION') this.addFilter(new ExtensionFilter(a[i].condition, a[i].value, scope));
229
- if (a[i].ftype === 'CONTENT') this.addFilter(new ContentFilter(a[i].condition, a[i].value, scope));
230
- }
231
- }
232
- }
233
-
234
-
@@ -1,29 +0,0 @@
1
- import { WinnowerResponse } from "../Winnower/WinnowerResponse";
2
-
3
- export class DispatchableItem {
4
- private winnowerResponse: WinnowerResponse;
5
-
6
- private errorCounter: number;
7
-
8
- constructor(winnowerResponse) {
9
- this.winnowerResponse = winnowerResponse;
10
- this.errorCounter = 0;
11
- }
12
-
13
- increaseErrorCounter() {
14
- this.errorCounter += 1;
15
- }
16
-
17
- public getWinnowerResponse(): WinnowerResponse {
18
- return this.winnowerResponse;
19
- }
20
-
21
- getContent() {
22
- return this.winnowerResponse.getContent();
23
- }
24
-
25
- getErrorCounter() {
26
- return this.errorCounter;
27
- }
28
-
29
- }