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

[Fleet] Honor registry datastream source_mode in package policy editor UI #147034

Merged
merged 8 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
packageToPackagePolicyInputs,
packageToPackagePolicy,
getStreamsForInputType,
getRegistryStreamWithDataStreamForInputType,
} from './package_to_package_policy';
export { fullAgentPolicyToYaml } from './full_agent_policy_to_yaml';
export { isPackageLimited, doesAgentPolicyAlreadyIncludePackage } from './limited_package';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
NewPackagePolicyInputStream,
NewPackagePolicy,
PackagePolicyConfigRecordEntry,
RegistryStreamWithDataStream,
} from '../types';

import { doesPackageHaveIntegrations } from '.';
Expand All @@ -24,7 +25,7 @@ import {
isIntegrationPolicyTemplate,
} from './policy_template';

type PackagePolicyStream = RegistryStream & { release?: 'beta' | 'experimental' | 'ga' } & {
type PackagePolicyStream = RegistryStream & {
data_stream: { type: string; dataset: string };
};

Expand All @@ -48,7 +49,33 @@ export const getStreamsForInputType = (
type: dataStream.type,
dataset: dataStream.dataset,
},
release: dataStream.release,
});
}
});
});

return streams;
};

export const getRegistryStreamWithDataStreamForInputType = (
inputType: string,
packageInfo: PackageInfo,
dataStreamPaths: string[] = []
): RegistryStreamWithDataStream[] => {
const streams: RegistryStreamWithDataStream[] = [];
const dataStreams = getNormalizedDataStreams(packageInfo);
const dataStreamsToSearch = dataStreamPaths.length
? dataStreams.filter((dataStream) => dataStreamPaths.includes(dataStream.path))
: dataStreams;

dataStreamsToSearch.forEach((dataStream) => {
(dataStream.streams || []).forEach((stream) => {
if (stream.input === inputType) {
streams.push({
...stream,
data_stream: {
...dataStream,
},
});
}
});
Expand Down Expand Up @@ -113,7 +140,6 @@ export const packageToPackagePolicyInputs = (
const stream: NewPackagePolicyInputStream = {
enabled: packageStream.enabled === false ? false : true,
data_stream: packageStream.data_stream,
release: packageStream.release,
};
if (packageStream.vars && packageStream.vars.length) {
stream.vars = packageStream.vars.reduce(varsReducer, {});
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ export interface RegistryStream {
[RegistryStreamKeys.template_path]: string;
}

export type RegistryStreamWithDataStream = RegistryStream & { data_stream: RegistryDataStream };

export type RequirementVersion = string;
export type RequirementVersionRange = string;
export interface ServiceRequirements {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface NewPackagePolicyInputStream {
indices?: string[];
};
index_mode?: string;
source_mode?: string;
};
};
release?: RegistryRelease;
Expand Down
Loading