-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution][Endpoint] Potential improvements in endpoint user artifact packager #160387
Changes from all commits
7aed42e
7f3cc68
d768630
11eed82
f54a82c
9608d18
14cd787
ca73b54
61b8331
57df8f2
6c48302
805f152
287f839
efca38d
0f7ae0b
cd628a2
ad11a8f
26e99fc
07f122e
74bca2b
88d5d70
dce6775
92b521b
5c9ef42
21041b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,6 +197,37 @@ export const deleteArtifact = async (esClient: ElasticsearchClient, id: string): | |
} | ||
}; | ||
|
||
export const bulkDeleteArtifacts = async ( | ||
esClient: ElasticsearchClient, | ||
ids: string[] | ||
): Promise<Error[]> => { | ||
try { | ||
const body = ids.map((id) => ({ | ||
delete: { _index: FLEET_SERVER_ARTIFACTS_INDEX, _id: id }, | ||
})); | ||
|
||
const res = await withPackageSpan(`Bulk delete fleet artifacts`, () => | ||
esClient.bulk({ | ||
body, | ||
refresh: 'wait_for', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't wait for the deletions to be done, then the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Thanks. |
||
}) | ||
); | ||
let errors: Error[] = []; | ||
// Track errors of the bulk delete action | ||
if (res.errors) { | ||
errors = res.items.reduce<Error[]>((acc, item) => { | ||
if (item.delete?.error) { | ||
acc.push(new Error(item.delete.error.reason)); | ||
} | ||
return acc; | ||
}, []); | ||
} | ||
return errors; | ||
} catch (e) { | ||
throw new ArtifactsElasticsearchError(e); | ||
} | ||
}; | ||
|
||
export const listArtifacts = async ( | ||
esClient: ElasticsearchClient, | ||
options: ListArtifactsProps = {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,3 +82,7 @@ export const uniqueIdFromArtifact = < | |
}: T): string => { | ||
return `${packageName}:${identifier}-${decodedSha256}`; | ||
}; | ||
|
||
export const uniqueIdFromId = (id: string, packageName: string): string => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The id of the artifact without the packageName, so it adds the packageName to the current id as an ES id: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also rename this to |
||
return `${packageName}:${id}`; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
body
is deprecated overoperations
forbulk
. You can renamebody
tooperations
. You can change the otherbulk
calls in the file as well.Similarly, the
create
method (used increateArtifact
) prefersdocument
instead of abody
in the request, and thesearch
(used inlistArtifacts
) method acceptssort
directly in the request instead of being nested inside abody
.