@contrast/contrast 1.0.8 → 1.0.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 (173) hide show
  1. package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +3 -12
  2. package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +88 -53
  3. package/dist/audit/languageAnalysisEngine/report/models/reportOutputModel.js +4 -3
  4. package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +58 -11
  5. package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +38 -5
  6. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +6 -30
  7. package/dist/audit/save.js +21 -13
  8. package/dist/commands/audit/auditConfig.js +0 -16
  9. package/dist/commands/audit/auditController.js +1 -10
  10. package/dist/commands/audit/help.js +7 -24
  11. package/dist/commands/audit/processAudit.js +1 -7
  12. package/dist/commands/audit/saveFile.js +2 -2
  13. package/dist/commands/scan/sca/scaAnalysis.js +22 -9
  14. package/dist/common/HTTPClient.js +8 -8
  15. package/dist/constants/constants.js +7 -2
  16. package/dist/constants/locales.js +24 -30
  17. package/dist/constants.js +11 -9
  18. package/dist/index.js +54 -45
  19. package/dist/lambda/lambda.js +5 -2
  20. package/dist/sbom/generateSbom.js +2 -2
  21. package/dist/scaAnalysis/common/formatMessage.js +7 -1
  22. package/dist/scaAnalysis/common/treeUpload.js +4 -5
  23. package/dist/scaAnalysis/dotnet/analysis.js +43 -0
  24. package/dist/scaAnalysis/dotnet/index.js +10 -0
  25. package/dist/scaAnalysis/javascript/analysis.js +4 -7
  26. package/dist/scaAnalysis/javascript/index.js +14 -5
  27. package/dist/scaAnalysis/php/analysis.js +14 -33
  28. package/dist/scaAnalysis/php/index.js +11 -4
  29. package/dist/scaAnalysis/ruby/analysis.js +2 -10
  30. package/dist/scan/autoDetection.js +18 -21
  31. package/dist/scan/fileUtils.js +31 -12
  32. package/dist/scan/formatScanOutput.js +3 -3
  33. package/dist/scan/scanConfig.js +2 -2
  34. package/dist/utils/getConfig.js +1 -6
  35. package/package.json +2 -3
  36. package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +3 -32
  37. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +128 -68
  38. package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +11 -5
  39. package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +41 -19
  40. package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +43 -4
  41. package/src/audit/languageAnalysisEngine/sendSnapshot.js +6 -32
  42. package/src/audit/save.js +32 -16
  43. package/src/commands/audit/auditConfig.ts +0 -25
  44. package/src/commands/audit/auditController.ts +0 -11
  45. package/src/commands/audit/help.ts +7 -24
  46. package/src/commands/audit/processAudit.ts +1 -7
  47. package/src/commands/audit/saveFile.ts +2 -2
  48. package/src/commands/scan/processScan.js +0 -1
  49. package/src/commands/scan/sca/scaAnalysis.js +28 -13
  50. package/src/common/HTTPClient.js +9 -9
  51. package/src/constants/constants.js +9 -3
  52. package/src/constants/locales.js +47 -35
  53. package/src/constants.js +12 -10
  54. package/src/index.ts +76 -66
  55. package/src/lambda/lambda.ts +5 -2
  56. package/src/lambda/types.ts +1 -0
  57. package/src/sbom/generateSbom.ts +2 -2
  58. package/src/scaAnalysis/common/formatMessage.js +8 -1
  59. package/src/scaAnalysis/common/treeUpload.js +4 -5
  60. package/src/scaAnalysis/dotnet/analysis.js +54 -0
  61. package/src/scaAnalysis/dotnet/index.js +11 -0
  62. package/src/scaAnalysis/javascript/analysis.js +6 -7
  63. package/src/scaAnalysis/javascript/index.js +23 -7
  64. package/src/scaAnalysis/php/analysis.js +15 -35
  65. package/src/scaAnalysis/php/index.js +15 -4
  66. package/src/scaAnalysis/ruby/analysis.js +2 -11
  67. package/src/scan/autoDetection.js +18 -24
  68. package/src/scan/fileUtils.js +33 -12
  69. package/src/scan/formatScanOutput.ts +3 -3
  70. package/src/scan/scanConfig.js +2 -4
  71. package/src/utils/getConfig.ts +1 -12
  72. package/dist/audit/AnalysisEngine.js +0 -37
  73. package/dist/audit/autodetection/autoDetectLanguage.js +0 -32
  74. package/dist/audit/dotnetAnalysisEngine/index.js +0 -25
  75. package/dist/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -35
  76. package/dist/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -15
  77. package/dist/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -18
  78. package/dist/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -14
  79. package/dist/audit/dotnetAnalysisEngine/sanitizer.js +0 -9
  80. package/dist/audit/goAnalysisEngine/index.js +0 -17
  81. package/dist/audit/goAnalysisEngine/parseProjectFileContents.js +0 -164
  82. package/dist/audit/goAnalysisEngine/readProjectFileContents.js +0 -21
  83. package/dist/audit/goAnalysisEngine/sanitizer.js +0 -5
  84. package/dist/audit/javaAnalysisEngine/index.js +0 -34
  85. package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -155
  86. package/dist/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -353
  87. package/dist/audit/javaAnalysisEngine/readProjectFileContents.js +0 -98
  88. package/dist/audit/javaAnalysisEngine/sanitizer.js +0 -5
  89. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -25
  90. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -25
  91. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -35
  92. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -24
  93. package/dist/audit/languageAnalysisEngine/constants.js +0 -20
  94. package/dist/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -25
  95. package/dist/audit/languageAnalysisEngine/index.js +0 -39
  96. package/dist/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -66
  97. package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -166
  98. package/dist/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -40
  99. package/dist/audit/nodeAnalysisEngine/index.js +0 -31
  100. package/dist/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -18
  101. package/dist/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -18
  102. package/dist/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -17
  103. package/dist/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -14
  104. package/dist/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -24
  105. package/dist/audit/nodeAnalysisEngine/sanitizer.js +0 -9
  106. package/dist/audit/phpAnalysisEngine/index.js +0 -23
  107. package/dist/audit/phpAnalysisEngine/parseLockFileContents.js +0 -52
  108. package/dist/audit/phpAnalysisEngine/readLockFileContents.js +0 -13
  109. package/dist/audit/phpAnalysisEngine/readProjectFileContents.js +0 -16
  110. package/dist/audit/phpAnalysisEngine/sanitizer.js +0 -5
  111. package/dist/audit/pythonAnalysisEngine/index.js +0 -25
  112. package/dist/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -17
  113. package/dist/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -21
  114. package/dist/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -13
  115. package/dist/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -14
  116. package/dist/audit/pythonAnalysisEngine/sanitizer.js +0 -7
  117. package/dist/audit/rubyAnalysisEngine/index.js +0 -25
  118. package/dist/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -176
  119. package/dist/audit/rubyAnalysisEngine/parsedGemfile.js +0 -22
  120. package/dist/audit/rubyAnalysisEngine/readGemfileContents.js +0 -14
  121. package/dist/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -14
  122. package/dist/audit/rubyAnalysisEngine/sanitizer.js +0 -6
  123. package/src/audit/AnalysisEngine.js +0 -103
  124. package/src/audit/autodetection/autoDetectLanguage.ts +0 -40
  125. package/src/audit/dotnetAnalysisEngine/index.js +0 -26
  126. package/src/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -47
  127. package/src/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -29
  128. package/src/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -30
  129. package/src/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -26
  130. package/src/audit/dotnetAnalysisEngine/sanitizer.js +0 -11
  131. package/src/audit/goAnalysisEngine/index.js +0 -18
  132. package/src/audit/goAnalysisEngine/parseProjectFileContents.js +0 -209
  133. package/src/audit/goAnalysisEngine/readProjectFileContents.js +0 -31
  134. package/src/audit/goAnalysisEngine/sanitizer.js +0 -7
  135. package/src/audit/javaAnalysisEngine/index.js +0 -41
  136. package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -225
  137. package/src/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -420
  138. package/src/audit/javaAnalysisEngine/readProjectFileContents.js +0 -141
  139. package/src/audit/javaAnalysisEngine/sanitizer.js +0 -6
  140. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -36
  141. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -42
  142. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -54
  143. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -33
  144. package/src/audit/languageAnalysisEngine/constants.js +0 -23
  145. package/src/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -41
  146. package/src/audit/languageAnalysisEngine/index.js +0 -45
  147. package/src/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -96
  148. package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -251
  149. package/src/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -49
  150. package/src/audit/nodeAnalysisEngine/index.js +0 -35
  151. package/src/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -20
  152. package/src/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -26
  153. package/src/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -23
  154. package/src/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -27
  155. package/src/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -36
  156. package/src/audit/nodeAnalysisEngine/sanitizer.js +0 -11
  157. package/src/audit/phpAnalysisEngine/index.js +0 -27
  158. package/src/audit/phpAnalysisEngine/parseLockFileContents.js +0 -60
  159. package/src/audit/phpAnalysisEngine/readLockFileContents.js +0 -14
  160. package/src/audit/phpAnalysisEngine/readProjectFileContents.js +0 -25
  161. package/src/audit/phpAnalysisEngine/sanitizer.js +0 -4
  162. package/src/audit/pythonAnalysisEngine/index.js +0 -55
  163. package/src/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -23
  164. package/src/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -33
  165. package/src/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -16
  166. package/src/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -22
  167. package/src/audit/pythonAnalysisEngine/sanitizer.js +0 -9
  168. package/src/audit/rubyAnalysisEngine/index.js +0 -30
  169. package/src/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -215
  170. package/src/audit/rubyAnalysisEngine/parsedGemfile.js +0 -39
  171. package/src/audit/rubyAnalysisEngine/readGemfileContents.js +0 -18
  172. package/src/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -17
  173. package/src/audit/rubyAnalysisEngine/sanitizer.js +0 -8
@@ -1,176 +0,0 @@
1
- "use strict";
2
- const whitespaceRegx = /^(\s*)/;
3
- let index = 0;
4
- const depReg = /^\s*([A-Za-z0-9.!@#$%\-^&*_+]*)\s*(\((.*?)\))/;
5
- const i18n = require('i18n');
6
- const GEMFILE_KEY_VALUE = /^\s*([^:(]*)\s*\:*\s*(.*)/;
7
- let rubyObj = {};
8
- rubyObj.dependencies = {};
9
- module.exports = exports = ({ ruby }, next) => {
10
- const { rawLockFileContents } = ruby;
11
- let lines = rawLockFileContents.split('\n');
12
- try {
13
- ruby.gemfileLock = {};
14
- getDirectDepencies(lines, ruby.gemfileLock);
15
- getRubyVersion(lines, ruby.gemfileLock);
16
- getSourceArr(lines, ruby.gemfileLock);
17
- next();
18
- }
19
- catch (err) {
20
- next(new Error(i18n.__('rubyAnalysisEngineParsedGemLockFileError') + `${err.message}`));
21
- }
22
- };
23
- const populateSourceType = (line, rubyObj) => {
24
- return (rubyObj.sourceType = line);
25
- };
26
- const nonDependencyKeys = (line, rubyObj) => {
27
- let parts = GEMFILE_KEY_VALUE.exec(line);
28
- let key = parts[1].trim();
29
- let value = parts[2] || '';
30
- return (rubyObj[key] = value);
31
- };
32
- const populateResolveAndPlatform = (dependency, rubyObj) => {
33
- const depArr = dependency.split('-');
34
- rubyObj.resolved = depArr[0];
35
- rubyObj.platform = depArr.length > 1 ? depArr[1] : 'UNSPECIFIED';
36
- return rubyObj;
37
- };
38
- const isUpperCase = str => {
39
- return str === str.toUpperCase();
40
- };
41
- const getDirectDepencies = (lines, ruby) => {
42
- let depIndex = 0;
43
- for (let i = 0; i < lines.length; i++) {
44
- if (lines[i] == 'DEPENDENCIES') {
45
- depIndex = i;
46
- }
47
- }
48
- const getDepArray = lines.slice(depIndex);
49
- ruby.dependencies = {};
50
- for (let j = 1; j < getDepArray.length; j++) {
51
- const element = getDepArray[j];
52
- if (!isUpperCase(element)) {
53
- const isDependencyWithVersion = depReg.test(element);
54
- if (isDependencyWithVersion) {
55
- const dependency = depReg.exec(element);
56
- let name = dependency[1];
57
- name = name.replace('!', '');
58
- ruby.dependencies[name.trim()] = dependency[3];
59
- }
60
- else {
61
- let name = element;
62
- name = name.replace('!', ' ');
63
- ruby.dependencies[name.trim()] = 'UNSPECIFIED';
64
- }
65
- }
66
- else {
67
- return;
68
- }
69
- }
70
- };
71
- const getRubyVersion = (lines, ruby) => {
72
- let rubVersionIndex = 0;
73
- for (let i = 0; i < lines.length; i++) {
74
- if (lines[i] == 'RUBY VERSION') {
75
- rubVersionIndex = i;
76
- break;
77
- }
78
- }
79
- if (rubVersionIndex !== 0) {
80
- const getRubyVersionArray = lines.slice(rubVersionIndex);
81
- ruby.runtimeDetails = {};
82
- for (let j = 1; j < getRubyVersionArray.length; j++) {
83
- let element = getRubyVersionArray[j];
84
- if (!isUpperCase(element)) {
85
- element = element.trim();
86
- if (/^([ruby\s0-9.*]+)/.test(element)) {
87
- let splitElement = element.split(' ');
88
- ruby.runtimeDetails['version'] = splitElement[1];
89
- }
90
- if (/^([p0-9]+)/.test(element)) {
91
- ruby.runtimeDetails['patchLevel'] = element.substring(1);
92
- }
93
- if (element.includes('engine')) {
94
- let splitElement = element.split(' ');
95
- ruby.runtimeDetails[splitElement[0]] = splitElement[1];
96
- }
97
- }
98
- else {
99
- return;
100
- }
101
- }
102
- }
103
- };
104
- const formatSourceArr = sourceArr => {
105
- return sourceArr.map(element => {
106
- if (element.sourceType === 'GIT') {
107
- delete element.specs;
108
- }
109
- if (element.sourceType === 'GEM') {
110
- delete element.branch;
111
- delete element.revision;
112
- delete element.depthLevel;
113
- delete element.specs;
114
- }
115
- if (element.sourceType === 'PATH') {
116
- delete element.branch;
117
- delete element.revision;
118
- delete element.depthLevel;
119
- delete element.specs;
120
- delete element.platform;
121
- }
122
- return element;
123
- });
124
- };
125
- const getSourceArr = (lines, ruby) => {
126
- let line = 0;
127
- let source = [];
128
- while ((line = lines[index++]) !== undefined) {
129
- let currentWS = whitespaceRegx.exec(line)[1].length;
130
- if (!line.includes(' bundler (')) {
131
- if (currentWS === 0 && !line.includes(':') && line != '') {
132
- populateSourceType(line, rubyObj);
133
- }
134
- if (currentWS !== 0 && line.includes(':')) {
135
- nonDependencyKeys(line, rubyObj);
136
- }
137
- if (currentWS > 2) {
138
- const isDependencyWithVersion = depReg.test(line);
139
- let nexlineWS = whitespaceRegx.exec(lines[index])[1].length;
140
- if (currentWS === 6) {
141
- const dependency = depReg.exec(line);
142
- if (isDependencyWithVersion) {
143
- if (rubyObj.name !== dependency[1]) {
144
- rubyObj.dependencies[dependency[1]] = dependency[3];
145
- }
146
- }
147
- else {
148
- rubyObj.dependencies[line.trim()] = 'UNSPECIFIED';
149
- }
150
- }
151
- if (currentWS === 4 && rubyObj.depthLevel === undefined) {
152
- const dependency = depReg.exec(line);
153
- rubyObj.name = dependency[1];
154
- rubyObj.depthLevel = currentWS;
155
- populateResolveAndPlatform(dependency[3], rubyObj);
156
- }
157
- if (currentWS === 4 && rubyObj.depthLevel) {
158
- const dependency = depReg.exec(line);
159
- rubyObj.name = dependency[1];
160
- rubyObj.depthLevel = currentWS;
161
- populateResolveAndPlatform(dependency[3], rubyObj);
162
- }
163
- if ((currentWS === 4 && nexlineWS === 4) ||
164
- (currentWS === 6 && nexlineWS === 4) ||
165
- nexlineWS == '') {
166
- let newObj = {};
167
- newObj = JSON.parse(JSON.stringify(rubyObj));
168
- source.push(newObj);
169
- rubyObj.dependencies = {};
170
- }
171
- }
172
- }
173
- }
174
- ruby.sources = formatSourceArr(source);
175
- };
176
- exports.getSourceArr = getSourceArr;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- const i18n = require('i18n');
3
- module.exports = exports = ({ ruby }, next) => {
4
- const { rawProjectFileContents } = ruby;
5
- try {
6
- const rubyArray = rawProjectFileContents.split('\n');
7
- let filteredRubyDep = rubyArray.filter(element => {
8
- return (!element.includes('#') &&
9
- element.includes('gem') &&
10
- !element.includes('source'));
11
- });
12
- for (let i = 0; i < filteredRubyDep.length; i++) {
13
- filteredRubyDep[i] = filteredRubyDep[i].trim();
14
- }
15
- ruby.gemfilesDependanceies = filteredRubyDep;
16
- next();
17
- }
18
- catch (err) {
19
- next(new Error(i18n.__('rubyAnalysisEngineParsedGemFileError', rawProjectFileContents) + `${err.message}`));
20
- return;
21
- }
22
- };
@@ -1,14 +0,0 @@
1
- "use strict";
2
- const fs = require('fs');
3
- const i18n = require('i18n');
4
- module.exports = exports = ({ language: { projectFilePath }, ruby }, next) => {
5
- try {
6
- ruby.rawProjectFileContents = fs.readFileSync(projectFilePath, 'utf8');
7
- next();
8
- }
9
- catch (err) {
10
- next(new Error(i18n.__('rubyAnalysisEngineReadGemFileError', projectFilePath) +
11
- `${err.message}`));
12
- return;
13
- }
14
- };
@@ -1,14 +0,0 @@
1
- "use strict";
2
- const fs = require('fs');
3
- const i18n = require('i18n');
4
- module.exports = exports = ({ language: { lockFilePath }, ruby }, next) => {
5
- try {
6
- ruby.rawLockFileContents = fs.readFileSync(lockFilePath, 'utf8');
7
- next();
8
- }
9
- catch (err) {
10
- next(new Error(i18n.__('rubyAnalysisEngineReadGemLockFileError', lockFilePath) +
11
- `${err.message}`));
12
- return;
13
- }
14
- };
@@ -1,6 +0,0 @@
1
- "use strict";
2
- module.exports = exports = ({ ruby }, next) => {
3
- delete ruby.rawProjectFileContents;
4
- delete ruby.rawLockFileContents;
5
- next();
6
- };
@@ -1,103 +0,0 @@
1
- /**
2
- * The 'AnalysisEngine' type represents a simple state machine that can be used
3
- * to move through a list of steps sequentially to analyze a project. Consumers
4
- * construct their own steps and add them to the state machine in their desired
5
- * order. Upon completion the state machine can callback to the consumer that
6
- * originally invoked them with the results of the analysis.
7
- */
8
- class AnalysisEngine {
9
- /**
10
- * Constructor that creates a new state machine instance. Accepts an optional
11
- * argument that initializes the internal state.
12
- *
13
- * @param {Object} initAnalysis - state used to initialize internal state
14
- *
15
- * @example
16
- * const ae = new AnalysisEngine()
17
- * const ae = new AnalysisEngine({ someInfo: [1, 2, 3] })
18
- */
19
- constructor(initAnalysis = {}) {
20
- this.analyzers = []
21
- this.analysis = { ...initAnalysis }
22
- }
23
-
24
- /**
25
- * Takes either a function or a list of functions and adds them in sequential
26
- * order to a list. The list will be executed at a later time as the steps of
27
- * the state machine.
28
- *
29
- * Functions must follow the signature (analysis, next) where:
30
- * 'analysis' is an object that represents the current internal state
31
- * 'next' is a function to be invoked when the step is complete
32
- *
33
- * The function signature of 'next' is (err) where:
34
- * 'err' is an Error that occurred during the previous step invoked
35
- *
36
- * @param {function(analysis: object, next: function)|function[]} analyzer -
37
- * the analyzer(s) to be added to the list of steps in sequential order
38
- *
39
- * @example
40
- * const myAnalyzer = (analysis, next) => {
41
- * // Perform business logic
42
- * // Add results to 'analysis'
43
- * analysis.result = ...
44
- *
45
- * // Signal the next analyzer/step to be invoked
46
- * next()
47
- * }
48
- *
49
- * ae.use(myAnalyzer)
50
- */
51
- use(analyzer) {
52
- if (Array.isArray(analyzer)) {
53
- this.analyzers = [...this.analyzers, ...analyzer]
54
- return
55
- }
56
-
57
- this.analyzers.push(analyzer)
58
- }
59
-
60
- /**
61
- * Starts the execution of the state machine given the steps it is to use.
62
- * When complete it callbacks back to the consumer that invoked it. The
63
- * callbacks signature is (err, analysis) where:
64
- * 'err' is an Error from one of the steps that prevented completion
65
- * 'analysis' is the final internal state
66
- *
67
- * @param {function(err: Error, analysis: object)} callback - callback to be
68
- * invoked when state machine complete or fails prematurely
69
- * @param config:object containing config - needed for Java analysis - optional for other languages
70
- */
71
- analyze(callback, config) {
72
- let i = 0
73
-
74
- const next = err => {
75
- // If one of the analyzers encountered an error then callback
76
- if (err) {
77
- return setImmediate(() => callback(err, this.analysis))
78
- }
79
-
80
- // If there are no more analyzers to invoke then callback
81
- if (i >= this.analyzers.length) {
82
- return setImmediate(() => callback(null, this.analysis))
83
- }
84
-
85
- // Invoke the next analyzer
86
- const analyzer = this.analyzers[i]
87
- i++
88
-
89
- setImmediate(() => {
90
- // Protect ourselves from any uncaught errors thrown by analyzers
91
- try {
92
- analyzer(this.analysis, next, config)
93
- } catch (uncaughtErr) {
94
- next(uncaughtErr)
95
- }
96
- })
97
- }
98
-
99
- next()
100
- }
101
- }
102
-
103
- module.exports = exports = AnalysisEngine
@@ -1,40 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import i18n from 'i18n'
3
- import {
4
- reduceIdentifiedLanguages,
5
- deduceLanguage
6
- } from '../languageAnalysisEngine/reduceIdentifiedLanguages'
7
-
8
- import { getProjectRootFilenames } from '../languageAnalysisEngine/getProjectRootFilenames'
9
-
10
- export function identifyLanguages(config: any) {
11
- const { file } = config
12
- const projectRootFilenames = getProjectRootFilenames(file)
13
-
14
- const identifiedLanguages = projectRootFilenames.reduce(
15
- (accumulator: any, filename: string) => {
16
- const deducedLanguages = deduceLanguage(filename)
17
- return [...accumulator, ...deducedLanguages]
18
- },
19
- []
20
- )
21
-
22
- if (Object.keys(identifiedLanguages).length === 0) {
23
- throw new Error(i18n.__('languageAnalysisNoLanguage', file))
24
- }
25
-
26
- return reduceIdentifiedLanguages(identifiedLanguages)
27
- }
28
-
29
- export function determineProjectLanguage(
30
- reducedLanguages: Record<string, string>
31
- ) {
32
- const reducedLanguagesKeys = Object.keys(reducedLanguages)
33
- if (reducedLanguagesKeys.length === 1) {
34
- return reducedLanguagesKeys[0]
35
- } else {
36
- throw new Error(
37
- 'Detected multiple languages. Please specify a single language using --language'
38
- )
39
- }
40
- }
@@ -1,26 +0,0 @@
1
- const AnalysisEngine = require('../AnalysisEngine')
2
- const readProjectFileContents = require('./readProjectFileContents')
3
- const parseProjectFileContents = require('./parseProjectFileContents')
4
- const readLockFileContents = require('./readLockFileContents')
5
- const parseLockFileContents = require('./parseLockFileContents')
6
- const sanitizer = require('./sanitizer')
7
- const i18n = require('i18n')
8
-
9
- module.exports = exports = (language, config, callback) => {
10
- const ae = new AnalysisEngine({ language, config, dotnet: {} })
11
- ae.use([
12
- readProjectFileContents,
13
- parseProjectFileContents,
14
- readLockFileContents,
15
- parseLockFileContents,
16
- sanitizer
17
- ])
18
-
19
- ae.analyze((err, analysis) => {
20
- if (err) {
21
- callback(new Error(i18n.__('dotnetAnalysisFailure') + err.message))
22
- return
23
- }
24
- callback(null, analysis)
25
- })
26
- }
@@ -1,47 +0,0 @@
1
- const i18n = require('i18n')
2
-
3
- module.exports = exports = ({ language: { lockFilePath }, dotnet }, next) => {
4
- const { rawLockFileContents } = dotnet
5
-
6
- // If we never read the lock file then pass priority
7
- if (!rawLockFileContents) {
8
- next()
9
-
10
- return
11
- }
12
-
13
- try {
14
- let count = 0 // Used to test if some nodes are deleted
15
- dotnet.lockFile = JSON.parse(rawLockFileContents)
16
-
17
- for (const dependenciesNode in dotnet.lockFile.dependencies) {
18
- for (const innerNode in dotnet.lockFile.dependencies[dependenciesNode]) {
19
- const nodeValidation = JSON.stringify(
20
- dotnet.lockFile.dependencies[dependenciesNode][innerNode]
21
- )
22
- if (nodeValidation.includes('"type":"Project"')) {
23
- count += 1
24
- delete dotnet.lockFile.dependencies[dependenciesNode][innerNode]
25
- dotnet.additionalInfo = 'dependenciesNote'
26
- }
27
- }
28
- }
29
-
30
- // If dependencies removed wait for json to be displayed and flag warning
31
- if (count > 0) {
32
- const multiLevelProjectWarning = () => {
33
- console.log('')
34
- console.log(i18n.__('dependenciesNote'))
35
- }
36
- setTimeout(multiLevelProjectWarning, 7000)
37
- }
38
- } catch (err) {
39
- next(
40
- new Error(i18n.__('dotnetParseLockfile', lockFilePath) + `${err.message}`)
41
- )
42
-
43
- return
44
- }
45
-
46
- next()
47
- }
@@ -1,29 +0,0 @@
1
- const xml2js = require('xml2js')
2
- const i18n = require('i18n')
3
-
4
- module.exports = exports = (
5
- { language: { projectFilePath }, dotnet },
6
- next
7
- ) => {
8
- const { rawProjectFileContents } = dotnet
9
-
10
- // Read the .NET project file contents. We are reading into memory presuming
11
- // that the contents of the file aren't large which may be bad... Could look
12
- // into streaming in the future
13
- // explicitArray: false - to not abuse of arrays, with this option we are able to read JSON properties in an easier way
14
- // mergeAttrs: true - to merge attributes and child elements as properties of the parent
15
- const parser = new xml2js.Parser({ explicitArray: false, mergeAttrs: true })
16
- parser.parseString(rawProjectFileContents, (err, projectFileXML) => {
17
- if (err) {
18
- next(
19
- new Error(i18n.__('dotnetParseProjectFile', projectFilePath) + `${err}`)
20
- )
21
-
22
- return
23
- }
24
-
25
- dotnet.projectFile = projectFileXML
26
-
27
- next()
28
- })
29
- }
@@ -1,30 +0,0 @@
1
- const fs = require('fs')
2
- const i18n = require('i18n')
3
-
4
- module.exports = exports = (analysis, next) => {
5
- const {
6
- language: { lockFilePath },
7
- dotnet
8
- } = analysis
9
-
10
- // Make sure to check to see if there was a lock file detected as its not
11
- // required
12
- if (!lockFilePath) {
13
- next()
14
- return
15
- }
16
-
17
- // we're working on the assumtion that a dotNet project will only ever have one lock file
18
- //while other language may have more
19
- try {
20
- dotnet.rawLockFileContents = fs.readFileSync(lockFilePath)
21
- } catch (err) {
22
- next(
23
- new Error(i18n.__('dotnetReadLockfile', lockFilePath) + `${err.message}`)
24
- )
25
-
26
- return
27
- }
28
-
29
- next()
30
- }
@@ -1,26 +0,0 @@
1
- const fs = require('fs')
2
- const i18n = require('i18n')
3
-
4
- module.exports = exports = (analysis, next) => {
5
- const {
6
- language: { projectFilePath },
7
- dotnet
8
- } = analysis
9
-
10
- // Read the .NET project file contents. We are reading into memory presuming
11
- // that the contents of the file aren't large which may be bad... Could look
12
- // into streaming in the future
13
- try {
14
- dotnet.rawProjectFileContents = fs.readFileSync(projectFilePath)
15
- } catch (err) {
16
- next(
17
- new Error(
18
- i18n.__('dotnetReadProjectFile', projectFilePath) + `${err.message}`
19
- )
20
- )
21
-
22
- return
23
- }
24
-
25
- next()
26
- }
@@ -1,11 +0,0 @@
1
- module.exports = exports = ({ dotnet }, next) => {
2
- // Remove anything sensitive or unnecessary from being sent to the backend as
3
- // a result of our .NET project analysis
4
- delete dotnet.rawProjectFileContents
5
- delete dotnet.parsedProjectFileContents
6
- delete dotnet.projectFileXML
7
- delete dotnet.packageReferences
8
- delete dotnet.rawLockFileContents
9
-
10
- next()
11
- }
@@ -1,18 +0,0 @@
1
- const AnalysisEngine = require('../AnalysisEngine')
2
- const readProjectFileContents = require('./readProjectFileContents')
3
- const parseProjectFileContents = require('./parseProjectFileContents')
4
- const sanitizer = require('./sanitizer')
5
- const i18n = require('i18n')
6
-
7
- module.exports = exports = (language, config, callback) => {
8
- const ae = new AnalysisEngine({ language, config, go: {} })
9
- ae.use([readProjectFileContents, parseProjectFileContents, sanitizer])
10
-
11
- ae.analyze((err, analysis) => {
12
- if (err) {
13
- callback(new Error(i18n.__('goAnalysisError') + `${err.message}`))
14
- return
15
- }
16
- callback(null, analysis)
17
- })
18
- }