-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Fix loading fields for transform destination index template (#…
- Loading branch information
Showing
6 changed files
with
167 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/mappings.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { loadMappingForTransform } from './mappings'; | ||
|
||
describe('loadMappingForTransform', () => { | ||
it('should return a mappings without properties if there is no fields resource', () => { | ||
const fields = loadMappingForTransform( | ||
{ | ||
packageInfo: {} as any, | ||
assetsMap: new Map(), | ||
paths: [], | ||
}, | ||
'test' | ||
); | ||
|
||
expect(fields).toEqual({ properties: {} }); | ||
}); | ||
|
||
it('should merge shallow mapping without properties if there is no fields resource', () => { | ||
const fields = loadMappingForTransform( | ||
{ | ||
packageInfo: {} as any, | ||
assetsMap: new Map([ | ||
[ | ||
'/package/ti_opencti/2.1.0/elasticsearch/transform/latest_ioc/fields/ecs.yml', | ||
Buffer.from( | ||
` | ||
- description: Description of the threat feed in a UI friendly format. | ||
name: threat.feed.description | ||
type: keyword | ||
- description: The name of the threat feed in UI friendly format. | ||
name: threat.feed.name | ||
type: keyword` | ||
), | ||
], | ||
[ | ||
'/package/ti_opencti/2.1.0/elasticsearch/transform/latest_ioc/fields/ecs-extra.yml', | ||
Buffer.from( | ||
` | ||
- description: The display name indicator in an UI friendly format | ||
level: extended | ||
name: threat.indicator.name | ||
type: keyword` | ||
), | ||
], | ||
]), | ||
paths: [ | ||
'/package/ti_opencti/2.1.0/elasticsearch/transform/latest_ioc/fields/ecs.yml', | ||
'/package/ti_opencti/2.1.0/elasticsearch/transform/latest_ioc/fields/ecs-extra.yml', | ||
], | ||
}, | ||
'latest_ioc' | ||
); | ||
|
||
expect(fields).toMatchInlineSnapshot(` | ||
Object { | ||
"properties": Object { | ||
"threat": Object { | ||
"properties": Object { | ||
"feed": Object { | ||
"properties": Object { | ||
"description": Object { | ||
"ignore_above": 1024, | ||
"type": "keyword", | ||
}, | ||
"name": Object { | ||
"ignore_above": 1024, | ||
"type": "keyword", | ||
}, | ||
}, | ||
}, | ||
"indicator": Object { | ||
"properties": Object { | ||
"name": Object { | ||
"ignore_above": 1024, | ||
"type": "keyword", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/mappings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { type PackageInstallContext } from '../../../../../common/types/models'; | ||
import { loadTransformFieldsFromYaml, processFields } from '../../fields/field'; | ||
import { generateMappings } from '../template/template'; | ||
|
||
export function loadMappingForTransform( | ||
packageInstallContext: PackageInstallContext, | ||
transformModuleId: string | ||
) { | ||
const fields = loadTransformFieldsFromYaml(packageInstallContext, transformModuleId); | ||
const validFields = processFields(fields); | ||
return generateMappings(validFields); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters