[Fleet] Support id when creating a package policy through API (#161306)

This commit is contained in:
Nicolas Chaulet 2023-07-06 10:06:14 -04:00 committed by GitHub
parent 099835fad5
commit fe0779e522
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 3 deletions

View file

@ -220,7 +220,7 @@ export const createPackagePolicyHandler: FleetRequestHandler<
const soClient = fleetContext.internalSoClient;
const esClient = coreContext.elasticsearch.client.asInternalUser;
const user = appContextService.getSecurity()?.authc.getCurrentUser(request) || undefined;
const { force, package: pkg, ...newPolicy } = request.body;
const { force, id, package: pkg, ...newPolicy } = request.body;
const authorizationHeader = HTTPAuthorizationHeader.parseFromRequest(request, user?.username);
if ('output_id' in newPolicy) {
@ -252,13 +252,12 @@ export const createPackagePolicyHandler: FleetRequestHandler<
}
// Create package policy
const packagePolicy = await fleetContext.packagePolicyService.asCurrentUser.create(
soClient,
esClient,
newPackagePolicy,
{
user,
id,
force,
spaceId,
authorizationHeader,

View file

@ -539,6 +539,37 @@ export default function (providerContext: FtrProviderContext) {
});
describe('Simplified package policy', () => {
it('should support providing an id', async () => {
const id = `test-id-${Date.now()}`;
await supertest
.post(`/api/fleet/package_policies`)
.set('kbn-xsrf', 'xxxx')
.send({
id,
name: `create-simplified-package-policy-required-variables-${Date.now()}`,
description: '',
namespace: 'default',
policy_id: agentPolicyId,
inputs: {
'with_required_variables-test_input': {
streams: {
'with_required_variables.log': {
vars: { test_var_required: 'I am required' },
},
},
},
},
package: {
name: 'with_required_variables',
version: '0.1.0',
},
})
.expect(200);
await await supertest.get(`/api/fleet/package_policies/${id}`).expect(200);
});
it('should work with valid values', async () => {
await supertest
.post(`/api/fleet/package_policies`)