-
Notifications
You must be signed in to change notification settings - Fork 8k
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
[Fleet] Create and update package policy API return 409 conflict when names are not unique #153533
Conversation
… names are not unique
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
Pinging @elastic/fleet (Team:Fleet) |
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.
Nice! Thanks for the refactor along the way 🚀
) { | ||
const existingPoliciesWithName = await packagePolicyService.list(soClient, { | ||
perPage: SO_SEARCH_LIMIT, | ||
kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.name:"${packagePolicy.name}"`, |
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: This logic could be simplified to use ES kuery to filter out the same id, and could use the total count without any hits.
Probably not a huge gain as there will be at least 1 matches, just some code simplification.
Something like:
const existingPoliciesWithName = await packagePolicyService.list(soClient, {
perPage: 0,
kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.name:"${packagePolicy.name}" AND NOT (${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.id:"${packagePolicy.id}")`,
});
if (existingPoliciesWithName?.total > 0) {
throw ...
}
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.
Thanks Julia! Since the gain it's not very big I'm going to merge as it is, but we can do this change the next time we touch this area :)
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.
LGTM
💚 Build Succeeded
Metrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
To update your PR or re-run it, just comment with: cc @criamico |
Closes #153026
Summary
The agent policy API returns a 409 in the case the policy already exists. The package policy API will now follow the same behavior.
Checklist
Delete any items that are not applicable to this PR.