Skip to content

Commit

Permalink
[8.7] [Security Solutions][Endpoint] Use id instead of identifier to …
Browse files Browse the repository at this point in the history
…get fleet artifact (#154810) (#154837)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[Security Solutions][Endpoint] Use id instead of identifier to get
fleet artifact (#154810)](#154810)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"David
Sánchez","email":"david.sanchezsoler@elastic.co"},"sourceCommit":{"committedDate":"2023-04-12T15:54:21Z","message":"[Security
Solutions][Endpoint] Use id instead of identifier to get fleet artifact
(#154810)\n\n## Summary\r\n\r\nGet fleet artifacts by `artifact.id`
instead of by `artifact.identifier`\r\nbefore pushing them to the
endpoint manifest.\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"fbe024306c37bd87d9c2d4a1bab45b89fb148e77","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Defend
Workflows","v8.8.0","v8.7.1"],"number":154810,"url":"#154810
Solutions][Endpoint] Use id instead of identifier to get fleet artifact
(#154810)\n\n## Summary\r\n\r\nGet fleet artifacts by `artifact.id`
instead of by `artifact.identifier`\r\nbefore pushing them to the
endpoint manifest.\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"fbe024306c37bd87d9c2d4a1bab45b89fb148e77"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"#154810
Solutions][Endpoint] Use id instead of identifier to get fleet artifact
(#154810)\n\n## Summary\r\n\r\nGet fleet artifacts by `artifact.id`
instead of by `artifact.identifier`\r\nbefore pushing them to the
endpoint manifest.\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"fbe024306c37bd87d9c2d4a1bab45b89fb148e77"}},{"branch":"8.7","label":"v8.7.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: David Sánchez <david.sanchezsoler@elastic.co>
  • Loading branch information
kibanamachine and dasansol92 committed Apr 12, 2023
1 parent b69320b commit 79a4c93
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pMap from 'p-map';
import semver from 'semver';
import type LRU from 'lru-cache';
import { isEqual, isEmpty, keyBy } from 'lodash';
import { isEqual, isEmpty } from 'lodash';
import { type Logger, type SavedObjectsClientContract } from '@kbn/core/server';
import {
ENDPOINT_EVENT_FILTERS_LIST_ID,
Expand Down Expand Up @@ -365,11 +365,15 @@ export class ManifestManager {
}

if (fleetArtifacts) {
const fleetArtfactsByIdentifier = keyBy(fleetArtifacts, 'identifier');
const fleetArtfactsByIdentifier: { [key: string]: InternalArtifactCompleteSchema } = {};
fleetArtifacts.forEach((fleetArtifact) => {
fleetArtfactsByIdentifier[getArtifactId(fleetArtifact)] = fleetArtifact;
});
artifactsToCreate.forEach((artifact) => {
const fleetArtifact = fleetArtfactsByIdentifier[artifact.identifier];
if (!fleetArtifact) return;
const artifactId = getArtifactId(artifact);
const fleetArtifact = fleetArtfactsByIdentifier[artifactId];

if (!fleetArtifact) return;
// Cache the compressed body of the artifact
this.cache.set(artifactId, Buffer.from(artifact.body, 'base64'));
newManifest.replaceArtifact(fleetArtifact);
Expand Down

0 comments on commit 79a4c93

Please sign in to comment.