@datadog/datadog-ci-plugin-sarif 5.12.1 → 5.13.1

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.
@@ -1,11 +0,0 @@
1
- import type { Payload } from './interfaces';
2
- export declare const renderInvalidFile: (sarifReport: string, errorMessages: string[]) => string;
3
- export declare const renderMissingTags: (missingTags: string[]) => string;
4
- export declare const renderFailedUpload: (sarifReport: Payload, error: any) => string;
5
- export declare const renderRetriedUpload: (sarifReport: Payload, errorMessage: string, attempt: number) => string;
6
- export declare const renderSuccessfulCommand: (fileCount: number, duration: number) => string;
7
- export declare const renderDryRunUpload: (payload: Payload) => string;
8
- export declare const renderUpload: (payload: Payload) => string;
9
- export declare const renderUploadWithSpan: (payload: Payload) => string;
10
- export declare const renderCommandInfo: (basePaths: string[], env: string, sha: string, concurrency: number, dryRun: boolean, noVerify: boolean) => string;
11
- export declare const renderFilesNotFound: (basePaths: string[]) => string;
package/dist/renderer.js DELETED
@@ -1,101 +0,0 @@
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.renderFilesNotFound = exports.renderCommandInfo = exports.renderUploadWithSpan = exports.renderUpload = exports.renderDryRunUpload = exports.renderSuccessfulCommand = exports.renderRetriedUpload = exports.renderFailedUpload = exports.renderMissingTags = exports.renderInvalidFile = void 0;
7
- const node_util_1 = require("node:util");
8
- const app_1 = require("@datadog/datadog-ci-base/helpers/app");
9
- const chalk_1 = __importDefault(require("chalk"));
10
- const upath_1 = __importDefault(require("upath"));
11
- const ICONS = {
12
- FAILED: '❌',
13
- SUCCESS: '✅',
14
- WARNING: '⚠️',
15
- INFO: 'ℹ️',
16
- };
17
- const renderInvalidFile = (sarifReport, errorMessages) => {
18
- let fullStr = '';
19
- const reportPath = `[${chalk_1.default.bold.dim(sarifReport)}]`;
20
- fullStr += chalk_1.default.red(`${ICONS.FAILED} Invalid SARIF report file ${reportPath}.\n`);
21
- fullStr += chalk_1.default.red(`The report is too large, not a valid JSON or is not compliant with the SARIF json schema v2.1.0.\n`);
22
- fullStr += chalk_1.default.red(`Error(s) found:\n`);
23
- for (const errorMessage of errorMessages) {
24
- fullStr += chalk_1.default.red(` - ${errorMessage}\n`);
25
- }
26
- return fullStr;
27
- };
28
- exports.renderInvalidFile = renderInvalidFile;
29
- const renderMissingTags = (missingTags) => {
30
- const styledPath = `[${chalk_1.default.bold.dim(process.cwd())}]`;
31
- let fullStr = '';
32
- fullStr += chalk_1.default.red(`There are missing git tags in ${styledPath}:\n`);
33
- missingTags.forEach((tag) => {
34
- fullStr += chalk_1.default.red(` - ${tag}\n`);
35
- });
36
- fullStr += chalk_1.default.red(`To fix this, ensure that the git information above is available for your commit.\n`);
37
- return fullStr;
38
- };
39
- exports.renderMissingTags = renderMissingTags;
40
- const renderFailedUpload = (sarifReport, error) => {
41
- var _a;
42
- const reportPath = `[${chalk_1.default.bold.dim(sarifReport.reportPath)}]`;
43
- let fullStr = '';
44
- fullStr += chalk_1.default.red(`${ICONS.FAILED} Failed upload SARIF report file ${reportPath}: ${error.message}\n`);
45
- if ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) {
46
- fullStr += chalk_1.default.red(`API status code: ${error.response.status}\n`);
47
- }
48
- if (error.message.includes('Aggregate Error')) {
49
- fullStr += chalk_1.default.red(`Inspect error: ${(0, node_util_1.inspect)(error)}\n`);
50
- }
51
- return fullStr;
52
- };
53
- exports.renderFailedUpload = renderFailedUpload;
54
- const renderRetriedUpload = (sarifReport, errorMessage, attempt) => {
55
- const sarifReportPath = `[${chalk_1.default.bold.dim(sarifReport.reportPath)}]`;
56
- return chalk_1.default.yellow(`[attempt ${attempt}] Retrying SARIF report upload ${sarifReportPath}: ${errorMessage}\n`);
57
- };
58
- exports.renderRetriedUpload = renderRetriedUpload;
59
- const renderSuccessfulCommand = (fileCount, duration) => {
60
- let fullStr = '';
61
- fullStr += chalk_1.default.green(`${ICONS.SUCCESS} Uploaded ${fileCount} files in ${duration} seconds.\n`);
62
- fullStr += chalk_1.default.green(`${ICONS.INFO} Results available on ${(0, app_1.getBaseUrl)()}ci/code-analysis\n`);
63
- fullStr += chalk_1.default.green('=================================================================================================\n');
64
- return fullStr;
65
- };
66
- exports.renderSuccessfulCommand = renderSuccessfulCommand;
67
- const renderDryRunUpload = (payload) => `[DRYRUN] ${(0, exports.renderUploadWithSpan)(payload)}`;
68
- exports.renderDryRunUpload = renderDryRunUpload;
69
- const renderUpload = (payload) => `Uploading SARIF report in ${payload.reportPath}\n`;
70
- exports.renderUpload = renderUpload;
71
- const renderUploadWithSpan = (payload) => `Uploading SARIF report to ${payload.reportPath} with tags ${JSON.stringify(payload.spanTags)}\n`;
72
- exports.renderUploadWithSpan = renderUploadWithSpan;
73
- const renderCommandInfo = (basePaths, env, sha, concurrency, dryRun, noVerify) => {
74
- let fullStr = '';
75
- if (dryRun) {
76
- fullStr += chalk_1.default.yellow(`${ICONS.WARNING} DRY-RUN MODE ENABLED. WILL NOT UPLOAD SARIF REPORT\n`);
77
- }
78
- if (noVerify) {
79
- fullStr += chalk_1.default.yellow(`${ICONS.INFO} --no-verify enabled. The reports will be uploaded without client validation.\n`);
80
- }
81
- fullStr += chalk_1.default.green(`Starting upload with concurrency ${concurrency}. \n`);
82
- if (basePaths.length === 1 && !!upath_1.default.extname(basePaths[0])) {
83
- fullStr += chalk_1.default.green(`Will upload SARIF report file ${basePaths[0]}\n`);
84
- }
85
- else {
86
- fullStr += chalk_1.default.green(`Will look for SARIF report files in ${basePaths.join(', ')}\n`);
87
- }
88
- fullStr += `Only one upload per commit, env and tool\n`;
89
- fullStr += `Preparing upload for sha:${sha} env:${env}\n`;
90
- return fullStr;
91
- };
92
- exports.renderCommandInfo = renderCommandInfo;
93
- const renderFilesNotFound = (basePaths) => {
94
- let fullStr = '';
95
- const paths = basePaths.length === 1 && !!upath_1.default.extname(basePaths[0]) ? basePaths[0] : basePaths.join(', ');
96
- fullStr += chalk_1.default.yellow(`${ICONS.WARNING} Cannot find valid SARIF report files to upload in ${paths}.\n`);
97
- fullStr += chalk_1.default.yellow(`Check the files exist and are valid.\n`);
98
- return fullStr;
99
- };
100
- exports.renderFilesNotFound = renderFilesNotFound;
101
- //# sourceMappingURL=renderer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAiC;AAIjC,8DAA+D;AAC/D,kDAAyB;AACzB,kDAAyB;AAEzB,MAAM,KAAK,GAAG;IACZ,MAAM,EAAE,GAAG;IACX,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,IAAI;CACX,CAAA;AAEM,MAAM,iBAAiB,GAAG,CAAC,WAAmB,EAAE,aAAuB,EAAE,EAAE;IAChF,IAAI,OAAO,GAAG,EAAE,CAAA;IAChB,MAAM,UAAU,GAAG,IAAI,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAA;IAErD,OAAO,IAAI,eAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,8BAA8B,UAAU,KAAK,CAAC,CAAA;IAClF,OAAO,IAAI,eAAK,CAAC,GAAG,CAClB,oGAAoG,CACrG,CAAA;IAED,OAAO,IAAI,eAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;IACzC,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;QACxC,OAAO,IAAI,eAAK,CAAC,GAAG,CAAC,MAAM,YAAY,IAAI,CAAC,CAAA;KAC7C;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAfY,QAAA,iBAAiB,qBAe7B;AAEM,MAAM,iBAAiB,GAAG,CAAC,WAAqB,EAAE,EAAE;IACzD,MAAM,UAAU,GAAG,IAAI,eAAK,CAAC,IAAI,CAAC,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CAAA;IAE3G,OAAO,IAAI,eAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,sDAAsD,KAAK,KAAK,CAAC,CAAA;IACzG,OAAO,IAAI,eAAK,CAAC,MAAM,CAAC,wCAAwC,CAAC,CAAA;IAEjE,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AARY,QAAA,mBAAmB,uBAQ/B"}
package/dist/utils.d.ts DELETED
@@ -1,21 +0,0 @@
1
- export declare const getBaseIntakeUrl: () => string;
2
- export declare const TAG_DATADOG_TYPE_TYPE_STATIC = "DATADOG_RULE_TYPE:STATIC_ANALYSIS";
3
- export declare const TAG_DATADOG_TYPE_TYPE_SECRET = "DATADOG_RULE_TYPE:SECRET";
4
- export declare const SERVICE_DATADOG_ANALYZER = "datadog-analyzer";
5
- export declare const SERVICE_DATADOG_ANALYZER_SA_ONLY = "datadog-analyzer-sa-only";
6
- export declare const SERVICE_DATADOG_ANALYZER_SECRETS_ONLY = "datadog-analyzer-secrets-only";
7
- export declare const SERVICE_THIRD_PARTY_ANALYZER = "third-party-analyzer";
8
- /**
9
- * Define the service and env based on the SARIF contents reports
10
- * - if the report is produced by the datadog static analyzer, we look if the report
11
- * contains only static analysis or secrets errors and change service
12
- * - if the report is produced by a third party tool, we report it as is and cannot
13
- * infer the nature of the results. We still try to get the first tool from the runs.
14
- *
15
- * The objective of this function is to make sure that if a user uploads one report
16
- * for static analysis only and one report for secrets only, they will have a different
17
- * service and env for each report so that they are not discarded later in our backend.
18
- *
19
- * @param filePath
20
- */
21
- export declare const getServiceFromSarifTool: (filePath: string) => string;
package/dist/utils.js DELETED
@@ -1,75 +0,0 @@
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.getServiceFromSarifTool = exports.SERVICE_THIRD_PARTY_ANALYZER = exports.SERVICE_DATADOG_ANALYZER_SECRETS_ONLY = exports.SERVICE_DATADOG_ANALYZER_SA_ONLY = exports.SERVICE_DATADOG_ANALYZER = exports.TAG_DATADOG_TYPE_TYPE_SECRET = exports.TAG_DATADOG_TYPE_TYPE_STATIC = exports.getBaseIntakeUrl = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const api_1 = require("@datadog/datadog-ci-base/helpers/api");
9
- const getBaseIntakeUrl = () => (0, api_1.getIntakeUrl)('cicodescan-intake');
10
- exports.getBaseIntakeUrl = getBaseIntakeUrl;
11
- exports.TAG_DATADOG_TYPE_TYPE_STATIC = 'DATADOG_RULE_TYPE:STATIC_ANALYSIS';
12
- exports.TAG_DATADOG_TYPE_TYPE_SECRET = 'DATADOG_RULE_TYPE:SECRET';
13
- exports.SERVICE_DATADOG_ANALYZER = 'datadog-analyzer';
14
- exports.SERVICE_DATADOG_ANALYZER_SA_ONLY = 'datadog-analyzer-sa-only';
15
- exports.SERVICE_DATADOG_ANALYZER_SECRETS_ONLY = 'datadog-analyzer-secrets-only';
16
- exports.SERVICE_THIRD_PARTY_ANALYZER = 'third-party-analyzer';
17
- /**
18
- * Define the service and env based on the SARIF contents reports
19
- * - if the report is produced by the datadog static analyzer, we look if the report
20
- * contains only static analysis or secrets errors and change service
21
- * - if the report is produced by a third party tool, we report it as is and cannot
22
- * infer the nature of the results. We still try to get the first tool from the runs.
23
- *
24
- * The objective of this function is to make sure that if a user uploads one report
25
- * for static analysis only and one report for secrets only, they will have a different
26
- * service and env for each report so that they are not discarded later in our backend.
27
- *
28
- * @param filePath
29
- */
30
- const getServiceFromSarifTool = (filePath) => {
31
- let otherTool = exports.SERVICE_THIRD_PARTY_ANALYZER;
32
- const ruleTypes = new Set();
33
- try {
34
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
35
- const report = JSON.parse(String(fs_1.default.readFileSync(filePath)));
36
- if ('runs' in report) {
37
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
38
- for (const run of report['runs']) {
39
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
40
- if ('tool' in run && 'driver' in run['tool'] && 'rules' in run['tool']['driver']) {
41
- for (const rule of run['tool']['driver']['rules']) {
42
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
43
- if ('properties' in rule && 'tags' in rule['properties']) {
44
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
45
- for (const tag of rule['properties']['tags']) {
46
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
47
- if (tag.includes('DATADOG_RULE_TYPE')) {
48
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
49
- ruleTypes.add(tag);
50
- }
51
- }
52
- }
53
- }
54
- }
55
- }
56
- }
57
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
58
- otherTool = report['runs'][0]['tool']['driver']['name'];
59
- }
60
- catch (error) {
61
- // ignore
62
- }
63
- if (ruleTypes.has(exports.TAG_DATADOG_TYPE_TYPE_STATIC) && ruleTypes.has(exports.TAG_DATADOG_TYPE_TYPE_SECRET)) {
64
- return exports.SERVICE_DATADOG_ANALYZER;
65
- }
66
- if (ruleTypes.has(exports.TAG_DATADOG_TYPE_TYPE_STATIC) && !ruleTypes.has(exports.TAG_DATADOG_TYPE_TYPE_SECRET)) {
67
- return exports.SERVICE_DATADOG_ANALYZER_SA_ONLY;
68
- }
69
- if (!ruleTypes.has(exports.TAG_DATADOG_TYPE_TYPE_STATIC) && ruleTypes.has(exports.TAG_DATADOG_TYPE_TYPE_SECRET)) {
70
- return exports.SERVICE_DATADOG_ANALYZER_SECRETS_ONLY;
71
- }
72
- return otherTool;
73
- };
74
- exports.getServiceFromSarifTool = getServiceFromSarifTool;
75
- //# sourceMappingURL=utils.js.map
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AAEnB,8DAAiE;A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5C,wGAAwG;gCACxG,IAAI,GAAG,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;oCACrC,iEAAiE;oCACjE,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;iCACnB;6BACF;yBACF;qBACF;iBACF;aACF;SACF;QAED,8GAA8G;QAC9G,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAA;KACxD;IAAC,OAAO,KAAK,EAAE;QACd,SAAS;KACV;IAED,IAAI,SAAS,CAAC,GAAG,CAAC,oCAA4B,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,oCAA4B,CAAC,EAAE;QAC9F,OAAO,gCAAwB,CAAA;KAChC;IAED,IAAI,SAAS,CAAC,GAAG,CAAC,oCAA4B,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,oCAA4B,CAAC,EAAE;QAC/F,OAAO,wCAAgC,CAAA;KACxC;IAED,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,oCAA4B,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,oCAA4B,CAAC,EAAE;QAC/F,OAAO,6CAAqC,CAAA;KAC7C;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAhDY,QAAA,uBAAuB,2BAgDnC"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Validate the SARIF file and check if the file is too large or not valid
3
- * against the SARIF schema.
4
- *
5
- * @param sarifReportPath - the path of the SARIF file
6
- */
7
- export declare const validateSarif: (sarifReportPath: string) => string | undefined;
8
- /**
9
- * Functions that looks for errors specific to how Datadog processes SARIF file. This way, we
10
- * show the error directly to the user instead of uploading a file we cannot process in our backend.
11
- *
12
- * The function returns a list of errors to show. The return value is empty if there is no error.
13
- *
14
- * @param filePath - the path of the SARIF file.
15
- */
16
- export declare const checkForError: (filePath: string) => string[];
@@ -1,102 +0,0 @@
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.checkForError = exports.validateSarif = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const ajv_1 = __importDefault(require("ajv"));
9
- const ajv_formats_1 = __importDefault(require("ajv-formats"));
10
- const sarif_schema_2_1_0_json_1 = __importDefault(require("./json-schema/sarif-schema-2.1.0.json"));
11
- const maxSarifFileSize = 100 * 1024 * 1024; // 100MB in bytes
12
- /**
13
- * Validate the SARIF file and check if the file is too large or not valid
14
- * against the SARIF schema.
15
- *
16
- * @param sarifReportPath - the path of the SARIF file
17
- */
18
- const validateSarif = (sarifReportPath) => {
19
- try {
20
- const stats = fs_1.default.statSync(sarifReportPath); // Synchronously get file stats
21
- const fileSize = stats.size;
22
- if (fileSize > maxSarifFileSize) {
23
- return `file size too large (size: ${fileSize / 1024 / 1024} MB, max size: ${maxSarifFileSize / 1024 / 1024} MB)`;
24
- }
25
- }
26
- catch (err) {
27
- return err.message;
28
- }
29
- const ajv = new ajv_1.default({ allErrors: true, validateFormats: false });
30
- (0, ajv_formats_1.default)(ajv);
31
- const sarifJsonSchemaValidate = ajv.compile(sarif_schema_2_1_0_json_1.default);
32
- try {
33
- const sarifReportContent = JSON.parse(String(fs_1.default.readFileSync(sarifReportPath)));
34
- const valid = sarifJsonSchemaValidate(sarifReportContent);
35
- if (!valid) {
36
- const errors = sarifJsonSchemaValidate.errors || [];
37
- const errorMessages = errors.map((error) => {
38
- return `${error.instancePath}: ${error.message}`;
39
- });
40
- return errorMessages.join('\n');
41
- }
42
- }
43
- catch (error) {
44
- return error.message;
45
- }
46
- return undefined;
47
- };
48
- exports.validateSarif = validateSarif;
49
- /**
50
- * Functions that looks for errors specific to how Datadog processes SARIF file. This way, we
51
- * show the error directly to the user instead of uploading a file we cannot process in our backend.
52
- *
53
- * The function returns a list of errors to show. The return value is empty if there is no error.
54
- *
55
- * @param filePath - the path of the SARIF file.
56
- */
57
- const checkForError = (filePath) => {
58
- const report = JSON.parse(String(fs_1.default.readFileSync(filePath)));
59
- const res = [];
60
- if ('runs' in report) {
61
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
62
- for (const run of report['runs']) {
63
- const rules = [];
64
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
65
- if ('tool' in run && 'driver' in run['tool'] && 'rules' in run['tool']['driver']) {
66
- for (const rule of run['tool']['driver']['rules']) {
67
- if ('id' in rule) {
68
- rules.push(rule['id']);
69
- }
70
- }
71
- }
72
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
73
- if ('tool' in run && 'extensions' in run['tool']) {
74
- for (const extension of run['tool']['extensions']) {
75
- if ('rules' in extension) {
76
- for (const rule of extension['rules']) {
77
- if ('id' in rule) {
78
- rules.push(rule['id']);
79
- }
80
- }
81
- }
82
- }
83
- }
84
- if ('results' in run) {
85
- for (const result of run['results']) {
86
- if (!('ruleId' in result)) {
87
- res.push('a result should have a ruleId');
88
- continue;
89
- }
90
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
91
- const ruleId = result['ruleId'];
92
- if (rules.indexOf(ruleId) === -1) {
93
- res.push(`result references rule ${ruleId} but rule not found in the tool section`);
94
- }
95
- }
96
- }
97
- }
98
- }
99
- return res;
100
- };
101
- exports.checkForError = checkForError;
102
- //# sourceMappingURL=validation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AAInB,8CAAqB;AACrB,8DAAoC;AAEpC,oGAAmE;AAEnE,MAAM,gBAAgB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAA,CAAC,iBAAiB;AAE5D;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,eAAuB,EAAsB,EAAE;IAC3E,IAAI;QACF,MAAM,KAAK,GAAG,YAAE,CA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