scanoss 0.7.8 → 0.7.9

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 (67) hide show
  1. package/.idea/workspace.xml +47 -31
  2. package/.nyc_output/3da9f448-90e4-4399-887b-e4fd1b8d7052.json +1 -0
  3. package/.nyc_output/processinfo/3da9f448-90e4-4399-887b-e4fd1b8d7052.json +1 -0
  4. package/.nyc_output/processinfo/index.json +1 -0
  5. package/build/main/index.d.ts +2 -0
  6. package/build/main/index.js +3 -1
  7. package/build/main/sdk/FileCount/FileCount.d.ts +6 -0
  8. package/build/main/sdk/FileCount/FileCount.js +88 -0
  9. package/build/main/sdk/FileCount/FileCountFilter.d.ts +2 -0
  10. package/build/main/sdk/FileCount/FileCountFilter.js +10 -0
  11. package/build/main/sdk/FileCount/Interfaces.d.ts +19 -0
  12. package/build/main/sdk/FileCount/Interfaces.js +8 -0
  13. package/build/main/sdk/Filtering/DefaultFilterForDependencies.d.ts +2 -0
  14. package/build/main/sdk/Filtering/DefaultFilterForDependencies.js +144 -0
  15. package/build/main/sdk/Filtering/DefaultFilterForScanning.d.ts +2 -0
  16. package/build/main/sdk/Filtering/DefaultFilterForScanning.js +193 -0
  17. package/build/main/sdk/Filtering/Filtering.d.ts +80 -0
  18. package/build/main/sdk/Filtering/Filtering.js +259 -0
  19. package/build/main/sdk/tree/Filters/DependencyFilter.js +4 -4
  20. package/build/main/sdk/tree/Filters/ScanFilter.js +4 -4
  21. package/build/main/tsconfig.tsbuildinfo +81 -38
  22. package/build/module/index.d.ts +2 -0
  23. package/build/module/index.js +3 -1
  24. package/build/module/sdk/FileCount/FileCount.d.ts +6 -0
  25. package/build/module/sdk/FileCount/FileCount.js +63 -0
  26. package/build/module/sdk/FileCount/FileCountFilter.d.ts +2 -0
  27. package/build/module/sdk/FileCount/FileCountFilter.js +8 -0
  28. package/build/module/sdk/FileCount/Interfaces.d.ts +19 -0
  29. package/build/module/sdk/FileCount/Interfaces.js +6 -0
  30. package/build/module/sdk/Filtering/DefaultFilterForDependencies.d.ts +2 -0
  31. package/build/module/sdk/Filtering/DefaultFilterForDependencies.js +142 -0
  32. package/build/module/sdk/Filtering/DefaultFilterForScanning.d.ts +2 -0
  33. package/build/module/sdk/Filtering/DefaultFilterForScanning.js +191 -0
  34. package/build/module/sdk/Filtering/Filtering.d.ts +80 -0
  35. package/build/module/sdk/Filtering/Filtering.js +229 -0
  36. package/build/module/sdk/tree/Filters/DependencyFilter.js +4 -4
  37. package/build/module/sdk/tree/Filters/ScanFilter.js +4 -4
  38. package/build/module/tsconfig.module.tsbuildinfo +81 -38
  39. package/package-lock.json +2 -3
  40. package/package.json +3 -3
  41. package/src/index.ts +5 -0
  42. package/src/sdk/FileCount/FileCount.ts +81 -0
  43. package/src/sdk/FileCount/FileCountFilter.ts +14 -0
  44. package/src/sdk/FileCount/Interfaces.ts +23 -0
  45. package/src/sdk/Filtering/DefaultFilterForDependencies.ts +148 -0
  46. package/src/sdk/Filtering/DefaultFilterForScanning.ts +206 -0
  47. package/src/sdk/Filtering/Filtering.ts +273 -0
  48. package/src/sdk/tree/Filters/DependencyFilter.ts +4 -4
  49. package/src/sdk/tree/Filters/ScanFilter.ts +4 -4
  50. package/src/sdk/tree/Node.ts +1 -1
  51. package/src/sdk/tree/Tree.ts +1 -1
  52. package/tests/sdk/FileCount/FileCount.spec.ts +35 -0
  53. package/tests/sdk/FileCount/samples/16557/.y.ts +27 -0
  54. package/tests/sdk/FileCount/samples/16557/.z.ts +129 -0
  55. package/tests/sdk/FileCount/samples/16557/files/a.ts +195 -0
  56. package/tests/sdk/FileCount/samples/16557/files/b.ts +184 -0
  57. package/tests/sdk/FileCount/samples/16557/files/c.ts +47 -0
  58. package/tests/sdk/FileCount/samples/22036/files/a.ts +195 -0
  59. package/tests/sdk/FileCount/samples/22036/files/b.ts +184 -0
  60. package/tests/sdk/FileCount/samples/22036/files/c.ts +47 -0
  61. package/tests/sdk/FileCount/samples/22036/files/d.ts +48 -0
  62. package/tests/sdk/FileCount/samples/22036/y.ts +27 -0
  63. package/tests/sdk/FileCount/samples/22036/z.ts +129 -0
  64. package/yarn.lock +4938 -4938
  65. package/src/sdk/filters/DefaultFilterForDependencies.ts +0 -149
  66. package/src/sdk/filters/DefaultFilterForScanning.ts +0 -207
  67. package/src/sdk/filters/filtering.ts +0 -235
@@ -0,0 +1,273 @@
1
+ import fs from 'fs';
2
+ import * as fpath from 'path';
3
+ import { isBinaryFileSync } from 'isbinaryfile';
4
+
5
+
6
+
7
+ export interface IFilter {
8
+ type: FilterListType.ALLOW | FilterListType.BANNED;
9
+ filters: Array<{
10
+ ftype: FilterType;
11
+ scope: FilterScope;
12
+ condition: string;
13
+ value: string;
14
+ }>;
15
+ }
16
+
17
+ export enum FilterType {
18
+ NAME = 'NAME',
19
+ CONTENT = 'CONTENT',
20
+ EXTENSION = 'EXTENSION',
21
+ SIZE = 'SIZE',
22
+ DATE = 'DATE',
23
+ NULL = 'NONE'
24
+ };
25
+
26
+ export enum FilterListType {
27
+ BANNED = 'BANNED',
28
+ ALLOW = 'ALLOW',
29
+ };
30
+
31
+ export enum FilterScope {
32
+ FOLDER = 'FOLDER',
33
+ FILE = 'FILE',
34
+ ALL = 'ALL',
35
+ }
36
+
37
+ class AbstractFilter {
38
+ condition: string;
39
+
40
+ value: string;
41
+
42
+ ftype: FilterType;
43
+
44
+ scope: FilterScope;
45
+
46
+ constructor(condition: string, value: string) {
47
+ this.condition = condition;
48
+ this.value = value;
49
+ this.ftype = FilterType.NULL;
50
+ this.scope = FilterScope.ALL;
51
+ }
52
+
53
+ evaluate(path: string): boolean {
54
+ return true;
55
+ }
56
+ }
57
+
58
+ export class NameFilter extends AbstractFilter {
59
+ static CONTAINS = 'contains';
60
+ static FULLMATCH = 'fullmatch';
61
+ static STARTS = 'starts';
62
+ static ENDS = 'ends';
63
+
64
+ constructor(condition: string, value: string, scope: FilterScope) {
65
+ super(condition, value);
66
+ this.ftype = FilterType.NAME;
67
+ this.scope = scope || super.scope;
68
+ }
69
+
70
+ evaluate(path: string): boolean {
71
+ this.value = this.value.toLowerCase();
72
+ path = path.toLowerCase();
73
+
74
+ if (this.condition === NameFilter.CONTAINS) {
75
+ return !(path.indexOf(this.value) >= 0);
76
+ }
77
+ if (this.condition === NameFilter.FULLMATCH) return fpath.basename(path) !== this.value;
78
+ if (this.condition === NameFilter.STARTS) {
79
+ let filename: string;
80
+ filename = fpath.basename(path);
81
+ return !filename.startsWith(this.value);
82
+ }
83
+ if (this.condition === NameFilter.ENDS) {
84
+ let filename: string;
85
+ filename = fpath.basename(path);
86
+ return !filename.endsWith(this.value);
87
+ }
88
+
89
+ return true;
90
+ }
91
+ }
92
+
93
+ export class ContentFilter extends AbstractFilter {
94
+ static VALUE_BINARY = 'BINARY';
95
+ static VALUE_TEXT = 'TEXT';
96
+ static EQUAL = '=';
97
+ static NOT_EQUAL = '!=';
98
+
99
+ constructor(condition: string, value: string, scope: FilterScope) {
100
+ super(condition, value);
101
+ this.ftype = FilterType.CONTENT;
102
+ this.scope = scope || super.scope; // Verificar
103
+ }
104
+
105
+ evaluate(path: string): boolean {
106
+ const binary = isBinaryFileSync(path);
107
+
108
+ if (this.condition === ContentFilter.EQUAL && this.value === ContentFilter.VALUE_BINARY && binary) return false;
109
+ if (this.condition === ContentFilter.NOT_EQUAL && this.value === ContentFilter.VALUE_TEXT && binary) return false;
110
+ if (this.condition === ContentFilter.EQUAL && this.value === ContentFilter.VALUE_TEXT && !binary) return false;
111
+ if (this.condition === ContentFilter.NOT_EQUAL && this.value === ContentFilter.VALUE_BINARY && !binary) return false;
112
+ return true;
113
+ }
114
+ }
115
+
116
+ export class ExtensionFilter extends AbstractFilter {
117
+
118
+ constructor(condition: string, value: string, scope: FilterScope) {
119
+ super(condition, value);
120
+ this.ftype = FilterType.EXTENSION;
121
+ this.scope = scope || super.scope; // Verificar
122
+ }
123
+
124
+ evaluate(path: string): boolean {
125
+ path = path.toLowerCase();
126
+ this.value = this.value.toLowerCase();
127
+ return !path.endsWith(this.value);
128
+ }
129
+ }
130
+
131
+ export class SizeFilter extends AbstractFilter {
132
+ static BIGGER = '>'
133
+ static SMALLER = '<'
134
+ static EQUAL = '='
135
+ constructor(condition: string, value: string, scope: FilterScope) {
136
+ super(condition, value);
137
+ this.ftype = FilterType.SIZE;
138
+ this.scope = scope || super.scope; // Verificar
139
+ }
140
+
141
+ evaluate(path: string): boolean {
142
+ const stat = fs.statSync(path);
143
+
144
+ if (this.condition === SizeFilter.BIGGER) {
145
+ if (stat.size > parseInt(this.value, 10)) {
146
+ // console.log("NO aceptado por que NO es mayor");
147
+ return false;
148
+ }
149
+ return true;
150
+ }
151
+ if (this.condition === SizeFilter.SMALLER) {
152
+ if (stat.size < parseInt(this.value, 10)) {
153
+ return false;
154
+ }
155
+ return true;
156
+ }
157
+ if (this.condition === SizeFilter.EQUAL) {
158
+ if (stat.size === parseInt(this.value, 10)) {
159
+ return false;
160
+ }
161
+
162
+ return true;
163
+ }
164
+
165
+ return true;
166
+ }
167
+ }
168
+ export class DateFilter extends AbstractFilter {
169
+ static BIGGER = '>'
170
+ static SMALLER = '<'
171
+ constructor(condition: string, value: string, scope: FilterScope) {
172
+ super(condition, value);
173
+ this.ftype = FilterType.NAME;
174
+ this.scope = scope || super.scope; // Verificar
175
+ }
176
+
177
+ evaluate(path: string): boolean {
178
+ const stats = fs.statSync(path);
179
+
180
+ modified = stats.mtime;
181
+
182
+ const lDate = new Date(this.value);
183
+
184
+ const ms: number = stats.mtimeMs;
185
+ var modified = new Date(ms);
186
+ // console.log(lDate);
187
+ // console.log(modified);
188
+ if (this.condition === DateFilter.BIGGER) {
189
+ if (modified > lDate) {
190
+ return false;
191
+ }
192
+ return true;
193
+ }
194
+ if (this.condition === DateFilter.SMALLER) {
195
+ if (modified < lDate) {
196
+ return false;
197
+ }
198
+ return true;
199
+ }
200
+ return true;
201
+ }
202
+ }
203
+
204
+ export class FilterList {
205
+ type: FilterListType;
206
+
207
+ filters: AbstractFilter[];
208
+
209
+ constructor(fList?: IFilter) {
210
+ this.filters = [];
211
+ if (fList) this.load(fList);
212
+ }
213
+
214
+ public addFilter(filter: AbstractFilter): void {
215
+ this.filters.push(filter);
216
+ }
217
+
218
+ // Returns false if the path match with some filter in the list
219
+ // IMPORTANT: This method DOES NOT honor the FilterType (BANNED | ALLOW)
220
+ // Use the method include to honor the FilterType
221
+ public evaluate(path: string): boolean {
222
+ const pathStat = fs.lstatSync(path);
223
+
224
+ let i: number;
225
+ for (i = 0; i < this.filters.length; i += 1) {
226
+ const evaluation = this.filters[i].evaluate(path);
227
+
228
+ if (this.filters[i].scope === FilterScope.FOLDER && pathStat.isDirectory() && !evaluation) return false;
229
+
230
+ if (this.filters[i].scope === FilterScope.FILE && pathStat.isFile() && !evaluation) return false;
231
+
232
+ if (this.filters[i].scope === FilterScope.ALL && !evaluation) return false;
233
+ }
234
+ return true;
235
+ }
236
+
237
+ //
238
+ public include(path: string): boolean {
239
+ if(this.type === FilterListType.BANNED) return this.evaluate(path);
240
+ return !this.evaluate(path);
241
+ }
242
+
243
+ public save(path: string) {
244
+ fs.writeFileSync(path, JSON.stringify(this.filters).toString());
245
+ }
246
+
247
+ public loadFromFile(path: string) {
248
+ const json = fs.readFileSync(path, 'utf8');
249
+ const filters = JSON.parse(json);
250
+ this.load(filters);
251
+ }
252
+
253
+ public unload() {
254
+ this.filters = [];
255
+ }
256
+
257
+ public load(fList: IFilter) {
258
+ this.type = fList.type;
259
+ const a = fList.filters;
260
+
261
+ let i: number;
262
+ for (i = 0; i < a.length; i += 1) {
263
+ const scope = a[i].scope || FilterScope.ALL;
264
+ if (a[i].ftype === FilterType.NAME) this.addFilter(new NameFilter(a[i].condition, a[i].value, scope));
265
+ if (a[i].ftype === FilterType.DATE) this.addFilter(new DateFilter(a[i].condition, a[i].value, scope));
266
+ if (a[i].ftype === FilterType.SIZE) this.addFilter(new SizeFilter(a[i].condition, a[i].value, scope));
267
+ if (a[i].ftype === FilterType.EXTENSION) this.addFilter(new ExtensionFilter(a[i].condition, a[i].value, scope));
268
+ if (a[i].ftype === FilterType.CONTENT) this.addFilter(new ContentFilter(a[i].condition, a[i].value, scope));
269
+ }
270
+ }
271
+ }
272
+
273
+
@@ -1,9 +1,9 @@
1
1
  import { Filter } from './Filter';
2
2
  import Node from '../Node'
3
- import { FilterList } from '../../filters/filtering';
3
+ import { FilterList, IFilter} from '../../Filtering/Filtering';
4
4
  import {
5
5
  defaultFilterForDependencies
6
- } from '../../filters/DefaultFilterForDependencies';
6
+ } from '../../Filtering/DefaultFilterForDependencies';
7
7
 
8
8
  export class DependencyFilter extends Filter {
9
9
 
@@ -11,8 +11,8 @@ export class DependencyFilter extends Filter {
11
11
 
12
12
  public constructor(filterName: string) {
13
13
  super();
14
- this.filter = new FilterList(filterName);
15
- this.filter.load(defaultFilterForDependencies as FilterList)
14
+ this.filter = new FilterList();
15
+ this.filter.load(defaultFilterForDependencies)
16
16
  }
17
17
 
18
18
  public evaluate(node: Node): boolean {
@@ -1,9 +1,9 @@
1
1
  import { Filter } from './Filter';
2
2
  import Node from '../Node'
3
- import { FilterList } from '../../filters/filtering';
3
+ import { FilterList } from '../../Filtering/Filtering';
4
4
  import {
5
5
  defaultFilterForScanning
6
- } from '../../filters/DefaultFilterForScanning';
6
+ } from '../../Filtering/DefaultFilterForScanning';
7
7
 
8
8
  export class ScanFilter extends Filter {
9
9
 
@@ -11,8 +11,8 @@ export class ScanFilter extends Filter {
11
11
 
12
12
  public constructor(filterName: string) {
13
13
  super();
14
- this.filter = new FilterList(filterName);
15
- this.filter.load(defaultFilterForScanning as FilterList)
14
+ this.filter = new FilterList();
15
+ this.filter.load(defaultFilterForScanning)
16
16
  }
17
17
 
18
18
  public evaluate(node: Node): boolean {
@@ -1,4 +1,4 @@
1
- import { FilterList } from '../filters/filtering';
1
+ import { FilterList } from '../Filtering/Filtering';
2
2
  import { Filter } from './Filters/Filter';
3
3
 
4
4
  export default abstract class Node {
@@ -6,7 +6,7 @@ import { NodeType } from './Node';
6
6
  import Node from './Node';
7
7
  import File from './File';
8
8
  import Folder from './Folder';
9
- import { FilterList } from '../filters/filtering';
9
+ import { FilterList } from '../Filtering/Filtering';
10
10
  import { Filter } from './Filters/Filter';
11
11
 
12
12
  export class Tree {
@@ -0,0 +1,35 @@
1
+ import { FileCount } from '../../../src/sdk/FileCount/FileCount';
2
+ import { IDirSummary } from '../../../src/sdk/FileCount/Interfaces';
3
+ import path from 'path';
4
+ import { Format } from '../../../src/sdk/FileCount/Interfaces';
5
+ import { expect } from 'chai';
6
+
7
+ describe('Suit test for FileCount', () => {
8
+
9
+ it('Testing empty dir with CSV and RAW formats', async function() {
10
+
11
+ let data = await FileCount.walk(path.join(__dirname, './samples/0'), );
12
+ expect((data as IDirSummary).totalFileSize ).to.be.equal(0)
13
+ expect((data as IDirSummary).fileSummary.size ).to.be.equal(0)
14
+
15
+
16
+ data = await FileCount.walk(path.join(__dirname, './samples/0'), {output: Format.CSV});
17
+ expect(data).equal( "");
18
+ });
19
+
20
+
21
+ it('Testing dir with files', async function() {
22
+ const data = await FileCount.walk(path.join(__dirname, './samples/22036'), { output: Format.CSV});
23
+ expect(data).equal('.ts,6,1\n');
24
+ });
25
+
26
+
27
+ it('Testing dir with hidden files in CSV formats', async function() {
28
+ const data = await FileCount.walk(path.join(__dirname, './samples/16557'), { output: Format.CSV});
29
+ expect(data).equal('.ts,3,1\n');
30
+ });
31
+
32
+
33
+
34
+ });
35
+
@@ -0,0 +1,27 @@
1
+ // import { DataProvider, IDataLayers } from './DataLayerTypes';
2
+ //
3
+ // export class DataProviderManager {
4
+ // private dataLayersProviders: Array<DataProvider>;
5
+ //
6
+ // constructor() {
7
+ // this.dataLayersProviders = [];
8
+ // }
9
+ //
10
+ // public addDataProvider(l: DataProvider) {
11
+ // this.dataLayersProviders.push(l)
12
+ // }
13
+ //
14
+ // public generateData(): IDataLayers {
15
+ //
16
+ // let dataLayer: IDataLayers = {
17
+ // component: null,
18
+ // dependencies: null,
19
+ // vulnerabilities: null,
20
+ // summary: null,
21
+ // licenses: null
22
+ // };
23
+ //
24
+ // for (const layer of this.dataLayersProviders) Object.assign(dataLayer, layer.getData());
25
+ // return dataLayer;
26
+ // }
27
+ // }
@@ -0,0 +1,129 @@
1
+ // /************* Component interface definition *************/
2
+ // export interface ComponentDataLayer {
3
+ // key: string; // purl[0]
4
+ // purls: string[];
5
+ // name: string;
6
+ // vendor: string;
7
+ // url: string;
8
+ // health: Health;
9
+ // versions: Version[];
10
+ // }
11
+ //
12
+ // export interface Version {
13
+ // version: string;
14
+ // licenses: string[]
15
+ // copyrights: Copyright[]
16
+ // cryptography: Cryptography[];
17
+ // quality: Quality;
18
+ // }
19
+ //
20
+ // export interface Copyright {
21
+ // name: string;
22
+ // source: string;
23
+ // };
24
+ //
25
+ // export interface Cryptography {
26
+ // algorithm: string;
27
+ // strength: string;
28
+ // };
29
+ //
30
+ // export interface Quality {
31
+ // scoreAvg: number;
32
+ // count: number;
33
+ // sum: number; //TODO remove
34
+ // };
35
+ //
36
+ // export interface Health {
37
+ // creation_date: string;
38
+ // issues: number;
39
+ // last_push: string;
40
+ // last_update: string;
41
+ // watchers: number;
42
+ // country: string;
43
+ // stars: number;
44
+ // forks: number;
45
+ // }
46
+ // /************* Component interface definition *************/
47
+ //
48
+ //
49
+ // /************* Dependency interface definition *************/
50
+ // export interface DependencyDataLayer {
51
+ // file: string;
52
+ // dependencies: Dependency[];
53
+ // }
54
+ //
55
+ // export interface License {
56
+ // name: string;
57
+ // spdxid: string;
58
+ // }
59
+ //
60
+ // export interface Dependency {
61
+ // purl: string;
62
+ // component: string;
63
+ // version: string;
64
+ // licenses: License[]
65
+ // }
66
+ // /************* Dependency interface definition *************/
67
+ //
68
+ // /************* Vulnerability interface definition *************/
69
+ // export interface Vulnerability {
70
+ // id: string;
71
+ // cve: string;
72
+ // url: string;
73
+ // summary: string;
74
+ // severity: string;
75
+ // published: string;
76
+ // modified: string;
77
+ // source: string;
78
+ // }
79
+ //
80
+ // export interface VulnerabilityDataLayer {
81
+ // purl: string;
82
+ // vulnerability: Vulnerability[];
83
+ // }
84
+ // /************* Vulnerability interface definition *************/
85
+ //
86
+ //
87
+ // /************* License interface definition *************/
88
+ // export interface LicenseDataLayer {
89
+ // label: string;
90
+ // value: number; //Number of licenses found
91
+ // components: Array<LicenseComponent>;
92
+ // incompatibleWith: Array<string>;
93
+ // hasIncompatibles: Array<string>;
94
+ // copyleft:boolean;
95
+ // }
96
+ //
97
+ //
98
+ // export interface LicenseComponent {
99
+ // purl: string;
100
+ // name: string;
101
+ // versions: Array<string>;
102
+ // url:string;
103
+ // vendor:string;
104
+ // }
105
+ // /************* License interface definition *************/
106
+ //
107
+ // export interface SummaryDataLayer {
108
+ // projectName: string;
109
+ // timestamp: Date;
110
+ // matchedFiles: number;
111
+ // noMatchFiles: number;
112
+ // totalFiles: number;
113
+ // }
114
+ //
115
+ // // Each layer is created to group by differents criteria.
116
+ // export interface IDataLayers {
117
+ // licenses: LicenseDataLayer[];
118
+ // component: ComponentDataLayer[];
119
+ // dependencies: DependencyDataLayer[];
120
+ // vulnerabilities: VulnerabilityDataLayer[];
121
+ // summary: SummaryDataLayer;
122
+ // }
123
+ //
124
+ //
125
+ // export interface DataProvider {
126
+ // getData(): IDataLayers;
127
+ // getLayerName(): string;
128
+ // }
129
+ //