Skip to content
Merged
4 changes: 2 additions & 2 deletions x-pack/plugins/ingest_manager/common/openapi/spec_oas3.json
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@
},
"parameters": []
},
"/packageConfigs": {
"/package_configs": {
"get": {
"summary": "PackageConfigs - List",
"tags": [],
Expand Down Expand Up @@ -1237,7 +1237,7 @@
]
}
},
"/packageConfigs/{packageConfigId}": {
"/package_configs/{packageConfigId}": {
"get": {
"summary": "PackageConfigs - Info",
"tags": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { TypeOf } from '@kbn/config-schema';
import Boom from 'boom';
import { RequestHandler } from 'src/core/server';
import { RequestHandler, SavedObjectsErrorHelpers } from '../../../../../../src/core/server';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the relative path here because I was getting an error like "cannot find module 'src/core/server'" when I added the helpers

import { appContextService, packageConfigService } from '../../services';
import { getPackageInfo } from '../../services/epm/packages';
import {
Expand Down Expand Up @@ -49,26 +49,31 @@ export const getOnePackageConfigHandler: RequestHandler<TypeOf<
typeof GetOnePackageConfigRequestSchema.params
>> = async (context, request, response) => {
const soClient = context.core.savedObjects.client;
const { packageConfigId } = request.params;
const notFoundResponse = () =>
response.notFound({ body: { message: `Package config ${packageConfigId} not found` } });

try {
const packageConfig = await packageConfigService.get(soClient, request.params.packageConfigId);
const packageConfig = await packageConfigService.get(soClient, packageConfigId);
if (packageConfig) {
return response.ok({
body: {
item: packageConfig,
success: true,
},
});
} else {
return notFoundResponse();
}
} catch (e) {
if (SavedObjectsErrorHelpers.isNotFoundError(e)) {
return notFoundResponse();
} else {
return response.customError({
statusCode: 404,
body: { message: 'Package config not found' },
statusCode: 500,
body: { message: e.message },
});
}
} catch (e) {
return response.customError({
statusCode: 500,
body: { message: e.message },
});
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class AgentConfigService {
throw new Error('Agent configuration not found');
}

const defaultConfigId = await this.getDefaultAgentConfigId(soClient);
const { id: defaultConfigId } = await this.ensureDefaultAgentConfig(soClient);
if (id === defaultConfigId) {
throw new Error('The default agent configuration cannot be deleted');
}
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/ingest_manager_api_integration/apis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function ({ loadTestFile }) {
// Package configs
loadTestFile(require.resolve('./package_config/create'));
loadTestFile(require.resolve('./package_config/update'));
loadTestFile(require.resolve('./package_config/get'));
// Agent config
loadTestFile(require.resolve('./agent_config/index'));
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';

export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;
const supertest = getService('supertest');
const dockerServers = getService('dockerServers');

const server = dockerServers.get('registry');
// use function () {} and not () => {} here
// because `this` has to point to the Mocha context
// see https://mochajs.org/#arrow-functions

describe('Package Config - get by id', async function () {
skipIfNoDockerRegistry(providerContext);
let agentConfigId: string;
let packageConfigId: string;

before(async function () {
if (!server.enabled) {
return;
}
const { body: agentConfigResponse } = await supertest
.post(`/api/ingest_manager/agent_configs`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'Test config',
namespace: 'default',
});
agentConfigId = agentConfigResponse.item.id;

const { body: packageConfigResponse } = await supertest
.post(`/api/ingest_manager/package_configs`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'filetest-1',
description: '',
namespace: 'default',
config_id: agentConfigId,
enabled: true,
output_id: '',
inputs: [],
package: {
name: 'filetest',
title: 'For File Tests',
version: '0.1.0',
},
});
packageConfigId = packageConfigResponse.item.id;
});

after(async function () {
if (!server.enabled) {
return;
}

await supertest
.post(`/api/ingest_manager/agent_configs/delete`)
.set('kbn-xsrf', 'xxxx')
.send({ agentConfigId })
.expect(200);

await supertest
.post(`/api/ingest_manager/package_configs/delete`)
.set('kbn-xsrf', 'xxxx')
.send({ packageConfigIds: [packageConfigId] })
.expect(200);
});

it('should succeed with a valid id', async function () {
const { body: apiResponse } = await supertest
.get(`/api/ingest_manager/package_configs/${packageConfigId}`)
.expect(200);

expect(apiResponse.success).to.be(true);
});

it('should return a 404 with an invalid id', async function () {
await supertest.get(`/api/ingest_manager/package_configs/IS_NOT_PRESENT`).expect(404);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await pageObjects.policy.navigateToPolicyDetails('invalid-id');
await testSubjects.existOrFail('policyDetailsIdNotFoundMessage');
expect(await testSubjects.getVisibleText('policyDetailsIdNotFoundMessage')).to.equal(
'Saved object [ingest-package-configs/invalid-id] not found'
'Package config invalid-id not found'
);
});
});
Expand Down