[Integration Assistant] Prevent wrongly formatted pipelines (#190626)

## Summary

This PR resolves certain scenarios causing the ingest pipeline to be
malformed when generated.
This commit is contained in:
Marius Iversen 2024-08-15 19:44:21 +02:00 committed by GitHub
parent c2fc468638
commit c00a06164a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 6 additions and 6 deletions

View file

@ -5,7 +5,7 @@
* 2.0.
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
import { load } from 'js-yaml';
import { safeLoad } from 'js-yaml';
import { Environment, FileSystemLoader } from 'nunjucks';
import { join as joinPath } from 'path';
import type { EcsMappingState } from '../../types';
@ -185,6 +185,6 @@ export function createPipeline(state: EcsMappingState): IngestPipeline {
});
const template = env.getTemplate('pipeline.yml.njk');
const renderedTemplate = template.render(mappedValues);
const ingestPipeline = load(renderedTemplate) as IngestPipeline;
const ingestPipeline = safeLoad(renderedTemplate) as IngestPipeline;
return ingestPipeline;
}

View file

@ -11,6 +11,6 @@ import { createSync } from '../util';
export function createPipeline(specificDataStreamDir: string, pipeline: object): void {
const filePath = joinPath(specificDataStreamDir, 'elasticsearch/ingest_pipeline/default.yml');
const yamlContent = `---\n${yaml.dump(pipeline, { sortKeys: false })}`;
const yamlContent = `---\n${yaml.safeDump(pipeline, { sortKeys: false })}`;
createSync(filePath, yamlContent);
}

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { load } from 'js-yaml';
import { safeLoad } from 'js-yaml';
import { join as joinPath } from 'path';
import { Environment, FileSystemLoader } from 'nunjucks';
import { deepCopy } from './util';
@ -43,6 +43,6 @@ function createAppendProcessors(processors: SimplifiedProcessors): ESProcessorIt
});
const template = env.getTemplate('append.yml.njk');
const renderedTemplate = template.render({ processors });
const appendProcessors = load(renderedTemplate) as ESProcessorItem[];
const appendProcessors = safeLoad(renderedTemplate) as ESProcessorItem[];
return appendProcessors;
}

View file

@ -203,5 +203,5 @@ export function generateFields(mergedDocs: string): string {
.filter((key) => !ecsTopKeysSet.has(key))
.map((key) => recursiveParse(doc[key], [key]));
return yaml.dump(fieldsStructure, { sortKeys: false });
return yaml.safeDump(fieldsStructure, { sortKeys: false });
}