@commercetools-connect/connector-validator 0.0.1-rc.79af18b3

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 (64) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE +21 -0
  3. package/README.md +21 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +17 -0
  6. package/dist/validator/common/common-types.d.ts +42 -0
  7. package/dist/validator/common/common-types.js +8 -0
  8. package/dist/validator/common/common-utils.d.ts +5 -0
  9. package/dist/validator/common/common-utils.js +24 -0
  10. package/dist/validator/common/connector-utils.d.ts +6 -0
  11. package/dist/validator/common/connector-utils.js +37 -0
  12. package/dist/validator/common/connector.d.ts +18 -0
  13. package/dist/validator/common/connector.js +27 -0
  14. package/dist/validator/common/index.d.ts +3 -0
  15. package/dist/validator/common/index.js +19 -0
  16. package/dist/validator/common/sonar-client.d.ts +12 -0
  17. package/dist/validator/common/sonar-client.js +55 -0
  18. package/dist/validator/index.d.ts +6 -0
  19. package/dist/validator/index.js +22 -0
  20. package/dist/validator/report/component-report.d.ts +22 -0
  21. package/dist/validator/report/component-report.js +29 -0
  22. package/dist/validator/report/index.d.ts +3 -0
  23. package/dist/validator/report/index.js +19 -0
  24. package/dist/validator/report/report.d.ts +30 -0
  25. package/dist/validator/report/report.js +42 -0
  26. package/dist/validator/report/step-report.d.ts +21 -0
  27. package/dist/validator/report/step-report.js +46 -0
  28. package/dist/validator/tasks/build-docker-image.d.ts +18 -0
  29. package/dist/validator/tasks/build-docker-image.js +31 -0
  30. package/dist/validator/tasks/create-workspace-volume.d.ts +11 -0
  31. package/dist/validator/tasks/create-workspace-volume.js +25 -0
  32. package/dist/validator/tasks/index.d.ts +7 -0
  33. package/dist/validator/tasks/index.js +23 -0
  34. package/dist/validator/tasks/run-sast-scan.d.ts +20 -0
  35. package/dist/validator/tasks/run-sast-scan.js +68 -0
  36. package/dist/validator/tasks/run-sca-scan.d.ts +19 -0
  37. package/dist/validator/tasks/run-sca-scan.js +60 -0
  38. package/dist/validator/tasks/run-unit-tests.d.ts +15 -0
  39. package/dist/validator/tasks/run-unit-tests.js +33 -0
  40. package/dist/validator/tasks/start-sast-server.d.ts +17 -0
  41. package/dist/validator/tasks/start-sast-server.js +39 -0
  42. package/dist/validator/tasks/stop-sast-server.d.ts +9 -0
  43. package/dist/validator/tasks/stop-sast-server.js +20 -0
  44. package/dist/validator/validator-events.d.ts +36 -0
  45. package/dist/validator/validator-events.js +2 -0
  46. package/dist/validator/validator-tasks.factory.d.ts +31 -0
  47. package/dist/validator/validator-tasks.factory.js +204 -0
  48. package/dist/validator/validator.d.ts +24 -0
  49. package/dist/validator/validator.js +127 -0
  50. package/dist/workflow/index.d.ts +5 -0
  51. package/dist/workflow/index.js +21 -0
  52. package/dist/workflow/interfaces/index.d.ts +1 -0
  53. package/dist/workflow/interfaces/index.js +17 -0
  54. package/dist/workflow/interfaces/task.interface.d.ts +24 -0
  55. package/dist/workflow/interfaces/task.interface.js +2 -0
  56. package/dist/workflow/workflow-engine.d.ts +21 -0
  57. package/dist/workflow/workflow-engine.js +69 -0
  58. package/dist/workflow/workflow-errors.d.ts +3 -0
  59. package/dist/workflow/workflow-errors.js +6 -0
  60. package/dist/workflow/workflow-task.d.ts +29 -0
  61. package/dist/workflow/workflow-task.js +73 -0
  62. package/dist/workflow/workflow.d.ts +7 -0
  63. package/dist/workflow/workflow.js +21 -0
  64. package/package.json +36 -0
@@ -0,0 +1,11 @@
1
+ import { Task } from "../../workflow";
2
+ type CreateWorkspaceVolumeTaskInput = {
3
+ workspaceSrcImageName: string;
4
+ componentDir: string;
5
+ dockerVolumeName: string;
6
+ };
7
+ type CreateWorkspaceVolumeTaskOutput = void;
8
+ declare class CreateWorkspaceVolumeTask extends Task<CreateWorkspaceVolumeTaskInput, CreateWorkspaceVolumeTaskOutput> {
9
+ run(input: CreateWorkspaceVolumeTaskInput): Promise<CreateWorkspaceVolumeTaskOutput>;
10
+ }
11
+ export { CreateWorkspaceVolumeTask };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CreateWorkspaceVolumeTask = void 0;
7
+ const execa_1 = __importDefault(require("execa"));
8
+ const workflow_1 = require("../../workflow");
9
+ class CreateWorkspaceVolumeTask extends workflow_1.Task {
10
+ async run(input) {
11
+ const { workspaceSrcImageName, componentDir, dockerVolumeName } = input;
12
+ await (0, execa_1.default)("docker", ["volume", "create", input.dockerVolumeName]);
13
+ await (0, execa_1.default)("docker", [
14
+ "run",
15
+ "--rm",
16
+ "--volume",
17
+ `${dockerVolumeName}:/workspace/${componentDir}`,
18
+ "--entrypoint",
19
+ "launcher",
20
+ workspaceSrcImageName,
21
+ "sh",
22
+ ]);
23
+ }
24
+ }
25
+ exports.CreateWorkspaceVolumeTask = CreateWorkspaceVolumeTask;
@@ -0,0 +1,7 @@
1
+ export * from "./build-docker-image";
2
+ export * from "./create-workspace-volume";
3
+ export * from "./run-sast-scan";
4
+ export * from "./run-sca-scan";
5
+ export * from "./run-unit-tests";
6
+ export * from "./start-sast-server";
7
+ export * from "./stop-sast-server";
@@ -0,0 +1,23 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./build-docker-image"), exports);
18
+ __exportStar(require("./create-workspace-volume"), exports);
19
+ __exportStar(require("./run-sast-scan"), exports);
20
+ __exportStar(require("./run-sca-scan"), exports);
21
+ __exportStar(require("./run-unit-tests"), exports);
22
+ __exportStar(require("./start-sast-server"), exports);
23
+ __exportStar(require("./stop-sast-server"), exports);
@@ -0,0 +1,20 @@
1
+ import { Task } from "../../workflow";
2
+ import { StaticCodeAnalysisIssue } from "../common/common-types";
3
+ type RunSastScanTaskInput = {
4
+ projectRootDir: string;
5
+ components: Array<{
6
+ name: string;
7
+ workspaceVolume: string;
8
+ }>;
9
+ sastServerPort: number;
10
+ };
11
+ type RunSastScanTaskOutput = {
12
+ success: boolean;
13
+ issues: Array<StaticCodeAnalysisIssue>;
14
+ };
15
+ declare class RunSastScanTask extends Task<RunSastScanTaskInput, RunSastScanTaskOutput> {
16
+ run(input: RunSastScanTaskInput): Promise<RunSastScanTaskOutput>;
17
+ buildCommand(input: RunSastScanTaskInput): [string, string[]];
18
+ extractTaskIdFromSonarReport(projectRootDir: string): string;
19
+ }
20
+ export { RunSastScanTask };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RunSastScanTask = void 0;
7
+ const node_os_1 = __importDefault(require("node:os"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const execa_1 = __importDefault(require("execa"));
11
+ const workflow_1 = require("../../workflow");
12
+ const common_utils_1 = require("../common/common-utils");
13
+ const sonar_client_1 = require("../common/sonar-client");
14
+ const SONAR_API_PROTO = "http";
15
+ const SONAR_API_HOST = "localhost";
16
+ const SONAR_AUTH = "admin:admin";
17
+ const SONAR_AUTH_HEADER = "Basic " + Buffer.from(SONAR_AUTH).toString("base64");
18
+ const SONAR_SEVERITIES = "BLOCKER,CRITICAL";
19
+ class RunSastScanTask extends workflow_1.Task {
20
+ async run(input) {
21
+ try {
22
+ const [command, args] = this.buildCommand(input);
23
+ const sonar = new sonar_client_1.SonarClient(SONAR_API_PROTO, SONAR_API_HOST, input.sastServerPort, SONAR_AUTH_HEADER);
24
+ await common_utils_1.CommonUtility.retry(() => sonar.hasServerStartedOrThrow(), 20, 10000);
25
+ await common_utils_1.CommonUtility.retry(() => sonar.isServerReadyOrThrow(), 60, 10000);
26
+ await (0, execa_1.default)(command, args, { killSignal: "SIGKILL" });
27
+ const taskId = await this.extractTaskIdFromSonarReport(input.projectRootDir);
28
+ await common_utils_1.CommonUtility.retry(() => sonar.hasTaskSucceeded(taskId), 20, 5000);
29
+ const issues = await sonar.fetchIssues(taskId, SONAR_SEVERITIES);
30
+ return { success: !issues.length, issues };
31
+ }
32
+ catch (error) {
33
+ if (error instanceof Error && "stderr" in error) {
34
+ throw new Error(String(error.stderr));
35
+ }
36
+ throw error;
37
+ }
38
+ }
39
+ buildCommand(input) {
40
+ const sources = [];
41
+ const command = "docker";
42
+ const args = ["run", "--rm", "--stop-signal", "SIGKILL"];
43
+ args.push("--add-host", "host.docker.internal:host-gateway");
44
+ args.push("--env", `SONAR_HOST_URL=http://host.docker.internal:${input.sastServerPort}`);
45
+ args.push("--env", "SONAR_LOGIN=admin");
46
+ args.push("--env", "SONAR_PASSWORD=admin");
47
+ args.push("--volume", `${input.projectRootDir}/.connect/.scannerwork:/usr/src/.scannerwork`);
48
+ args.push("--volume", `${node_path_1.default.join(node_os_1.default.homedir(), ".sonar")}:/opt/sonar-scanner/.sonar/cache`);
49
+ for (const application of input.components) {
50
+ sources.push(node_path_1.default.join(application.name, "src"));
51
+ args.push("--volume", `${application.workspaceVolume}:/usr/src/${application.name}`);
52
+ }
53
+ args.push("sonarsource/sonar-scanner-cli:5.0.1");
54
+ args.push(`-Dsonar.projectKey=project`, `-Dsonar.projectBaseDir=.`, `-Dsonar.sources=${sources.join(",")}`, "-Dsonar.java.binaries=.", "-Dsonar.ws.timeout=180");
55
+ return [command, args];
56
+ }
57
+ extractTaskIdFromSonarReport(projectRootDir) {
58
+ const reportPath = node_path_1.default.join(projectRootDir, ".connect", ".scannerwork", "report-task.txt");
59
+ const data = node_fs_1.default.readFileSync(reportPath, "utf-8");
60
+ const taskIdLine = data.split("\n").find((line) => line.startsWith("ceTaskId="));
61
+ if (taskIdLine) {
62
+ const [, taskId] = taskIdLine.split("=");
63
+ return String(taskId).trim();
64
+ }
65
+ throw new Error("Task ID not found in report-task.txt");
66
+ }
67
+ }
68
+ exports.RunSastScanTask = RunSastScanTask;
@@ -0,0 +1,19 @@
1
+ import { Task } from "../../workflow";
2
+ import { CompositionAnalysisIssue } from "../common/common-types";
3
+ type RunScaTaskInput = {
4
+ components: Array<{
5
+ name: string;
6
+ workspaceVolume: string;
7
+ }>;
8
+ };
9
+ type RunScaTaskOutput = {
10
+ success: boolean;
11
+ issues: Array<CompositionAnalysisIssue>;
12
+ };
13
+ declare class RunScaTask extends Task<RunScaTaskInput, RunScaTaskOutput> {
14
+ run(input: RunScaTaskInput): Promise<RunScaTaskOutput>;
15
+ private buildCommand;
16
+ private extractIssuesFromTrivyReport;
17
+ private mapTrivyVulnerabilityToIssue;
18
+ }
19
+ export { RunScaTask };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RunScaTask = void 0;
7
+ const execa_1 = __importDefault(require("execa"));
8
+ const workflow_1 = require("../../workflow");
9
+ class RunScaTask extends workflow_1.Task {
10
+ async run(input) {
11
+ const [command, args] = this.buildCommand(input);
12
+ const result = await (0, execa_1.default)(command, args, { all: true });
13
+ const report = JSON.parse(result.stdout);
14
+ const issues = this.extractIssuesFromTrivyReport(report);
15
+ return { success: !issues.length, issues };
16
+ }
17
+ buildCommand(input) {
18
+ const command = "docker";
19
+ const args = ["run", "--rm", "--stop-signal", "SIGKILL"];
20
+ for (const component of input.components) {
21
+ args.push("--volume", `${component.workspaceVolume}:/workspace/${component.name}`);
22
+ }
23
+ args.push("aquasec/trivy:0.51.1", "fs");
24
+ args.push("--format", "json");
25
+ args.push("--include-dev-deps");
26
+ args.push("--scanners", "vuln");
27
+ args.push("--severity", "HIGH,CRITICAL");
28
+ args.push("--ignore-unfixed");
29
+ args.push("workspace");
30
+ return [command, args];
31
+ }
32
+ extractIssuesFromTrivyReport(trivyResult) {
33
+ const results = trivyResult.Results;
34
+ if (results == null)
35
+ return [];
36
+ return results.reduce((issues, target) => {
37
+ const vulnerabilities = target.Vulnerabilities;
38
+ if (vulnerabilities == null)
39
+ return issues;
40
+ const targetIssues = vulnerabilities.map((vuln) => this.mapTrivyVulnerabilityToIssue(target.Target, vuln));
41
+ issues.push(...targetIssues);
42
+ return issues;
43
+ }, []);
44
+ }
45
+ mapTrivyVulnerabilityToIssue(file, vuln) {
46
+ return {
47
+ kind: "dependency_vulnerability",
48
+ id: vuln.VulnerabilityID,
49
+ file,
50
+ package: {
51
+ name: vuln.PkgName,
52
+ installedVersion: vuln.InstalledVersion,
53
+ },
54
+ severity: vuln.Severity,
55
+ title: vuln.Title,
56
+ description: vuln.Description,
57
+ };
58
+ }
59
+ }
60
+ exports.RunScaTask = RunScaTask;
@@ -0,0 +1,15 @@
1
+ import { Task } from "../../workflow";
2
+ type RunUnitTestsTaskInput = {
3
+ workspaceSrcImageName: string;
4
+ componentName: string;
5
+ logDirectory: string;
6
+ };
7
+ type RunUnitTestsTaskOutput = {
8
+ success: boolean;
9
+ logFilePath: string;
10
+ };
11
+ declare class RunUnitTestsTask extends Task<RunUnitTestsTaskInput, RunUnitTestsTaskOutput> {
12
+ run(input: RunUnitTestsTaskInput): Promise<RunUnitTestsTaskOutput>;
13
+ private writeLogFile;
14
+ }
15
+ export { RunUnitTestsTask };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RunUnitTestsTask = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const workflow_1 = require("../../workflow");
10
+ const connector_buildtools_1 = require("@commercetools-connect/connector-buildtools");
11
+ class RunUnitTestsTask extends workflow_1.Task {
12
+ async run(input) {
13
+ const { workspaceSrcImageName, componentName } = input;
14
+ const logFilePath = node_path_1.default.join(input.logDirectory, `tests_${componentName}.log`);
15
+ try {
16
+ const applicationContainerImage = new connector_buildtools_1.ApplicationImage(workspaceSrcImageName);
17
+ const testResults = await applicationContainerImage.runTests();
18
+ this.writeLogFile(logFilePath, String(testResults?.all));
19
+ return { success: true, logFilePath };
20
+ }
21
+ catch (error) {
22
+ if (error instanceof Error && "all" in error) {
23
+ this.writeLogFile(logFilePath, String(error?.all));
24
+ return { success: false, logFilePath };
25
+ }
26
+ throw error;
27
+ }
28
+ }
29
+ writeLogFile(logFilePath, logs) {
30
+ node_fs_1.default.writeFileSync(logFilePath, logs);
31
+ }
32
+ }
33
+ exports.RunUnitTestsTask = RunUnitTestsTask;
@@ -0,0 +1,17 @@
1
+ import { Task } from "../../workflow";
2
+ type StartSastServerTaskInput = {
3
+ containerName: string;
4
+ logDir?: string;
5
+ };
6
+ type StartSastServerTaskOutput = {
7
+ sastServerPort: number;
8
+ };
9
+ declare class StartSastServerTask extends Task<StartSastServerTaskInput, StartSastServerTaskOutput> {
10
+ run(input: StartSastServerTaskInput): Promise<{
11
+ sastServerPort: number;
12
+ }>;
13
+ startServer(input: StartSastServerTaskInput): Promise<{
14
+ sastServerPort: number;
15
+ }>;
16
+ }
17
+ export { StartSastServerTask };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StartSastServerTask = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const execa_1 = __importDefault(require("execa"));
10
+ const get_port_1 = __importDefault(require("get-port"));
11
+ const workflow_1 = require("../../workflow");
12
+ const common_utils_1 = require("../common/common-utils");
13
+ class StartSastServerTask extends workflow_1.Task {
14
+ async run(input) {
15
+ return common_utils_1.CommonUtility.retry(() => this.startServer(input), 3, 5000);
16
+ }
17
+ async startServer(input) {
18
+ const sastServerPort = await (0, get_port_1.default)({ port: get_port_1.default.makeRange(9000, 9999) });
19
+ const command = "docker";
20
+ const args = ["run", "--rm", "--stop-signal", "SIGKILL"];
21
+ args.push("-p", `${sastServerPort}:9000`);
22
+ args.push("--name", input.containerName);
23
+ args.push("--env", "SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true");
24
+ args.push("sonarqube:9.9-community");
25
+ const subProcess = (0, execa_1.default)(command, args, { all: true, killSignal: "SIGKILL" });
26
+ await common_utils_1.CommonUtility.sleep(1000);
27
+ if (subProcess.exitCode) {
28
+ throw new Error(`Failed to start SAST server. Process was killed. Error details: ${String(subProcess.stderr)}`);
29
+ }
30
+ if (input.logDir) {
31
+ const logFilePath = node_path_1.default.join(input.logDir, "sast_server.log");
32
+ subProcess.all?.pipe(node_fs_1.default.createWriteStream(logFilePath));
33
+ }
34
+ subProcess.catch(() => {
35
+ });
36
+ return { sastServerPort };
37
+ }
38
+ }
39
+ exports.StartSastServerTask = StartSastServerTask;
@@ -0,0 +1,9 @@
1
+ import { Task } from "../../workflow";
2
+ type StopSastServerTaskInput = {
3
+ containerName: string;
4
+ };
5
+ type StopSastServerTaskOutput = void;
6
+ declare class StopSastServerTask extends Task<StopSastServerTaskInput, StopSastServerTaskOutput> {
7
+ run(input: StopSastServerTaskInput): Promise<StopSastServerTaskOutput>;
8
+ }
9
+ export { StopSastServerTask };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StopSastServerTask = void 0;
7
+ const execa_1 = __importDefault(require("execa"));
8
+ const workflow_1 = require("../../workflow");
9
+ const common_utils_1 = require("../common/common-utils");
10
+ class StopSastServerTask extends workflow_1.Task {
11
+ async run(input) {
12
+ try {
13
+ const stopSastServer = () => (0, execa_1.default)("docker", ["stop", "-s", "SIGKILL", input.containerName]);
14
+ await common_utils_1.CommonUtility.retry(stopSastServer, 5, 2000);
15
+ }
16
+ catch (error) {
17
+ }
18
+ }
19
+ }
20
+ exports.StopSastServerTask = StopSastServerTask;
@@ -0,0 +1,36 @@
1
+ import { ConnectorComponent } from "./common/connector";
2
+ import { CompositionAnalysisIssue, StaticCodeAnalysisIssue } from "./common/common-types";
3
+ import { ReportObject, StepReportObject } from "./report";
4
+ export interface BuildStepEvent {
5
+ kind: "build";
6
+ component: ConnectorComponent;
7
+ report: StepReportObject<{
8
+ logFilePath: string | undefined;
9
+ }>;
10
+ }
11
+ export interface TestStepEvent {
12
+ kind: "test";
13
+ component: ConnectorComponent;
14
+ report: StepReportObject<{
15
+ logFilePath: string | undefined;
16
+ }>;
17
+ }
18
+ export interface ScaStepEvent {
19
+ kind: "sca";
20
+ report: StepReportObject<{
21
+ issues: Array<CompositionAnalysisIssue>;
22
+ }>;
23
+ }
24
+ export interface SastStepEvent {
25
+ kind: "sast";
26
+ report: StepReportObject<{
27
+ issues: Array<StaticCodeAnalysisIssue>;
28
+ }>;
29
+ }
30
+ export type StepEvent = BuildStepEvent | TestStepEvent | ScaStepEvent | SastStepEvent;
31
+ export type ConnectorValidatorEvents = {
32
+ stepStarted: [StepEvent];
33
+ stepCompleted: [StepEvent];
34
+ validationCompleted: [ReportObject];
35
+ validationException: [Error[]];
36
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
1
+ import * as Tasks from "./tasks";
2
+ import { Report as ValidationReport } from "./report";
3
+ import { ITask } from "../workflow/interfaces/task.interface";
4
+ import { ConnectorValidatorEvents } from "./validator-events";
5
+ import { ConnectorComponent } from "./common/connector";
6
+ declare class ValidatorTasksFactory {
7
+ private readonly projectRootDir;
8
+ private readonly validationId;
9
+ private readonly report;
10
+ private readonly emitter;
11
+ constructor(projectRootDir: string, validationId: string, report: ValidationReport, emitter: NodeJS.EventEmitter<ConnectorValidatorEvents>);
12
+ createBuildTask(component: ConnectorComponent, logDirectory: string): Tasks.BuildDockerImageTask;
13
+ createWorkspaceVolumeTask(component: ConnectorComponent & {
14
+ workspaceVolume: string;
15
+ }, needs: [Tasks.BuildDockerImageTask]): Tasks.CreateWorkspaceVolumeTask;
16
+ createTestTask(component: ConnectorComponent & {
17
+ workspaceVolume: string;
18
+ }, logDirectory: string, needs: [Tasks.CreateWorkspaceVolumeTask]): Tasks.RunUnitTestsTask;
19
+ createScaScanTask(components: Array<ConnectorComponent & {
20
+ workspaceVolume: string;
21
+ }>, needs?: Array<ITask>): Tasks.RunScaTask;
22
+ createStartSastServerTask(logDirectory: string, needs?: Array<ITask>): Tasks.StartSastServerTask;
23
+ createSastScanTask(components: Array<{
24
+ name: string;
25
+ workspaceVolume: string;
26
+ }>, needs: [Tasks.StartSastServerTask, ...ITask[]]): Tasks.RunSastScanTask;
27
+ createStopSastServerTask(needs: [Tasks.RunSastScanTask]): Tasks.StopSastServerTask;
28
+ private buildComponentImageName;
29
+ private buildComponentImageTag;
30
+ }
31
+ export { ValidatorTasksFactory };
@@ -0,0 +1,204 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.ValidatorTasksFactory = void 0;
30
+ const node_path_1 = __importDefault(require("node:path"));
31
+ const Tasks = __importStar(require("./tasks"));
32
+ class ValidatorTasksFactory {
33
+ projectRootDir;
34
+ validationId;
35
+ report;
36
+ emitter;
37
+ constructor(projectRootDir, validationId, report, emitter) {
38
+ this.projectRootDir = projectRootDir;
39
+ this.validationId = validationId;
40
+ this.report = report;
41
+ this.emitter = emitter;
42
+ }
43
+ createBuildTask(component, logDirectory) {
44
+ const imageName = this.buildComponentImageName(component);
45
+ const task = new Tasks.BuildDockerImageTask({
46
+ id: `build-${component.name}`,
47
+ handleInput: () => ({
48
+ projectRootDir: this.projectRootDir,
49
+ componentName: component.name,
50
+ componentDir: component.directory,
51
+ imageName,
52
+ imageTag: `${imageName}:${this.validationId}`,
53
+ logDir: logDirectory,
54
+ }),
55
+ });
56
+ const stepReport = this.report.getComponentOrThrow(component.name).build;
57
+ const baseEventData = { kind: "build", component };
58
+ task.on("started", () => {
59
+ stepReport.inProgress();
60
+ this.emitter.emit("stepStarted", { ...baseEventData, report: stepReport.toObject() });
61
+ });
62
+ task.on("succeeded", (_, output) => {
63
+ if (output.success)
64
+ stepReport.success(output);
65
+ else
66
+ stepReport.failure(output);
67
+ this.emitter.emit("stepCompleted", { ...baseEventData, report: stepReport.toObject() });
68
+ });
69
+ return task;
70
+ }
71
+ createWorkspaceVolumeTask(component, needs) {
72
+ return new Tasks.CreateWorkspaceVolumeTask({
73
+ id: `create-volume-${component.name}`,
74
+ needs,
75
+ if: () => needs[0].output?.success === true,
76
+ handleInput: () => ({
77
+ componentDir: component.directory,
78
+ dockerVolumeName: component.workspaceVolume,
79
+ workspaceSrcImageName: this.buildComponentImageTag(component),
80
+ }),
81
+ });
82
+ }
83
+ createTestTask(component, logDirectory, needs) {
84
+ const task = new Tasks.RunUnitTestsTask({
85
+ id: `test-${component.name}`,
86
+ needs,
87
+ handleInput: () => ({
88
+ componentName: component.name,
89
+ dockerVolumeName: component.workspaceVolume,
90
+ workspaceSrcImageName: this.buildComponentImageTag(component),
91
+ logDirectory,
92
+ }),
93
+ });
94
+ const stepReport = this.report.getComponentOrThrow(component.name).test;
95
+ const baseEventData = { kind: "test", component };
96
+ task.on("started", () => {
97
+ stepReport.inProgress();
98
+ this.emitter.emit("stepStarted", { ...baseEventData, report: stepReport.toObject() });
99
+ });
100
+ task.on("skipped", () => {
101
+ stepReport.skip();
102
+ this.emitter.emit("stepCompleted", { ...baseEventData, report: stepReport.toObject() });
103
+ });
104
+ task.on("succeeded", (_, output) => {
105
+ if (output.success)
106
+ stepReport.success(output);
107
+ else
108
+ stepReport.failure(output);
109
+ this.emitter.emit("stepCompleted", { ...baseEventData, report: stepReport.toObject() });
110
+ });
111
+ return task;
112
+ }
113
+ createScaScanTask(components, needs = []) {
114
+ const task = new Tasks.RunScaTask({
115
+ id: "sca",
116
+ needs,
117
+ handleInput: () => ({ components }),
118
+ });
119
+ task.on("started", () => {
120
+ this.report.scaAnalysis.inProgress();
121
+ this.emitter.emit("stepStarted", { kind: "sca", report: this.report.scaAnalysis.toObject() });
122
+ });
123
+ task.on("skipped", () => {
124
+ this.report.scaAnalysis.skip();
125
+ this.emitter.emit("stepCompleted", {
126
+ kind: "sca",
127
+ report: this.report.scaAnalysis.toObject(),
128
+ });
129
+ });
130
+ task.on("succeeded", (_, output) => {
131
+ if (output.success)
132
+ this.report.scaAnalysis.success(output);
133
+ else
134
+ this.report.scaAnalysis.failure(output);
135
+ this.emitter.emit("stepCompleted", {
136
+ kind: "sca",
137
+ report: this.report.scaAnalysis.toObject(),
138
+ });
139
+ });
140
+ return task;
141
+ }
142
+ createStartSastServerTask(logDirectory, needs = []) {
143
+ return new Tasks.StartSastServerTask({
144
+ id: "start-sast-server",
145
+ needs,
146
+ handleInput: () => ({
147
+ containerName: `ct-connect-sq_${this.validationId}`,
148
+ logDir: logDirectory,
149
+ }),
150
+ });
151
+ }
152
+ createSastScanTask(components, needs) {
153
+ const task = new Tasks.RunSastScanTask({
154
+ id: "run-sast",
155
+ needs,
156
+ handleInput: () => ({
157
+ projectRootDir: this.projectRootDir,
158
+ components,
159
+ sastServerPort: Number(needs[0].output?.sastServerPort),
160
+ }),
161
+ });
162
+ task.on("started", () => {
163
+ this.report.sastAnalysis.inProgress();
164
+ this.emitter.emit("stepStarted", {
165
+ kind: "sast",
166
+ report: this.report.sastAnalysis.toObject(),
167
+ });
168
+ });
169
+ task.on("skipped", () => {
170
+ this.report.sastAnalysis.skip();
171
+ this.emitter.emit("stepCompleted", {
172
+ kind: "sast",
173
+ report: this.report.sastAnalysis.toObject(),
174
+ });
175
+ });
176
+ task.on("succeeded", (_, output) => {
177
+ if (output.success)
178
+ this.report.sastAnalysis.success(output);
179
+ else
180
+ this.report.sastAnalysis.failure(output);
181
+ this.emitter.emit("stepCompleted", {
182
+ kind: "sast",
183
+ report: this.report.sastAnalysis.toObject(),
184
+ });
185
+ });
186
+ return task;
187
+ }
188
+ createStopSastServerTask(needs) {
189
+ const task = new Tasks.StopSastServerTask({
190
+ id: "stop-sast-server",
191
+ needs,
192
+ if: () => true,
193
+ handleInput: () => ({ containerName: `ct-connect-sq_${this.validationId}` }),
194
+ });
195
+ return task;
196
+ }
197
+ buildComponentImageName(component) {
198
+ return `${node_path_1.default.basename(this.projectRootDir)}_${component.name}`.toLowerCase();
199
+ }
200
+ buildComponentImageTag(component) {
201
+ return `${this.buildComponentImageName(component)}:${this.validationId}`;
202
+ }
203
+ }
204
+ exports.ValidatorTasksFactory = ValidatorTasksFactory;