mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Fleet] Support id when creating a package policy through API (#161306)
This commit is contained in:
parent
099835fad5
commit
fe0779e522
2 changed files with 33 additions and 3 deletions
|
@ -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,
|
||||
|
|
|
@ -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`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue