Skip to content

Commit

Permalink
Account for if a stream is enabled by default from registry package d…
Browse files Browse the repository at this point in the history
…efinition: elastic#59724
  • Loading branch information
jen-huang committed Mar 10, 2020
1 parent e38cc50 commit 017aaf2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
60 changes: 31 additions & 29 deletions x-pack/plugins/ingest_manager/common/services/package_to_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,39 @@ export const packageToConfigDatasourceInputs = (packageInfo: PackageInfo): Datas
if (packageDatasource?.inputs?.length) {
// Map each package datasource input to agent config datasource input
packageDatasource.inputs.forEach(packageInput => {
// Map each package input stream into datasource input stream
const streams: DatasourceInputStream[] = packageInput.streams
? packageInput.streams.map(packageStream => {
// Copy input vars into each stream's vars
const streamVars: RegistryVarsEntry[] = [
...(packageInput.vars || []),
...(packageStream.vars || []),
];
const streamConfig = {};
const streamVarsReducer = (
configObject: DatasourceInputStream['config'],
streamVar: RegistryVarsEntry
): DatasourceInputStream['config'] => {
if (!streamVar.default && streamVar.multi) {
configObject![streamVar.name] = [];
} else {
configObject![streamVar.name] = streamVar.default;
}
return configObject;
};
return {
id: `${packageInput.type}-${packageStream.dataset}`,
enabled: packageStream.enabled === false ? false : true,
dataset: packageStream.dataset,
config: streamVars.reduce(streamVarsReducer, streamConfig),
};
})
: [];

const input: DatasourceInput = {
type: packageInput.type,
enabled: true,
// Map each package input stream into datasource input stream
streams: packageInput.streams
? packageInput.streams.map(packageStream => {
// Copy input vars into each stream's vars
const streamVars: RegistryVarsEntry[] = [
...(packageInput.vars || []),
...(packageStream.vars || []),
];
const streamConfig = {};
const streamVarsReducer = (
configObject: DatasourceInputStream['config'],
streamVar: RegistryVarsEntry
): DatasourceInputStream['config'] => {
if (!streamVar.default && streamVar.multi) {
configObject![streamVar.name] = [];
} else {
configObject![streamVar.name] = streamVar.default;
}
return configObject;
};
return {
id: `${packageInput.type}-${packageStream.dataset}`,
enabled: true,
dataset: packageStream.dataset,
config: streamVars.reduce(streamVarsReducer, streamConfig),
};
})
: [],
enabled: streams.length ? !!streams.find(stream => stream.enabled) : true,
streams,
};

inputs.push(input);
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_manager/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface RegistryStream {
dataset: string;
title: string;
description?: string;
enabled?: boolean;
vars?: RegistryVarsEntry[];
}

Expand Down

0 comments on commit 017aaf2

Please sign in to comment.