Skip to content

Commit

Permalink
Match elastic/package-spec#50 config_templates->policy_templates
Browse files Browse the repository at this point in the history
…property renaming
  • Loading branch information
jen-huang committed Sep 28, 2020
1 parent 4c5e586 commit e0bb46d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PackageInfo, AgentPolicy, PackagePolicy } from '../types';

// Assume packages only ever include 1 config template for now
export const isPackageLimited = (packageInfo: PackageInfo): boolean => {
return packageInfo.config_templates?.[0]?.multiple === false;
return packageInfo.policy_templates?.[0]?.multiple === false;
};

export const doesAgentPolicyAlreadyIncludePackage = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
describe('packageToPackagePolicyInputs', () => {
it('returns empty array for packages with no config templates', () => {
expect(packageToPackagePolicyInputs(mockPackage)).toEqual([]);
expect(packageToPackagePolicyInputs({ ...mockPackage, config_templates: [] })).toEqual([]);
expect(packageToPackagePolicyInputs({ ...mockPackage, policy_templates: [] })).toEqual([]);
});

it('returns empty array for packages with a config template but no inputs', () => {
expect(
packageToPackagePolicyInputs(({
...mockPackage,
config_templates: [{ inputs: [] }],
policy_templates: [{ inputs: [] }],
} as unknown) as PackageInfo)
).toEqual([]);
});
Expand All @@ -50,13 +50,13 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
expect(
packageToPackagePolicyInputs(({
...mockPackage,
config_templates: [{ inputs: [{ type: 'foo' }] }],
policy_templates: [{ inputs: [{ type: 'foo' }] }],
} as unknown) as PackageInfo)
).toEqual([{ type: 'foo', enabled: true, streams: [] }]);
expect(
packageToPackagePolicyInputs(({
...mockPackage,
config_templates: [{ inputs: [{ type: 'foo' }, { type: 'bar' }] }],
policy_templates: [{ inputs: [{ type: 'foo' }, { type: 'bar' }] }],
} as unknown) as PackageInfo)
).toEqual([
{ type: 'foo', enabled: true, streams: [] },
Expand All @@ -73,7 +73,7 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
{ type: 'logs', dataset: 'bar', streams: [{ input: 'bar' }] },
{ type: 'logs', dataset: 'bar2', streams: [{ input: 'bar' }] },
],
config_templates: [
policy_templates: [
{
inputs: [{ type: 'foo' }, { type: 'bar' }],
},
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
],
},
],
config_templates: [
policy_templates: [
{
inputs: [{ type: 'foo' }, { type: 'bar' }],
},
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
],
},
],
config_templates: [
policy_templates: [
{
inputs: [
{
Expand Down Expand Up @@ -372,13 +372,13 @@ describe('Ingest Manager - packageToPackagePolicy', () => {
});
});
it('returns package policy with inputs', () => {
const mockPackageWithConfigTemplates = ({
const mockPackageWithPolicyTemplates = ({
...mockPackage,
config_templates: [{ inputs: [{ type: 'foo' }] }],
policy_templates: [{ inputs: [{ type: 'foo' }] }],
} as unknown) as PackageInfo;

expect(
packageToPackagePolicy(mockPackageWithConfigTemplates, '1', '2', 'default', 'pkgPolicy-1')
packageToPackagePolicy(mockPackageWithPolicyTemplates, '1', '2', 'default', 'pkgPolicy-1')
).toEqual({
policy_id: '1',
namespace: 'default',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import {
PackageInfo,
RegistryConfigTemplate,
RegistryPolicyTemplate,
RegistryVarsEntry,
RegistryStream,
PackagePolicy,
Expand Down Expand Up @@ -46,9 +46,9 @@ export const packageToPackagePolicyInputs = (packageInfo: PackageInfo): PackageP
const inputs: PackagePolicy['inputs'] = [];

// Assume package will only ever ship one package policy template for now
const packagePolicyTemplate: RegistryConfigTemplate | null =
packageInfo.config_templates && packageInfo.config_templates[0]
? packageInfo.config_templates[0]
const packagePolicyTemplate: RegistryPolicyTemplate | null =
packageInfo.policy_templates && packageInfo.policy_templates[0]
? packageInfo.policy_templates[0]
: null;

// Create package policy input property
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/ingest_manager/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface RegistryPackage {
internal?: boolean;
format_version: string;
data_streams?: RegistryDataStream[];
config_templates?: RegistryConfigTemplate[];
policy_templates?: RegistryPolicyTemplate[];
download: string;
path: string;
}
Expand All @@ -80,7 +80,7 @@ interface RegistryImage {
size?: string;
type?: string;
}
export interface RegistryConfigTemplate {
export interface RegistryPolicyTemplate {
name: string;
title: string;
description: string;
Expand Down Expand Up @@ -128,7 +128,7 @@ export type RegistrySearchResult = Pick<
| 'download'
| 'path'
| 'data_streams'
| 'config_templates'
| 'policy_templates'
>;

export type ScreenshotItem = RegistryImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PackageInfo,
InstallationStatus,
NewPackagePolicy,
RegistryConfigTemplate,
RegistryPolicyTemplate,
} from '../../../../types';
import { validatePackagePolicy, validationHasErrors } from './validate_package_policy';

Expand Down Expand Up @@ -90,7 +90,7 @@ describe('Ingest Manager - validatePackagePolicy()', () => {
],
},
],
config_templates: [
policy_templates: [
{
name: 'pkgPolicy1',
title: 'Package policy 1',
Expand Down Expand Up @@ -465,7 +465,7 @@ describe('Ingest Manager - validatePackagePolicy()', () => {
expect(
validatePackagePolicy(validPackagePolicy, {
...mockPackage,
config_templates: undefined,
policy_templates: undefined,
})
).toEqual({
name: null,
Expand All @@ -476,7 +476,7 @@ describe('Ingest Manager - validatePackagePolicy()', () => {
expect(
validatePackagePolicy(validPackagePolicy, {
...mockPackage,
config_templates: [],
policy_templates: [],
})
).toEqual({
name: null,
Expand All @@ -490,7 +490,7 @@ describe('Ingest Manager - validatePackagePolicy()', () => {
expect(
validatePackagePolicy(validPackagePolicy, {
...mockPackage,
config_templates: [{} as RegistryConfigTemplate],
policy_templates: [{} as RegistryPolicyTemplate],
})
).toEqual({
name: null,
Expand All @@ -501,7 +501,7 @@ describe('Ingest Manager - validatePackagePolicy()', () => {
expect(
validatePackagePolicy(validPackagePolicy, {
...mockPackage,
config_templates: [({ inputs: [] } as unknown) as RegistryConfigTemplate],
policy_templates: [({ inputs: [] } as unknown) as RegistryPolicyTemplate],
})
).toEqual({
name: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ export const validatePackagePolicy = (
}

if (
!packageInfo.config_templates ||
packageInfo.config_templates.length === 0 ||
!packageInfo.config_templates[0] ||
!packageInfo.config_templates[0].inputs ||
packageInfo.config_templates[0].inputs.length === 0
!packageInfo.policy_templates ||
packageInfo.policy_templates.length === 0 ||
!packageInfo.policy_templates[0] ||
!packageInfo.policy_templates[0].inputs ||
packageInfo.policy_templates[0].inputs.length === 0
) {
validationResults.inputs = null;
return validationResults;
Expand All @@ -87,7 +87,7 @@ export const validatePackagePolicy = (
const registryInputsByType: Record<
string,
RegistryInput
> = packageInfo.config_templates[0].inputs.reduce((inputs, registryInput) => {
> = packageInfo.policy_templates[0].inputs.reduce((inputs, registryInput) => {
inputs[registryInput.type] = registryInput;
return inputs;
}, {} as Record<string, RegistryInput>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export const StepConfigurePackagePolicy: React.FunctionComponent<{
// Configure inputs (and their streams)
// Assume packages only export one config template for now
const renderConfigureInputs = () =>
packageInfo.config_templates &&
packageInfo.config_templates[0] &&
packageInfo.config_templates[0].inputs &&
packageInfo.config_templates[0].inputs.length ? (
packageInfo.policy_templates &&
packageInfo.policy_templates[0] &&
packageInfo.policy_templates[0].inputs &&
packageInfo.policy_templates[0].inputs.length ? (
<>
<EuiHorizontalRule margin="m" />
<EuiFlexGroup direction="column" gutterSize="none">
{packageInfo.config_templates[0].inputs.map((packageInput) => {
{packageInfo.policy_templates[0].inputs.map((packageInput) => {
const packagePolicyInput = packagePolicy.inputs.find(
(input) => input.type === packageInput.type
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export {
RegistryVarsEntry,
RegistryInput,
RegistryStream,
RegistryConfigTemplate,
RegistryPolicyTemplate,
PackageList,
PackageListItem,
PackagesGroupedByStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Package policy service', () => {
streams: [{ input: 'log', template_path: 'some_template_path.yml' }],
},
],
config_templates: [
policy_templates: [
{
inputs: [{ type: 'log' }],
},
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('Package policy service', () => {
streams: [{ input: 'log', template_path: 'some_template_path.yml' }],
},
],
config_templates: [
policy_templates: [
{
inputs: [{ type: 'log' }],
},
Expand Down

0 comments on commit e0bb46d

Please sign in to comment.