Skip to content

Commit

Permalink
[Integration Assistant] Prevent wrongly formatted pipelines (elastic#…
Browse files Browse the repository at this point in the history
…190626)

## Summary

This PR resolves certain scenarios causing the ingest pipeline to be
malformed when generated.
  • Loading branch information
P1llus authored Aug 15, 2024
1 parent c2fc468 commit c00a061
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

0 comments on commit c00a061

Please sign in to comment.