Skip to content
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] Allow integrations on hosted policies to be updated #96705

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions x-pack/plugins/fleet/server/services/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,14 @@ class PackagePolicyService {
const parentAgentPolicy = await agentPolicyService.get(soClient, packagePolicy.policy_id);
if (!parentAgentPolicy) {
throw new Error('Agent policy not found');
} else {
if (parentAgentPolicy.is_managed) {
throw new IngestManagerError(`Cannot update integrations of managed policy ${id}`);
}
if (
(parentAgentPolicy.package_policies as PackagePolicy[]).find(
(siblingPackagePolicy) =>
siblingPackagePolicy.id !== id && siblingPackagePolicy.name === packagePolicy.name
)
) {
throw new Error('There is already a package with the same name on this agent policy');
}
}
if (
(parentAgentPolicy.package_policies as PackagePolicy[]).find(
(siblingPackagePolicy) =>
siblingPackagePolicy.id !== id && siblingPackagePolicy.name === packagePolicy.name
)
) {
throw new Error('There is already a package with the same name on this agent policy');
}

let inputs = restOfPackagePolicy.inputs.map((input) =>
Expand Down
16 changes: 6 additions & 10 deletions x-pack/test/fleet_api_integration/apis/package_policy/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';

Expand Down Expand Up @@ -115,15 +114,15 @@ export default function (providerContext: FtrProviderContext) {
await getService('esArchiver').unload('empty_kibana');
});

it('should fail on managed agent policies', async function () {
const { body } = await supertest
it('should work with valid values on "regular" policies', async function () {
await supertest
.put(`/api/fleet/package_policies/${packagePolicyId}`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'filetest-1',
description: '',
namespace: 'updated_namespace',
policy_id: managedAgentPolicyId,
policy_id: agentPolicyId,
enabled: true,
output_id: '',
inputs: [],
Expand All @@ -132,21 +131,18 @@ export default function (providerContext: FtrProviderContext) {
title: 'For File Tests',
version: '0.1.0',
},
})
.expect(400);

expect(body.message).to.contain('Cannot update integrations of managed policy');
});
});

it('should work with valid values', async function () {
it('should work with valid values on hosted policies', async function () {
await supertest
.put(`/api/fleet/package_policies/${packagePolicyId}`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'filetest-1',
description: '',
namespace: 'updated_namespace',
policy_id: agentPolicyId,
policy_id: managedAgentPolicyId,
enabled: true,
output_id: '',
inputs: [],
Expand Down