@appland/scanner 1.55.0 → 1.58.0

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 (244) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/built/algorithms/dataStructures/graph/Graph.js +53 -62
  3. package/built/algorithms/dataStructures/graph/GraphEdge.js +13 -16
  4. package/built/algorithms/dataStructures/graph/GraphVertex.js +37 -42
  5. package/built/algorithms/dataStructures/linked-list/LinkedList.js +33 -38
  6. package/built/algorithms/dataStructures/linked-list/LinkedListNode.js +6 -10
  7. package/built/algorithms/graph/depth-first-search/index.js +7 -8
  8. package/built/algorithms/graph/detect-cycle/index.js +15 -16
  9. package/built/algorithms/utils/Comparator.js +19 -21
  10. package/built/analyzer/recordSecrets.js +7 -30
  11. package/built/analyzer/secretsRegexes.js +8 -9
  12. package/built/appMapIndex.js +19 -21
  13. package/built/check.js +17 -21
  14. package/built/checkInstance.js +26 -48
  15. package/built/cli/ci/command.js +61 -156
  16. package/built/cli/ci/options.js +0 -1
  17. package/built/cli/codeVersionArgs.js +0 -1
  18. package/built/cli/exitCode.js +0 -1
  19. package/built/cli/fail.js +2 -3
  20. package/built/cli/merge/command.js +21 -63
  21. package/built/cli/merge/options.js +0 -1
  22. package/built/cli/reportUploadURL.js +2 -3
  23. package/built/cli/resolveAppId.js +34 -85
  24. package/built/cli/scan/command.js +57 -242
  25. package/built/cli/scan/formatReport.js +44 -0
  26. package/built/cli/scan/options.js +0 -1
  27. package/built/cli/scan/scanner.js +38 -117
  28. package/built/cli/scan/singleScan.js +80 -0
  29. package/built/cli/scan/watchScan.js +102 -0
  30. package/built/cli/scan.js +39 -132
  31. package/built/cli/scanArgs.js +0 -1
  32. package/built/cli/scanOptions.js +0 -1
  33. package/built/cli/updateCommitStatus.js +10 -47
  34. package/built/cli/upload/command.js +20 -64
  35. package/built/cli/upload/options.js +0 -1
  36. package/built/cli/upload/pruneAppMap.js +16 -0
  37. package/built/cli/upload.js +91 -172
  38. package/built/cli/validateFile.js +13 -48
  39. package/built/cli.js +34 -21
  40. package/built/configuration/configurationProvider.js +151 -233
  41. package/built/configuration/schema/options.json +76 -76
  42. package/built/configuration/types/checkConfig.js +0 -1
  43. package/built/configuration/types/configuration.js +0 -1
  44. package/built/configuration/types/matchEventConfig.js +0 -1
  45. package/built/configuration/types/matchPatternConfig.js +0 -1
  46. package/built/database/index.js +35 -128
  47. package/built/database/visit.js +20 -68
  48. package/built/errors.js +4 -30
  49. package/built/eventUtil.js +10 -35
  50. package/built/findings.js +3 -4
  51. package/built/integration/appland/app/exists.js +33 -76
  52. package/built/integration/appland/app/listFindingStatus.js +5 -38
  53. package/built/integration/appland/appMap/create.js +38 -89
  54. package/built/integration/appland/location.js +0 -1
  55. package/built/integration/appland/mapset/create.js +34 -85
  56. package/built/integration/appland/retry.js +10 -11
  57. package/built/integration/appland/retryOptions.js +0 -1
  58. package/built/integration/appland/scannerJob/create.js +34 -84
  59. package/built/integration/appland/scannerJob/merge.js +28 -74
  60. package/built/integration/appland/scannerJob.js +0 -1
  61. package/built/integration/github/commitStatus.js +3 -4
  62. package/built/integration/vars.js +1 -2
  63. package/built/openapi/index.js +39 -83
  64. package/built/report/appMapMetadata.js +0 -1
  65. package/built/report/findingSummary.js +0 -1
  66. package/built/report/findingsReport.js +14 -16
  67. package/built/report/scanResults.js +50 -72
  68. package/built/report/scanSummary.js +0 -1
  69. package/built/report/summaryReport.js +12 -13
  70. package/built/ruleChecker.js +146 -297
  71. package/built/rules/authzBeforeAuthn.js +25 -59
  72. package/built/rules/circularDependency.js +69 -101
  73. package/built/rules/deserializationOfUntrustedData.js +29 -63
  74. package/built/rules/execOfUntrustedCommand.js +28 -62
  75. package/built/rules/http-500/metadata.js +0 -1
  76. package/built/rules/http-500/rule.js +2 -3
  77. package/built/rules/illegalPackageDependency.js +16 -18
  78. package/built/rules/incompatibleHttpClientRequest.js +30 -69
  79. package/built/rules/insecureCompare.js +12 -13
  80. package/built/rules/jobNotCancelled.js +13 -45
  81. package/built/rules/lib/hasParameterOrReceiver.js +4 -7
  82. package/built/rules/lib/matchEvent.js +12 -13
  83. package/built/rules/lib/matchPattern.js +6 -7
  84. package/built/rules/lib/metadata.js +0 -1
  85. package/built/rules/lib/parseRuleDescription.js +5 -6
  86. package/built/rules/lib/precedingEvents.js +7 -75
  87. package/built/rules/lib/rpcWithoutProtection.js +5 -28
  88. package/built/rules/lib/sanitizesData.js +0 -1
  89. package/built/rules/lib/util.js +34 -73
  90. package/built/rules/logoutWithoutSessionReset.js +24 -58
  91. package/built/rules/missingAuthentication.js +28 -28
  92. package/built/rules/missingContentType.js +8 -9
  93. package/built/rules/nPlusOneQuery.js +35 -87
  94. package/built/rules/queryFromInvalidPackage.js +17 -19
  95. package/built/rules/queryFromView.js +13 -16
  96. package/built/rules/rpcWithoutCircuitBreaker.js +14 -84
  97. package/built/rules/saveWithoutValidation.js +8 -9
  98. package/built/rules/secretInLog.js +30 -93
  99. package/built/rules/slowFunctionCall.js +16 -20
  100. package/built/rules/slowHttpServerRequest.js +9 -11
  101. package/built/rules/slowQuery.js +9 -12
  102. package/built/rules/tooManyJoins.js +26 -51
  103. package/built/rules/tooManyUpdates.js +25 -105
  104. package/built/rules/unbatchedMaterializedQuery.js +26 -30
  105. package/built/rules/updateInGetRequest.js +30 -45
  106. package/built/scope/commandScope.js +24 -144
  107. package/built/scope/httpClientRequestScope.js +11 -98
  108. package/built/scope/httpServerRequestScope.js +11 -98
  109. package/built/scope/rootScope.js +11 -98
  110. package/built/scope/scopeImpl.js +10 -82
  111. package/built/scope/scopeIterator.js +6 -10
  112. package/built/scope/sqlTransactionScope.js +24 -122
  113. package/built/sqlWarning.js +9 -35
  114. package/built/telemetry.js +215 -0
  115. package/built/wellKnownLabels.js +0 -1
  116. package/package.json +10 -3
  117. package/built/algorithms/dataStructures/graph/Graph.js.map +0 -1
  118. package/built/algorithms/dataStructures/graph/GraphEdge.js.map +0 -1
  119. package/built/algorithms/dataStructures/graph/GraphVertex.js.map +0 -1
  120. package/built/algorithms/dataStructures/linked-list/LinkedList.js.map +0 -1
  121. package/built/algorithms/dataStructures/linked-list/LinkedListNode.js.map +0 -1
  122. package/built/algorithms/graph/depth-first-search/index.js.map +0 -1
  123. package/built/algorithms/graph/detect-cycle/index.js.map +0 -1
  124. package/built/algorithms/utils/Comparator.js.map +0 -1
  125. package/built/analyzer/recordSecrets.js.map +0 -1
  126. package/built/analyzer/secretsRegexes.js.map +0 -1
  127. package/built/appMapIndex.js.map +0 -1
  128. package/built/check.js.map +0 -1
  129. package/built/checkInstance.js.map +0 -1
  130. package/built/cli/ci/command.js.map +0 -1
  131. package/built/cli/ci/options.js.map +0 -1
  132. package/built/cli/codeVersionArgs.js.map +0 -1
  133. package/built/cli/exitCode.js.map +0 -1
  134. package/built/cli/fail.js.map +0 -1
  135. package/built/cli/merge/command.js.map +0 -1
  136. package/built/cli/merge/options.js.map +0 -1
  137. package/built/cli/reportUploadURL.js.map +0 -1
  138. package/built/cli/resolveAppId.js.map +0 -1
  139. package/built/cli/scan/command.js.map +0 -1
  140. package/built/cli/scan/options.js.map +0 -1
  141. package/built/cli/scan/scanner.js.map +0 -1
  142. package/built/cli/scan.js.map +0 -1
  143. package/built/cli/scanArgs.js.map +0 -1
  144. package/built/cli/scanOptions.js.map +0 -1
  145. package/built/cli/updateCommitStatus.js.map +0 -1
  146. package/built/cli/upload/command.js.map +0 -1
  147. package/built/cli/upload/options.js.map +0 -1
  148. package/built/cli/upload.js.map +0 -1
  149. package/built/cli/validateFile.js.map +0 -1
  150. package/built/cli.js.map +0 -1
  151. package/built/configuration/configurationProvider.js.map +0 -1
  152. package/built/configuration/types/checkConfig.js.map +0 -1
  153. package/built/configuration/types/configuration.js.map +0 -1
  154. package/built/configuration/types/matchEventConfig.js.map +0 -1
  155. package/built/configuration/types/matchPatternConfig.js.map +0 -1
  156. package/built/database/index.js.map +0 -1
  157. package/built/database/visit.js.map +0 -1
  158. package/built/errors.js.map +0 -1
  159. package/built/eventUtil.js.map +0 -1
  160. package/built/findings.js.map +0 -1
  161. package/built/integration/appland/app/exists.js.map +0 -1
  162. package/built/integration/appland/app/listFindingStatus.js.map +0 -1
  163. package/built/integration/appland/appMap/create.js.map +0 -1
  164. package/built/integration/appland/location.js.map +0 -1
  165. package/built/integration/appland/mapset/create.js.map +0 -1
  166. package/built/integration/appland/retry.js.map +0 -1
  167. package/built/integration/appland/retryOptions.js.map +0 -1
  168. package/built/integration/appland/scannerJob/create.js.map +0 -1
  169. package/built/integration/appland/scannerJob/merge.js.map +0 -1
  170. package/built/integration/appland/scannerJob.js.map +0 -1
  171. package/built/integration/github/commitStatus.js.map +0 -1
  172. package/built/integration/vars.js.map +0 -1
  173. package/built/openapi/index.js.map +0 -1
  174. package/built/openapi/method.js +0 -120
  175. package/built/openapi/method.js.map +0 -1
  176. package/built/openapi/model.js +0 -49
  177. package/built/openapi/model.js.map +0 -1
  178. package/built/openapi/path.js +0 -36
  179. package/built/openapi/path.js.map +0 -1
  180. package/built/openapi/provider.js +0 -133
  181. package/built/openapi/provider.js.map +0 -1
  182. package/built/openapi/response.js +0 -59
  183. package/built/openapi/response.js.map +0 -1
  184. package/built/openapi/rpcRequest.js +0 -130
  185. package/built/openapi/rpcRequest.js.map +0 -1
  186. package/built/openapi/schema.js +0 -42
  187. package/built/openapi/schema.js.map +0 -1
  188. package/built/openapi/securitySchemes.js +0 -32
  189. package/built/openapi/securitySchemes.js.map +0 -1
  190. package/built/openapi/statusCodes.js +0 -68
  191. package/built/openapi/statusCodes.js.map +0 -1
  192. package/built/openapi/util.js +0 -91
  193. package/built/openapi/util.js.map +0 -1
  194. package/built/report/appMapMetadata.js.map +0 -1
  195. package/built/report/findingSummary.js.map +0 -1
  196. package/built/report/findingsReport.js.map +0 -1
  197. package/built/report/scanResults.js.map +0 -1
  198. package/built/report/scanSummary.js.map +0 -1
  199. package/built/report/summaryReport.js.map +0 -1
  200. package/built/ruleChecker.js.map +0 -1
  201. package/built/rules/authzBeforeAuthn.js.map +0 -1
  202. package/built/rules/circularDependency.js.map +0 -1
  203. package/built/rules/deserializationOfUntrustedData.js.map +0 -1
  204. package/built/rules/execOfUntrustedCommand.js.map +0 -1
  205. package/built/rules/http-500/metadata.js.map +0 -1
  206. package/built/rules/http-500/rule.js.map +0 -1
  207. package/built/rules/illegalPackageDependency.js.map +0 -1
  208. package/built/rules/incompatibleHttpClientRequest.js.map +0 -1
  209. package/built/rules/insecureCompare.js.map +0 -1
  210. package/built/rules/jobNotCancelled.js.map +0 -1
  211. package/built/rules/lib/hasParameterOrReceiver.js.map +0 -1
  212. package/built/rules/lib/matchEvent.js.map +0 -1
  213. package/built/rules/lib/matchPattern.js.map +0 -1
  214. package/built/rules/lib/metadata.js.map +0 -1
  215. package/built/rules/lib/parseRuleDescription.js.map +0 -1
  216. package/built/rules/lib/precedingEvents.js.map +0 -1
  217. package/built/rules/lib/rpcWithoutProtection.js.map +0 -1
  218. package/built/rules/lib/sanitizesData.js.map +0 -1
  219. package/built/rules/lib/util.js.map +0 -1
  220. package/built/rules/logoutWithoutSessionReset.js.map +0 -1
  221. package/built/rules/missingAuthentication.js.map +0 -1
  222. package/built/rules/missingContentType.js.map +0 -1
  223. package/built/rules/nPlusOneQuery.js.map +0 -1
  224. package/built/rules/queryFromInvalidPackage.js.map +0 -1
  225. package/built/rules/queryFromView.js.map +0 -1
  226. package/built/rules/rpcWithoutCircuitBreaker.js.map +0 -1
  227. package/built/rules/saveWithoutValidation.js.map +0 -1
  228. package/built/rules/secretInLog.js.map +0 -1
  229. package/built/rules/slowFunctionCall.js.map +0 -1
  230. package/built/rules/slowHttpServerRequest.js.map +0 -1
  231. package/built/rules/slowQuery.js.map +0 -1
  232. package/built/rules/tooManyJoins.js.map +0 -1
  233. package/built/rules/tooManyUpdates.js.map +0 -1
  234. package/built/rules/unbatchedMaterializedQuery.js.map +0 -1
  235. package/built/rules/updateInGetRequest.js.map +0 -1
  236. package/built/scope/commandScope.js.map +0 -1
  237. package/built/scope/httpClientRequestScope.js.map +0 -1
  238. package/built/scope/httpServerRequestScope.js.map +0 -1
  239. package/built/scope/rootScope.js.map +0 -1
  240. package/built/scope/scopeImpl.js.map +0 -1
  241. package/built/scope/scopeIterator.js.map +0 -1
  242. package/built/scope/sqlTransactionScope.js.map +0 -1
  243. package/built/sqlWarning.js.map +0 -1
  244. package/built/wellKnownLabels.js.map +0 -1
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -23,122 +8,58 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
24
9
  });
25
10
  };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
54
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
55
13
  };
56
14
  Object.defineProperty(exports, "__esModule", { value: true });
57
- var src_1 = require("@appland/client/dist/src");
58
- var configurationProvider_1 = require("../../configuration/configurationProvider");
59
- var listFindingStatus_1 = __importDefault(require("../../integration/appland/app/listFindingStatus"));
60
- var resolveAppId_1 = __importDefault(require("../resolveAppId"));
61
- var scan_1 = __importDefault(require("../scan"));
62
- var scanResults_1 = require("../../report/scanResults");
15
+ const src_1 = require("@appland/client/dist/src");
16
+ const configurationProvider_1 = require("../../configuration/configurationProvider");
17
+ const listFindingStatus_1 = __importDefault(require("../../integration/appland/app/listFindingStatus"));
18
+ const resolveAppId_1 = __importDefault(require("../resolveAppId"));
19
+ const scan_1 = __importDefault(require("../scan"));
20
+ const scanResults_1 = require("../../report/scanResults");
63
21
  function scanner(reportAllFindings, configuration, files) {
64
- return __awaiter(this, void 0, void 0, function () {
65
- return __generator(this, function (_a) {
66
- switch (_a.label) {
67
- case 0:
68
- if (!reportAllFindings) return [3 /*break*/, 1];
69
- return [2 /*return*/, new StandaloneScanner(configuration, files)];
70
- case 1: return [4 /*yield*/, (0, src_1.loadConfiguration)()];
71
- case 2:
72
- _a.sent();
73
- return [2 /*return*/, new ServerIntegratedScanner(configuration, files)];
74
- }
75
- });
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ if (reportAllFindings) {
24
+ return new StandaloneScanner(configuration, files);
25
+ }
26
+ else {
27
+ yield (0, src_1.loadConfiguration)();
28
+ return new ServerIntegratedScanner(configuration, files);
29
+ }
76
30
  });
77
31
  }
78
32
  exports.default = scanner;
79
- var ScannerBase = /** @class */ (function () {
80
- function ScannerBase(configuration, files) {
33
+ class ScannerBase {
34
+ constructor(configuration, files) {
81
35
  this.configuration = configuration;
82
36
  this.files = files;
83
37
  }
84
- ScannerBase.prototype.scan = function () {
85
- return __awaiter(this, void 0, void 0, function () {
86
- var checks, _a, appMapMetadata, findings;
87
- return __generator(this, function (_b) {
88
- switch (_b.label) {
89
- case 0: return [4 /*yield*/, (0, configurationProvider_1.loadConfig)(this.configuration)];
90
- case 1:
91
- checks = _b.sent();
92
- return [4 /*yield*/, (0, scan_1.default)(this.files, checks)];
93
- case 2:
94
- _a = _b.sent(), appMapMetadata = _a.appMapMetadata, findings = _a.findings;
95
- return [2 /*return*/, new scanResults_1.ScanResults(this.configuration, appMapMetadata, findings, checks)];
96
- }
97
- });
38
+ scan() {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const checks = yield (0, configurationProvider_1.loadConfig)(this.configuration);
41
+ const { appMapMetadata, findings } = yield (0, scan_1.default)(this.files, checks);
42
+ return new scanResults_1.ScanResults(this.configuration, appMapMetadata, findings, checks);
98
43
  });
99
- };
100
- return ScannerBase;
101
- }());
102
- var ServerIntegratedScanner = /** @class */ (function (_super) {
103
- __extends(ServerIntegratedScanner, _super);
104
- function ServerIntegratedScanner() {
105
- return _super !== null && _super.apply(this, arguments) || this;
106
44
  }
107
- ServerIntegratedScanner.prototype.fetchFindingStatus = function (appIdArg, appMapDir) {
108
- return __awaiter(this, void 0, void 0, function () {
109
- var appId;
110
- return __generator(this, function (_a) {
111
- switch (_a.label) {
112
- case 0: return [4 /*yield*/, (0, resolveAppId_1.default)(appIdArg, appMapDir)];
113
- case 1:
114
- appId = _a.sent();
115
- return [4 /*yield*/, (0, listFindingStatus_1.default)(appId)];
116
- case 2: return [2 /*return*/, _a.sent()];
117
- }
118
- });
45
+ }
46
+ class ServerIntegratedScanner extends ScannerBase {
47
+ fetchFindingStatus(appIdArg, appMapDir) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const appId = yield (0, resolveAppId_1.default)(appIdArg, appMapDir);
50
+ return yield (0, listFindingStatus_1.default)(appId);
119
51
  });
120
- };
121
- return ServerIntegratedScanner;
122
- }(ScannerBase));
123
- var StandaloneScanner = /** @class */ (function (_super) {
124
- __extends(StandaloneScanner, _super);
125
- function StandaloneScanner() {
126
- return _super !== null && _super.apply(this, arguments) || this;
127
52
  }
128
- StandaloneScanner.prototype.verifyServerConfiguration = function () {
129
- return __awaiter(this, void 0, void 0, function () {
130
- return __generator(this, function (_a) {
131
- return [2 /*return*/, true];
132
- });
53
+ }
54
+ class StandaloneScanner extends ScannerBase {
55
+ verifyServerConfiguration() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ return true;
133
58
  });
134
- };
135
- StandaloneScanner.prototype.fetchFindingStatus = function () {
136
- return __awaiter(this, void 0, void 0, function () {
137
- return __generator(this, function (_a) {
138
- return [2 /*return*/, []];
139
- });
59
+ }
60
+ fetchFindingStatus() {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ return [];
140
63
  });
141
- };
142
- return StandaloneScanner;
143
- }(ScannerBase));
144
- //# sourceMappingURL=scanner.js.map
64
+ }
65
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const util_1 = require("util");
16
+ const promises_1 = require("fs/promises");
17
+ const glob_1 = require("glob");
18
+ const validateFile_1 = __importDefault(require("../validateFile"));
19
+ const scanner_1 = __importDefault(require("./scanner"));
20
+ const errors_1 = require("../../errors");
21
+ const findings_1 = require("../../findings");
22
+ const findingsReport_1 = __importDefault(require("../../report/findingsReport"));
23
+ const summaryReport_1 = __importDefault(require("../../report/summaryReport"));
24
+ const formatReport_1 = require("./formatReport");
25
+ const telemetry_1 = __importDefault(require("../../telemetry"));
26
+ function singleScan(options) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const { appmapFile, appmapDir, configData, reportAllFindings, appId, ide, reportFile } = options;
29
+ let files = [];
30
+ if (appmapDir) {
31
+ const glob = (0, util_1.promisify)(glob_1.glob);
32
+ files = yield glob(`${appmapDir}/**/*.appmap.json`);
33
+ }
34
+ if (appmapFile) {
35
+ files = typeof appmapFile === 'string' ? [appmapFile] : appmapFile;
36
+ yield Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () { return (0, validateFile_1.default)('file', file); })));
37
+ }
38
+ const scanner = yield (0, scanner_1.default)(reportAllFindings, configData, files).catch((error) => {
39
+ throw new errors_1.ValidationError(error.message + '\nUse --all to perform an offline scan.');
40
+ });
41
+ const startTime = Date.now();
42
+ const [rawScanResults, findingStatuses] = yield Promise.all([
43
+ scanner.scan(),
44
+ scanner.fetchFindingStatus(appId, appmapDir),
45
+ ]);
46
+ // Always report the raw data
47
+ yield (0, promises_1.writeFile)(reportFile, (0, formatReport_1.formatReport)(rawScanResults));
48
+ let scanResults;
49
+ if (reportAllFindings) {
50
+ scanResults = rawScanResults;
51
+ }
52
+ else {
53
+ scanResults = rawScanResults.withFindings((0, findings_1.newFindings)(rawScanResults.findings, findingStatuses));
54
+ }
55
+ (0, findingsReport_1.default)(scanResults.findings, scanResults.appMapMetadata, ide);
56
+ console.log();
57
+ (0, summaryReport_1.default)(scanResults, true);
58
+ console.log('\n');
59
+ const elapsed = Date.now() - startTime;
60
+ const numChecks = scanResults.checks.length * scanResults.summary.numAppMaps;
61
+ console.log(`Performed ${numChecks} checks in ${elapsed}ms (${Math.floor(numChecks / (elapsed / 1000.0))} checks/sec)`);
62
+ sendTelemetry(scanResults, elapsed);
63
+ });
64
+ }
65
+ exports.default = singleScan;
66
+ function sendTelemetry(scanResults, msElapsed) {
67
+ const rules = [...new Set(scanResults.checks.map(({ id }) => id))];
68
+ telemetry_1.default.sendEvent({
69
+ name: 'scan:completed',
70
+ properties: {
71
+ rules: rules.join(', '),
72
+ },
73
+ metrics: {
74
+ duration: msElapsed / 1000,
75
+ numRules: rules.length,
76
+ numAppMaps: scanResults.summary.numAppMaps,
77
+ numFindings: scanResults.findings.length,
78
+ },
79
+ });
80
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.Watcher = void 0;
39
+ const promises_1 = require("fs/promises");
40
+ const chokidar = __importStar(require("chokidar"));
41
+ const formatReport_1 = require("./formatReport");
42
+ const scanner_1 = __importDefault(require("./scanner"));
43
+ const fs_1 = require("fs");
44
+ const util_1 = require("util");
45
+ const configurationProvider_1 = require("../../configuration/configurationProvider");
46
+ const assert_1 = __importDefault(require("assert"));
47
+ class Watcher {
48
+ constructor(options) {
49
+ this.options = options;
50
+ }
51
+ watch() {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ yield this.reloadConfig();
54
+ this.configWatcher = chokidar.watch(this.options.configFile, {
55
+ ignoreInitial: true,
56
+ });
57
+ this.configWatcher
58
+ .on('add', this.reloadConfig.bind(this))
59
+ .on('change', this.reloadConfig.bind(this));
60
+ this.appmapWatcher = chokidar.watch(`${this.options.appmapDir}/**/mtime`, {
61
+ ignoreInitial: true,
62
+ });
63
+ this.appmapWatcher.on('add', this.scan.bind(this)).on('change', this.scan.bind(this));
64
+ });
65
+ }
66
+ close() {
67
+ if (!this.appmapWatcher)
68
+ return;
69
+ (0, assert_1.default)(this.configWatcher, `configWatcher should always be defined if appmapWatcher is defined`);
70
+ this.appmapWatcher.close();
71
+ this.configWatcher.close();
72
+ this.appmapWatcher = undefined;
73
+ this.configWatcher = undefined;
74
+ }
75
+ scan(fileName) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ (0, assert_1.default)(this.config, `config should always be loaded before appmapWatcher triggers a scan`);
78
+ const pathTokens = fileName.split('/');
79
+ const appmapDir = pathTokens.slice(0, pathTokens.length - 1).join('/');
80
+ const appmapFile = [appmapDir, 'appmap.json'].join('.');
81
+ const reportFile = [appmapDir, 'appmap-findings.json'].join('/');
82
+ if (!(yield (0, util_1.promisify)(fs_1.exists)(appmapFile)))
83
+ return;
84
+ const scanner = yield (0, scanner_1.default)(true, this.config, [appmapFile]);
85
+ const rawScanResults = yield scanner.scan();
86
+ // Always report the raw data
87
+ yield (0, promises_1.writeFile)(reportFile, (0, formatReport_1.formatReport)(rawScanResults));
88
+ });
89
+ }
90
+ reloadConfig() {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ this.config = yield (0, configurationProvider_1.parseConfigFile)(this.options.configFile);
93
+ });
94
+ }
95
+ }
96
+ exports.Watcher = Watcher;
97
+ function watchScan(options) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ return new Watcher(options).watch();
100
+ });
101
+ }
102
+ exports.default = watchScan;
package/built/cli/scan.js CHANGED
@@ -8,153 +8,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __read = (this && this.__read) || function (o, n) {
39
- var m = typeof Symbol === "function" && o[Symbol.iterator];
40
- if (!m) return o;
41
- var i = m.call(o), r, ar = [], e;
42
- try {
43
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
- }
45
- catch (error) { e = { error: error }; }
46
- finally {
47
- try {
48
- if (r && !r.done && (m = i["return"])) m.call(i);
49
- }
50
- finally { if (e) throw e.error; }
51
- }
52
- return ar;
53
- };
54
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
55
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
56
- if (ar || !(i in from)) {
57
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
58
- ar[i] = from[i];
59
- }
60
- }
61
- return to.concat(ar || Array.prototype.slice.call(from));
62
- };
63
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
64
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
65
13
  };
66
14
  Object.defineProperty(exports, "__esModule", { value: true });
67
15
  /* eslint-disable @typescript-eslint/no-empty-function */
68
- var cli_progress_1 = __importDefault(require("cli-progress"));
69
- var promises_1 = require("fs/promises");
70
- var models_1 = require("@appland/models");
71
- var ruleChecker_1 = __importDefault(require("../ruleChecker"));
72
- var appMapIndex_1 = __importDefault(require("../appMapIndex"));
16
+ const cli_progress_1 = __importDefault(require("cli-progress"));
17
+ const promises_1 = require("fs/promises");
18
+ const models_1 = require("@appland/models");
19
+ const ruleChecker_1 = __importDefault(require("../ruleChecker"));
20
+ const appMapIndex_1 = __importDefault(require("../appMapIndex"));
73
21
  function batch(items, size, process) {
74
- return __awaiter(this, void 0, void 0, function () {
75
- var left;
76
- return __generator(this, function (_a) {
77
- switch (_a.label) {
78
- case 0:
79
- left = __spreadArray([], __read(items), false);
80
- _a.label = 1;
81
- case 1:
82
- if (!left.length) return [3 /*break*/, 3];
83
- return [4 /*yield*/, Promise.all(left.splice(0, size).map(process))];
84
- case 2:
85
- _a.sent();
86
- return [3 /*break*/, 1];
87
- case 3: return [2 /*return*/];
88
- }
89
- });
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const left = [...items];
24
+ while (left.length)
25
+ yield Promise.all(left.splice(0, size).map(process));
90
26
  });
91
27
  }
92
28
  function scan(files, checks) {
93
- return __awaiter(this, void 0, void 0, function () {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ // TODO: Improve this by respecting .gitignore, or similar.
31
+ // For now, this addresses the main problem of encountering appmap-js and its appmap.json files
32
+ // in a bundled node_modules.
33
+ files = files.filter((file) => !file.split('/').includes('node_modules'));
34
+ const checker = new ruleChecker_1.default();
35
+ const appMapMetadata = {};
36
+ const findings = [];
94
37
  function newProgress() {
95
38
  if (process.stdout.isTTY) {
96
- return new cli_progress_1.default.SingleBar({ format: "Scanning [{bar}] {percentage}% | {value}/{total}" }, cli_progress_1.default.Presets.shades_classic);
39
+ return new cli_progress_1.default.SingleBar({ format: `Scanning [{bar}] {percentage}% | {value}/{total}` }, cli_progress_1.default.Presets.shades_classic);
97
40
  }
98
41
  return {
99
- increment: function () { },
100
- start: function () { },
101
- stop: function () { },
42
+ increment: () => { },
43
+ start: () => { },
44
+ stop: () => { },
102
45
  };
103
46
  }
104
- var checker, appMapMetadata, findings, progress;
105
- var _this = this;
106
- return __generator(this, function (_a) {
107
- switch (_a.label) {
108
- case 0:
109
- // TODO: Improve this by respecting .gitignore, or similar.
110
- // For now, this addresses the main problem of encountering appmap-js and its appmap.json files
111
- // in a bundled node_modules.
112
- files = files.filter(function (file) { return !file.split('/').includes('node_modules'); });
113
- checker = new ruleChecker_1.default();
114
- appMapMetadata = {};
115
- findings = [];
116
- progress = newProgress();
117
- progress.start(files.length * checks.length, 0);
118
- return [4 /*yield*/, batch(files, 2, function (file) { return __awaiter(_this, void 0, void 0, function () {
119
- var appMapData, appMap, appMapIndex;
120
- var _this = this;
121
- return __generator(this, function (_a) {
122
- switch (_a.label) {
123
- case 0: return [4 /*yield*/, (0, promises_1.readFile)(file, 'utf8')];
124
- case 1:
125
- appMapData = _a.sent();
126
- appMap = (0, models_1.buildAppMap)(appMapData).normalize().build();
127
- appMapIndex = new appMapIndex_1.default(appMap);
128
- appMapMetadata[file] = appMap.metadata;
129
- return [4 /*yield*/, Promise.all(checks.map(function (check) { return __awaiter(_this, void 0, void 0, function () {
130
- var matchCount, newMatches;
131
- return __generator(this, function (_a) {
132
- switch (_a.label) {
133
- case 0:
134
- matchCount = findings.length;
135
- return [4 /*yield*/, checker.check(file, appMapIndex, check, findings)];
136
- case 1:
137
- _a.sent();
138
- progress.increment();
139
- newMatches = findings.slice(matchCount, findings.length);
140
- newMatches.forEach(function (match) { return (match.appMapFile = file); });
141
- return [2 /*return*/];
142
- }
143
- });
144
- }); }))];
145
- case 2:
146
- _a.sent();
147
- return [2 /*return*/, null];
148
- }
149
- });
150
- }); })];
151
- case 1:
152
- _a.sent();
153
- progress.stop();
154
- return [2 /*return*/, { appMapMetadata: appMapMetadata, findings: findings }];
155
- }
156
- });
47
+ const progress = newProgress();
48
+ progress.start(files.length * checks.length, 0);
49
+ yield batch(files, 2, (file) => __awaiter(this, void 0, void 0, function* () {
50
+ const appMapData = yield (0, promises_1.readFile)(file, 'utf8');
51
+ const appMap = (0, models_1.buildAppMap)(appMapData).normalize().build();
52
+ const appMapIndex = new appMapIndex_1.default(appMap);
53
+ appMapMetadata[file] = appMap.metadata;
54
+ yield Promise.all(checks.map((check) => __awaiter(this, void 0, void 0, function* () {
55
+ const matchCount = findings.length;
56
+ yield checker.check(file, appMapIndex, check, findings);
57
+ progress.increment();
58
+ const newMatches = findings.slice(matchCount, findings.length);
59
+ newMatches.forEach((match) => (match.appMapFile = file));
60
+ })));
61
+ return null;
62
+ }));
63
+ progress.stop();
64
+ return { appMapMetadata, findings };
157
65
  });
158
66
  }
159
67
  exports.default = scan;
160
- //# sourceMappingURL=scan.js.map
@@ -23,4 +23,3 @@ function default_1(args) {
23
23
  });
24
24
  }
25
25
  exports.default = default_1;
26
- //# sourceMappingURL=scanArgs.js.map
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=scanOptions.js.map
@@ -8,58 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
13
  };
41
14
  Object.defineProperty(exports, "__esModule", { value: true });
42
- var commitStatus_1 = __importDefault(require("../integration/github/commitStatus"));
15
+ const commitStatus_1 = __importDefault(require("../integration/github/commitStatus"));
43
16
  function updateCommitStatus(numFindings, numChecks) {
44
- return __awaiter(this, void 0, void 0, function () {
45
- return __generator(this, function (_a) {
46
- switch (_a.label) {
47
- case 0:
48
- if (!(numFindings > 0)) return [3 /*break*/, 2];
49
- return [4 /*yield*/, (0, commitStatus_1.default)('failure', "".concat(numChecks, " checks, ").concat(numFindings, " findings. See CI job log for details."))];
50
- case 1:
51
- _a.sent();
52
- console.log("Commit status updated to: failure (".concat(numFindings, " findings)"));
53
- return [3 /*break*/, 4];
54
- case 2: return [4 /*yield*/, (0, commitStatus_1.default)('success', "".concat(numChecks, " checks passed"))];
55
- case 3:
56
- _a.sent();
57
- console.log("Commit status updated to: success.");
58
- _a.label = 4;
59
- case 4: return [2 /*return*/];
60
- }
61
- });
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ if (numFindings > 0) {
19
+ yield (0, commitStatus_1.default)('failure', `${numChecks} checks, ${numFindings} findings. See CI job log for details.`);
20
+ console.log(`Commit status updated to: failure (${numFindings} findings)`);
21
+ }
22
+ else {
23
+ yield (0, commitStatus_1.default)('success', `${numChecks} checks passed`);
24
+ console.log(`Commit status updated to: success.`);
25
+ }
62
26
  });
63
27
  }
64
28
  exports.default = updateCommitStatus;
65
- //# sourceMappingURL=updateCommitStatus.js.map