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

[Ingest Manager] Rename API /api/ingest_manager => /api/fleet #79193

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'master' of github.com:elastic/kibana into feature-inges…
…tmanager-fleet-api-renaming
  • Loading branch information
nchaulet committed Oct 5, 2020
commit 6515f6a30ea9444944ec8f87d4c2ffef0731977e
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_manager/common/constants/routes.ts
Original file line number Diff line number Diff line change
@@ -92,6 +92,7 @@ export const AGENT_API_ROUTES = {
BULK_REASSIGN_PATTERN: `${API_ROOT}/agents/bulk_reassign`,
STATUS_PATTERN: `${API_ROOT}/agent-status`,
UPGRADE_PATTERN: `${API_ROOT}/agents/{agentId}/upgrade`,
BULK_UPGRADE_PATTERN: `${API_ROOT}/agents/bulk_upgrade`,
};
export const AGENT_API_ROUTES_7_9 = {
CHECKIN_PATTERN: `${FLEET_API_ROOT_7_9}/agents/{agentId}/checkin`,
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_manager/server/routes/agent/index.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import {
AGENT_API_ROUTES,
AGENT_API_ROUTES_7_9,
LIMITED_CONCURRENCY_ROUTE_TAG,
AGENT_POLLING_REQUEST_TIMEOUT_MARGIN_MS,
} from '../../constants';
import {
GetAgentsRequestSchema,
124 changes: 110 additions & 14 deletions x-pack/test/ingest_manager_api_integration/apis/epm/install_by_upload.ts
Original file line number Diff line number Diff line change
@@ -62,20 +62,116 @@ export default function (providerContext: FtrProviderContext) {
});

it('should install a tar archive correctly', async function () {
if (server.enabled) {
const buf = fs.readFileSync(testPkgArchiveTgz);
const res = await supertest
.post(`/api/fleet/epm/packages`)
.set('kbn-xsrf', 'xxxx')
.type('application/gzip')
.send(buf)
.expect(200);
expect(res.body.response).to.equal(
'package upload was received ok, but not installed (not implemented yet)'
);
} else {
warnAndSkipTest(this, log);
}
const buf = fs.readFileSync(testPkgArchiveTgz);
const res = await supertest
.post(`/api/fleet/epm/packages`)
.set('kbn-xsrf', 'xxxx')
.type('application/gzip')
.send(buf)
.expect(200);
expect(res.body.response.length).to.be(23);
});

it('should install a zip archive correctly', async function () {
const buf = fs.readFileSync(testPkgArchiveZip);
const res = await supertest
.post(`/api/fleet/epm/packages`)
.set('kbn-xsrf', 'xxxx')
.type('application/zip')
.send(buf)
.expect(200);
expect(res.body.response.length).to.be(18);
});

it('should throw an error if the archive is zip but content type is gzip', async function () {
const buf = fs.readFileSync(testPkgArchiveZip);
const res = await supertest
.post(`/api/fleet/epm/packages`)
.set('kbn-xsrf', 'xxxx')
.type('application/gzip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Uploaded archive seems empty. Assumed content type was application/gzip, check if this matches the archive type."}'
);
});

it('should throw an error if the archive is tar.gz but content type is zip', async function () {
const buf = fs.readFileSync(testPkgArchiveTgz);
const res = await supertest
.post(`/api/fleet/epm/packages`)
.set('kbn-xsrf', 'xxxx')
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Error during extraction of uploaded package: Error: end of central directory record signature not found. Assumed content type was application/zip, check if this matches the archive type."}'
);
});

it('should throw an error if the archive contains two top-level directories', async function () {
const buf = fs.readFileSync(testPkgArchiveInvalidTwoToplevels);
const res = await supertest
.post(`/api/fleet/epm/packages`)
.set('kbn-xsrf', 'xxxx')
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Package contains more than one top-level directory."}'
);
});

it('should throw an error if the archive does not contain a manifest', async function () {
const buf = fs.readFileSync(testPkgArchiveInvalidNoManifest);
const res = await supertest
.post(`/api/fleet/epm/packages`)
.set('kbn-xsrf', 'xxxx')
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Package must contain a top-level manifest.yml file."}'
);
});

it('should throw an error if the archive manifest contains invalid YAML', async function () {
const buf = fs.readFileSync(testPkgArchiveInvalidManifestInvalidYaml);
const res = await supertest
.post(`/api/fleet/epm/packages`)
.set('kbn-xsrf', 'xxxx')
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Could not parse top-level package manifest: YAMLException: bad indentation of a mapping entry at line 2, column 7:\\n name: apache\\n ^."}'
);
});

it('should throw an error if the archive manifest misses a mandatory field', async function () {
const buf = fs.readFileSync(testPkgArchiveInvalidManifestMissingField);
const res = await supertest
.post(`/api/fleet/epm/packages`)
.set('kbn-xsrf', 'xxxx')
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Invalid top-level package manifest: one or more fields missing of name, version, description, type, categories, format_version"}'
);
});

it('should throw an error if the toplevel directory name does not match the package key', async function () {
const buf = fs.readFileSync(testPkgArchiveInvalidToplevelMismatch);
const res = await supertest
.post(`/api/fleet/epm/packages`)
.set('kbn-xsrf', 'xxxx')
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Name thisIsATypo and version 0.1.4 do not match top-level directory apache-0.1.4"}'
);
});
});
}
Original file line number Diff line number Diff line change
@@ -38,9 +38,7 @@ export default function (providerContext: FtrProviderContext) {
})
.expect(200);

const res = await supertest
.get(`/api/ingest_manager/fleet/agents/agent1`)
.set('kbn-xsrf', 'xxx');
const res = await supertest.get(`/api/fleet/agents/agent1`).set('kbn-xsrf', 'xxx');
expect(typeof res.body.item.upgrade_started_at).to.be('string');
});
it('should respond 200 to upgrade agent and update the agent SO without source_uri', async () => {
@@ -52,17 +50,15 @@ export default function (providerContext: FtrProviderContext) {
version: kibanaVersion,
})
.expect(200);
const res = await supertest
.get(`/api/ingest_manager/fleet/agents/agent1`)
.set('kbn-xsrf', 'xxx');
const res = await supertest.get(`/api/fleet/agents/agent1`).set('kbn-xsrf', 'xxx');
expect(typeof res.body.item.upgrade_started_at).to.be('string');
});

it('should respond 400 if trying to upgrade to a version that does not match installed kibana version', async () => {
const kibanaVersion = await kibanaServer.version.get();
const higherVersion = semver.inc(kibanaVersion, 'patch');
await supertest
.post(`/api/ingest_manager/fleet/agents/agent1/upgrade`)
.post(`/api/fleet/agents/agent1/upgrade`)
.set('kbn-xsrf', 'xxx')
.send({
version: higherVersion,
@@ -72,14 +68,11 @@ export default function (providerContext: FtrProviderContext) {
});
it('should respond 400 if trying to upgrade an agent that is unenrolling', async () => {
const kibanaVersion = await kibanaServer.version.get();
await supertest.post(`/api/fleet/agents/agent1/unenroll`).set('kbn-xsrf', 'xxx').send({
force: true,
});
await supertest
.post(`/api/ingest_manager/fleet/agents/agent1/unenroll`)
.set('kbn-xsrf', 'xxx')
.send({
force: true,
});
await supertest
.post(`/api/ingest_manager/fleet/agents/agent1/upgrade`)
.post(`/api/fleet/agents/agent1/upgrade`)
.set('kbn-xsrf', 'xxx')
.send({
version: kibanaVersion,
@@ -94,7 +87,7 @@ export default function (providerContext: FtrProviderContext) {
attributes: { unenrolled_at: new Date().toISOString() },
});
await supertest
.post(`/api/ingest_manager/fleet/agents/agent1/upgrade`)
.post(`/api/fleet/agents/agent1/upgrade`)
.set('kbn-xsrf', 'xxx')
.send({
version: kibanaVersion,
@@ -105,7 +98,7 @@ export default function (providerContext: FtrProviderContext) {
it('should respond 200 to bulk upgrade agents and update the agent SOs', async () => {
const kibanaVersion = await kibanaServer.version.get();
await supertest
.post(`/api/ingest_manager/fleet/agents/bulk_upgrade`)
.post(`/api/fleet/agents/bulk_upgrade`)
.set('kbn-xsrf', 'xxx')
.send({
version: kibanaVersion,
@@ -114,8 +107,8 @@ export default function (providerContext: FtrProviderContext) {
.expect(200);

const [agent1data, agent2data] = await Promise.all([
supertest.get(`/api/ingest_manager/fleet/agents/agent1`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/ingest_manager/fleet/agents/agent2`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/fleet/agents/agent1`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/fleet/agents/agent2`).set('kbn-xsrf', 'xxx'),
]);
expect(typeof agent1data.body.item.upgrade_started_at).to.be('string');
expect(typeof agent2data.body.item.upgrade_started_at).to.be('string');
@@ -124,39 +117,36 @@ export default function (providerContext: FtrProviderContext) {
it('should allow to upgrade multiple agents by kuery', async () => {
const kibanaVersion = await kibanaServer.version.get();
await supertest
.post(`/api/ingest_manager/fleet/agents/bulk_upgrade`)
.post(`/api/fleet/agents/bulk_upgrade`)
.set('kbn-xsrf', 'xxx')
.send({
agents: 'fleet-agents.active: true',
version: kibanaVersion,
})
.expect(200);
const [agent1data, agent2data] = await Promise.all([
supertest.get(`/api/ingest_manager/fleet/agents/agent1`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/ingest_manager/fleet/agents/agent2`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/fleet/agents/agent1`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/fleet/agents/agent2`).set('kbn-xsrf', 'xxx'),
]);
expect(typeof agent1data.body.item.upgrade_started_at).to.be('string');
expect(typeof agent2data.body.item.upgrade_started_at).to.be('string');
});

it('should not upgrade an unenrolling agent during bulk_upgrade', async () => {
const kibanaVersion = await kibanaServer.version.get();
await supertest.post(`/api/fleet/agents/agent1/unenroll`).set('kbn-xsrf', 'xxx').send({
force: true,
});
await supertest
.post(`/api/ingest_manager/fleet/agents/agent1/unenroll`)
.set('kbn-xsrf', 'xxx')
.send({
force: true,
});
await supertest
.post(`/api/ingest_manager/fleet/agents/bulk_upgrade`)
.post(`/api/fleet/agents/bulk_upgrade`)
.set('kbn-xsrf', 'xxx')
.send({
agents: ['agent1', 'agent2'],
version: kibanaVersion,
});
const [agent1data, agent2data] = await Promise.all([
supertest.get(`/api/ingest_manager/fleet/agents/agent1`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/ingest_manager/fleet/agents/agent2`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/fleet/agents/agent1`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/fleet/agents/agent2`).set('kbn-xsrf', 'xxx'),
]);
expect(typeof agent1data.body.item.upgrade_started_at).to.be('undefined');
expect(typeof agent2data.body.item.upgrade_started_at).to.be('string');
@@ -169,15 +159,15 @@ export default function (providerContext: FtrProviderContext) {
attributes: { unenrolled_at: new Date().toISOString() },
});
await supertest
.post(`/api/ingest_manager/fleet/agents/bulk_upgrade`)
.post(`/api/fleet/agents/bulk_upgrade`)
.set('kbn-xsrf', 'xxx')
.send({
agents: ['agent1', 'agent2'],
version: kibanaVersion,
});
const [agent1data, agent2data] = await Promise.all([
supertest.get(`/api/ingest_manager/fleet/agents/agent1`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/ingest_manager/fleet/agents/agent2`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/fleet/agents/agent1`).set('kbn-xsrf', 'xxx'),
supertest.get(`/api/fleet/agents/agent2`).set('kbn-xsrf', 'xxx'),
]);
expect(typeof agent1data.body.item.upgrade_started_at).to.be('undefined');
expect(typeof agent2data.body.item.upgrade_started_at).to.be('string');
You are viewing a condensed version of this merge commit. You can view the full changes here.