-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Entity Store] Store EUID Scripts #254515
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6b7fb23
[Entity Store] Store EUID Scripts
romulets ee16c41
[Entity Store] Fix type script constant map
romulets 15861a1
Merge branch 'main' into entity-create/store-scripts
romulets de9d42f
[Entity Store] Put initilization in a Promise.all set up
romulets 6606666
Merge branch 'main' into entity-create/store-scripts
romulets File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
45 changes: 45 additions & 0 deletions
45
x-pack/solutions/security/plugins/entity_store/server/domain/assets/euid_stored_scripts.ts
This file contains hidden or 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,45 @@ | ||
| /* | ||
| * 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 { ElasticsearchClient, Logger } from '@kbn/core/server'; | ||
| import { getEuidPainlessEvaluation } from '../../../common/domain/euid/painless'; | ||
| import type { EntityType } from '../../../common/domain/definitions/entity_schema'; | ||
| import { putStoredScript, deleteStoredScript } from '../../infra/elasticsearch/scripts'; | ||
|
|
||
| const storedScriptName: Record<EntityType, string> = { | ||
| user: 'euid_user_entity', | ||
| host: 'euid_host_entity', | ||
| service: 'euid_service_entity', | ||
| generic: 'euid_generic_entity', | ||
| } as const satisfies Record<EntityType, string>; | ||
|
|
||
| export async function installEuidStoredScripts({ | ||
| esClient, | ||
| logger, | ||
| }: { | ||
| esClient: ElasticsearchClient; | ||
| logger: Logger; | ||
| }) { | ||
| logger.debug('Installing/updating EUID stored scripts'); | ||
|
|
||
| for (const [type, name] of Object.entries(storedScriptName)) { | ||
| await putStoredScript(esClient, name, getEuidPainlessEvaluation(type as EntityType)); | ||
| } | ||
| } | ||
|
|
||
| export async function deleteEuidStoredScripts({ | ||
| esClient, | ||
| logger, | ||
| }: { | ||
| esClient: ElasticsearchClient; | ||
| logger: Logger; | ||
| }) { | ||
| logger.debug('Deleting EUID stored scripts'); | ||
| for (const name of Object.values(storedScriptName)) { | ||
| await deleteStoredScript(esClient, name); | ||
| } | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
x-pack/solutions/security/plugins/entity_store/server/infra/elasticsearch/scripts.ts
This file contains hidden or 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,26 @@ | ||
| /* | ||
| * 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 { ElasticsearchClient as EsClient } from '@kbn/core/server'; | ||
|
|
||
| export const putStoredScript = async ( | ||
| esClient: EsClient, | ||
| name: string, | ||
| painlessSource: string | ||
| ): Promise<void> => { | ||
| await esClient.putScript({ | ||
| id: name, | ||
| script: { | ||
| lang: 'painless', | ||
| source: painlessSource, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| export const deleteStoredScript = async (esClient: EsClient, name: string) => { | ||
| await esClient.deleteScript({ id: name }, { ignore: [404] }); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.