From e9a32eb3bfc542187c63a5c8b1cf55098e12e1e1 Mon Sep 17 00:00:00 2001 From: John Schulz Date: Fri, 9 Apr 2021 12:07:29 -0400 Subject: [PATCH] Allow integrations of hosted policies to be updated --- .../fleet/server/services/package_policy.ts | 20 ++++++++----------- .../apis/package_policy/update.ts | 16 ++++++--------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/package_policy.ts b/x-pack/plugins/fleet/server/services/package_policy.ts index 418a10225edad..210c9128b1ec7 100644 --- a/x-pack/plugins/fleet/server/services/package_policy.ts +++ b/x-pack/plugins/fleet/server/services/package_policy.ts @@ -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) => diff --git a/x-pack/test/fleet_api_integration/apis/package_policy/update.ts b/x-pack/test/fleet_api_integration/apis/package_policy/update.ts index 3e652d47ac425..6e6a475cd4824 100644 --- a/x-pack/test/fleet_api_integration/apis/package_policy/update.ts +++ b/x-pack/test/fleet_api_integration/apis/package_policy/update.ts @@ -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'; @@ -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: [], @@ -132,13 +131,10 @@ 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') @@ -146,7 +142,7 @@ export default function (providerContext: FtrProviderContext) { name: 'filetest-1', description: '', namespace: 'updated_namespace', - policy_id: agentPolicyId, + policy_id: managedAgentPolicyId, enabled: true, output_id: '', inputs: [],