Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated js-yaml to v4 #190678

Merged
merged 18 commits into from
Sep 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replaced safeLoad, safeDump with load and dump
  • Loading branch information
elena-shostak committed Sep 18, 2024
commit ef700e1c611c5a308c19d8efbb95a55b825d521a
Original file line number Diff line number Diff line change
@@ -949,7 +949,7 @@ describe('EPM template', () => {
},
},
};
const fields: Field[] = safeLoad(nestedYaml);
const fields: Field[] = load(nestedYaml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(mappings).toEqual(expectedMapping);
@@ -978,7 +978,7 @@ describe('EPM template', () => {
},
},
};
const fields: Field[] = safeLoad(nestedYaml);
const fields: Field[] = load(nestedYaml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(mappings).toEqual(expectedMapping);
@@ -1014,7 +1014,7 @@ describe('EPM template', () => {
},
},
};
const fields: Field[] = safeLoad(nestedYaml);
const fields: Field[] = load(nestedYaml);
const processedFields = processFields(fields);
const mappings = generateMappings(processedFields);
expect(mappings).toEqual(expectedMapping);
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ export const readKibanaConfig = () => {
const kibanaDevConfig = path.join(kibanaConfigDir, 'kibana.dev.yml');
const kibanaConfig = path.join(kibanaConfigDir, 'kibana.yml');

const loadedKibanaConfig = (yaml.safeLoad(
const loadedKibanaConfig = (yaml.load(
fs.readFileSync(fs.existsSync(kibanaDevConfig) ? kibanaDevConfig : kibanaConfig, 'utf8')
) || {}) as {};

Original file line number Diff line number Diff line change
@@ -252,7 +252,7 @@ describe('renderPackageManifestYAML', () => {
const manifestContent = renderPackageManifestYAML(integration);

// The manifest content must be parseable as YAML.
const manifest = yaml.safeLoad(manifestContent);
const manifest = yaml.load(manifestContent);

expect(manifest).toBeDefined();
expect(manifest.title).toBe(integration.title);
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import AdmZip from 'adm-zip';
import nunjucks from 'nunjucks';
import { getDataPath } from '@kbn/utils';
import { join as joinPath } from 'path';
import { safeDump } from 'js-yaml';
import { dump } from 'js-yaml';
import type { DataStream, Integration } from '../../common';
import { createSync, ensureDirSync, generateUniqueId, removeDirSync } from '../util';
import { createAgentInput } from './agent';
@@ -228,7 +228,7 @@ export function renderPackageManifestYAML(integration: Integration): string {
uniqueInputsList // inputs
);

return safeDump(packageData);
return dump(packageData);
}

function createPackageManifest(packageDir: string, integration: Integration): void {
Original file line number Diff line number Diff line change
@@ -232,5 +232,5 @@ function encodeDiscoveryRulesYaml(discoveryRules: IDiscoveryRule[]): string {
[`${operation}-${type}`]: probe,
})
);
return yaml.safeDump(mappedDiscoveryRules);
return yaml.dump(mappedDiscoveryRules);
}
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ function ensureValidMultiText(textMultiValue: string[] | undefined) {

function escapeInvalidYamlString(yamlString: string) {
try {
yaml.safeLoad(yamlString);
yaml.load(yamlString);
} catch (error) {
if (error instanceof yaml.YAMLException) {
return `"${yamlString}"`;
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* 2.0.
*/

import { safeDump, safeLoad } from 'js-yaml';
import { dump, load } from 'js-yaml';

export const generateCustomLogsYml = ({
datasetName = '',
@@ -26,7 +26,7 @@ export const generateCustomLogsYml = ({
esHost: string[];
logfileId: string;
}) => {
const customConfigYaml = safeLoad(customConfigurations ?? '');
const customConfigYaml = load(customConfigurations ?? '');
const processors = [
{
add_fields: {
@@ -38,7 +38,7 @@ export const generateCustomLogsYml = ({
},
];

return safeDump({
return dump({
...{
outputs: {
default: {
Original file line number Diff line number Diff line change
@@ -557,7 +557,7 @@ const generateAgentConfigTar = ({
path: 'elastic-agent.yml',
mode: 0o644,
mtime: now,
data: safeDump({
data: dump({
outputs: {
default: {
type: 'elasticsearch',
@@ -578,7 +578,7 @@ const generateAgentConfigTar = ({
path: `inputs.d/${integration.pkgName}.yml`,
mode: 0o644,
mtime: now,
data: safeDump({ inputs: integration.inputs }),
data: dump({ inputs: integration.inputs }),
})),
]);
};
4 changes: 2 additions & 2 deletions x-pack/plugins/security_solution/scripts/beat_docs/build.js
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ const manageZipFields = async (beat, filePath, beatFields) => {
try {
await extract(filePath, { dir: beat.outputDir });
console.log('building fields', beat.index);
const obj = yaml.safeLoad(
const obj = yaml.load(
fs.readFileSync(`${beat.outputDir}/winlogbeat-${BEATS_VERSION}-windows-x86_64/fields.yml`, {
encoding: 'utf-8',
})
@@ -172,7 +172,7 @@ const manageTarFields = async (beat, filePath, beatFields) =>
return reject(new Error(err));
}
console.log('building fields', beat.index);
const obj = yaml.safeLoad(
const obj = yaml.load(
fs.readFileSync(`${beat.outputDir}/fields.yml`, { encoding: 'utf-8' })
);
const ebeatFields = convertSchemaToHash(obj, beatFields);
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
*/

import expect from '@kbn/expect';
import { safeLoad } from 'js-yaml';
import { load } from 'js-yaml';
import { FtrProviderContext } from '../../common/ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
@@ -39,7 +39,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

expect(req.status).to.be(200);

const ymlConfig = safeLoad(req.text);
const ymlConfig = load(req.text);
expect(ymlConfig.inputs[0].data_stream.namespace).to.be('');
expect(ymlConfig.inputs[0].streams[0].data_stream.dataset).to.be('');
expect(ymlConfig.inputs[0].streams[0].paths).to.be.empty();
@@ -75,7 +75,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

expect(req.status).to.be(200);

const ymlConfig = safeLoad(req.text);
const ymlConfig = load(req.text);
expect(ymlConfig.inputs[0].data_stream.namespace).to.be(namespace);
expect(ymlConfig.inputs[0].streams[0].data_stream.dataset).to.be(datasetName);
expect(ymlConfig.inputs[0].streams[0].paths).to.be.eql([logFilepath]);
@@ -107,7 +107,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

expect(req.status).to.be(200);

const ymlConfig = safeLoad(req.text);
const ymlConfig = load(req.text);
expect(ymlConfig.inputs[0].data_stream.namespace).to.be('default');
expect(ymlConfig.inputs[0].streams.length).to.be(2);
expect(ymlConfig.inputs[0].streams[0].data_stream.dataset).to.be('system.auth');
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import { REPO_ROOT } from '@kbn/repo-info';

const getYamlData = (filePath: string): any => {
const fileContents = fs.readFileSync(filePath, 'utf8');
return yaml.safeLoad(fileContents);
return yaml.load(fileContents);
};

const getRoleConfiguration = (role: string, filePath: string): any => {