Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
688b53e
[Fleet] Introduce API versioning for serverless
criamico Aug 9, 2023
677361c
Add versioning to all endpoints
criamico Aug 10, 2023
3eaaba9
Mark deprecated endpoints as internal only
criamico Aug 10, 2023
70e5f39
Merge main to the branch
criamico Aug 10, 2023
c6528a0
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 10, 2023
65e88ae
Add headers in fleet cypress tests
criamico Aug 10, 2023
204c2a3
Pass headers to api calls in other plugins
criamico Aug 10, 2023
7efaa66
Add flag to run tests without requiring version in headers
criamico Aug 11, 2023
a44ee11
Removing changes in other plugins tests for now
criamico Aug 11, 2023
a3348d9
Undoing leftover changes
criamico Aug 11, 2023
bd2007c
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Aug 11, 2023
ebbb419
Rename versions to oldest
criamico Aug 11, 2023
e40fa9b
Merge branch 'main' into 1921_API_versioning
kibanamachine Aug 11, 2023
6deb500
Merge main and solve conflicts
criamico Aug 21, 2023
06c817f
Merge branch 'main' into 1921_API_versioning
kibanamachine Aug 21, 2023
d99bcf9
fix tests for internal version
criamico Aug 23, 2023
4d8199a
Merge main
criamico Aug 24, 2023
8a16717
Refactor router with versioned router decorator
criamico Aug 24, 2023
ee0eeaa
Update endpoints
criamico Aug 25, 2023
1fd693c
Small change to router
criamico Aug 25, 2023
fee33ee
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 25, 2023
ee6503d
Try fixing router
nchaulet Aug 25, 2023
38ae650
Merge branch 'main' into 1921_API_versioning
kibanamachine Aug 28, 2023
0bc3c0c
Fix unit tests
criamico Aug 29, 2023
871f0a6
Merge branch 'main' into 1921_API_versioning
kibanamachine Aug 29, 2023
196953d
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 29, 2023
011ddcc
Fix fleet integration tests
criamico Aug 29, 2023
e781cf9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 29, 2023
455b092
Make deprecated epm endpoint public to solve related tests failures
criamico Aug 30, 2023
89aeed9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 30, 2023
780aae9
Merge main and solve conflicts
criamico Aug 30, 2023
3049d71
Fix ML integration test
criamico Aug 30, 2023
9261be6
Merge branch 'main' into 1921_API_versioning
kibanamachine Sep 4, 2023
6558151
Use better naming for constants
criamico Sep 4, 2023
65fb288
Fix integration tests
criamico Sep 4, 2023
b2863af
Merge branch 'main' into 1921_API_versioning
kibanamachine Sep 4, 2023
21e1203
Merge branch 'main' into 1921_API_versioning
kibanamachine Sep 4, 2023
fac7151
Merge branch 'main' into 1921_API_versioning
kibanamachine Sep 4, 2023
ea407b2
Merge branch 'main' into 1921_API_versioning
kibanamachine Sep 4, 2023
598b690
Merge branch 'main' into 1921_API_versioning
kibanamachine Sep 5, 2023
93620c1
Merge branch 'main' into 1921_API_versioning
kibanamachine Sep 5, 2023
3a7ca03
Merge branch 'main' into 1921_API_versioning
kibanamachine Sep 5, 2023
db3767f
Merge branch 'main' into 1921_API_versioning
kibanamachine Sep 5, 2023
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
13 changes: 13 additions & 0 deletions x-pack/plugins/fleet/common/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,16 @@ export const DOWNLOAD_SOURCE_API_ROUTES = {
UPDATE_PATTERN: `${API_ROOT}/agent_download_sources/{sourceId}`,
DELETE_PATTERN: `${API_ROOT}/agent_download_sources/{sourceId}`,
};

// API versioning constants
export const API_VERSIONS = {
public: {
v1: '2023-10-31',
},
internal: {
v1: '1',
},
};

export const PUBLIC_API_ACCESS = 'public';
export const INTERNAL_API_ACCESS = 'internal';
6 changes: 4 additions & 2 deletions x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { AGENT_POLICY_NAME_LINK } from '../../screens/integrations';
import { cleanupAgentPolicies, unenrollAgent } from '../../tasks/cleanup';
import { setFleetServerHost } from '../../tasks/fleet_server';

import { API_VERSIONS } from '../../../common/constants';

describe('Home page', () => {
before(() => {
setFleetServerHost('https://fleetserver:8220');
Expand Down Expand Up @@ -152,7 +154,7 @@ describe('Home page', () => {
method: 'POST',
url: '/api/fleet/agent_policies',
body: { name: 'Agent policy for A11y test', namespace: 'default', id: 'agent-policy-a11y' },
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});
});
beforeEach(() => {
Expand All @@ -164,7 +166,7 @@ describe('Home page', () => {
method: 'POST',
url: '/api/fleet/agent_policies/delete',
body: { agentPolicyId: 'agent-policy-a11y' },
headers: { 'kbn-xsrf': 'kibana' },
headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});
});
it('Uninstall Tokens Table', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { cleanupDownloadSources } from '../tasks/cleanup';
import { FLEET, navigateTo } from '../tasks/navigation';
import { CONFIRM_MODAL } from '../screens/navigation';

import { API_VERSIONS } from '../../common/constants';

describe('Agent binary download source section', () => {
beforeEach(() => {
cleanupDownloadSources();
Expand Down Expand Up @@ -80,7 +82,7 @@ describe('Agent binary download source section', () => {
id: 'fleet-local-registry',
host: 'https://new-custom-host.co',
},
headers: { 'kbn-xsrf': 'kibana' },
headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});
cy.request({
method: 'POST',
Expand All @@ -93,7 +95,7 @@ describe('Agent binary download source section', () => {
id: 'new-agent-policy',
download_source_id: 'fleet-local-registry',
},
headers: { 'kbn-xsrf': 'kibana' },
headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
}).then((response: any) => {
navigateTo('app/fleet/policies/new-agent-policy/settings');
cy.getBySel(AGENT_POLICY_FORM.DOWNLOAD_SOURCE_SELECT).contains('Custom Host');
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { deleteFleetServerDocs, deleteAgentDocs, cleanupAgentPolicies } from '..
import type { CreateAgentPolicyRequest } from '../../../common/types';
import { setUISettings } from '../../tasks/ui_settings';

import { API_VERSIONS } from '../../../common/constants';

const createAgentDocs = (kibanaVersion: string) => [
createAgentDoc('agent-1', 'policy-1'), // this agent will have upgrade available
createAgentDoc('agent-2', 'policy-2', 'error', kibanaVersion),
Expand Down Expand Up @@ -66,7 +68,7 @@ function createAgentPolicy(body: CreateAgentPolicyRequest['body']) {
cy.request({
method: 'POST',
url: '/api/fleet/agent_policies',
headers: { 'kbn-xsrf': 'xx' },
headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
body,
});
}
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import { cleanupAgentPolicies } from '../tasks/cleanup';
import { ENROLLMENT_TOKENS } from '../screens/fleet';

import { API_VERSIONS } from '../../common/constants';

describe('Enrollment token page', () => {
before(() => {
cy.request({
Expand All @@ -20,7 +22,7 @@ describe('Enrollment token page', () => {
monitoring_enabled: ['logs', 'metrics'],
id: 'agent-policy-1',
},
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});
});

Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { createAgentDoc } from '../tasks/agents';
import { setFleetServerHost } from '../tasks/fleet_server';
import { FLEET, navigateTo } from '../tasks/navigation';

import { API_VERSIONS } from '../../common/constants';

const FLEET_SERVER_POLICY_ID = 'fleet-server-policy';

function cleanUp() {
Expand All @@ -28,7 +30,7 @@ describe('Fleet add agent flyout', () => {
cy.request({
method: 'POST',
url: '/api/fleet/agent_policies',
headers: { 'kbn-xsrf': 'xx' },
headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
body: {
id: FLEET_SERVER_POLICY_ID,
name: 'Fleet Server policy',
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { LOADING_SPINNER, CONFIRM_MODAL } from '../screens/navigation';
import { ADD_PACKAGE_POLICY_BTN } from '../screens/fleet';
import { cleanupAgentPolicies } from '../tasks/cleanup';
import { API_VERSIONS } from '../../common/constants';

function setupIntegrations() {
cy.intercept(
Expand Down Expand Up @@ -135,7 +136,7 @@ describe('Add Integration - Real API', () => {
namespace: 'default',
monitoring_enabled: ['logs', 'metrics'],
},
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});

cy.request('/api/fleet/agent_policies').then((response: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const INPUT_TEST_PACKAGE = 'input_package-1.0.0';
const INTEGRATION_TEST_PACKAGE = 'logs_integration-1.0.0';
const INTEGRATION_TEST_PACKAGE_NO_DATASET = 'logs_int_no_dataset-1.0.0';

import { API_VERSIONS } from '../../common/constants';

describe('Input package create and edit package policy', () => {
const agentPolicyId = 'test-input-package-policy';
const agentPolicyName = 'Test input package policy';
Expand Down Expand Up @@ -45,15 +47,15 @@ describe('Input package create and edit package policy', () => {
namespace: 'default',
monitoring_enabled: [],
},
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});
});
after(() => {
// delete agent policy
cy.request({
method: 'POST',
url: `/api/fleet/agent_policies/delete`,
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
body: JSON.stringify({
agentPolicyId,
}),
Expand Down Expand Up @@ -120,15 +122,15 @@ describe('Integration package with custom dataset create and edit package policy
namespace: 'default',
monitoring_enabled: [],
},
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});
});
after(() => {
// delete agent policy
cy.request({
method: 'POST',
url: `/api/fleet/agent_policies/delete`,
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
body: JSON.stringify({
agentPolicyId,
}),
Expand Down Expand Up @@ -184,15 +186,15 @@ describe('Integration package with fixed dataset create and edit package policy'
namespace: 'default',
monitoring_enabled: [],
},
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});
});
after(() => {
// delete agent policy
cy.request({
method: 'POST',
url: `/api/fleet/agent_policies/delete`,
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
body: JSON.stringify({
agentPolicyId,
}),
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { cleanupAgentPolicies } from '../tasks/cleanup';
import { UNINSTALL_TOKENS } from '../screens/fleet';
import type { GetUninstallTokenResponse } from '../../common/types/rest_spec/uninstall_token';

import { API_VERSIONS } from '../../common/constants';

describe('Uninstall token page', () => {
before(() => {
cleanupAgentPolicies();
Expand Down Expand Up @@ -78,7 +80,7 @@ describe('Uninstall token page', () => {
method: 'POST',
url: '/api/fleet/agent_policies',
body: { name: `Agent policy ${i}00`, namespace: 'default', id: `agent-policy-${i}00` },
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});
}
};
Expand Down
8 changes: 7 additions & 1 deletion x-pack/plugins/fleet/cypress/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import fs from 'fs';
import fetch from 'node-fetch';
import { createEsClientForTesting } from '@kbn/test';

import { API_VERSIONS } from '../../common/constants';

const plugin: Cypress.PluginConfig = (on, config) => {
const client = createEsClientForTesting({
esUrl: config.env.ELASTICSEARCH_URL,
Expand All @@ -22,8 +24,9 @@ const plugin: Cypress.PluginConfig = (on, config) => {
path: string;
body?: any;
contentType?: string;
version?: string;
}) {
const { method, path, body, contentType } = opts;
const { method, path, body, contentType, version } = opts;
const Authorization = `Basic ${Buffer.from(
`elastic:${config.env.ELASTICSEARCH_PASSWORD}`
).toString('base64')}`;
Expand All @@ -35,6 +38,7 @@ const plugin: Cypress.PluginConfig = (on, config) => {
'kbn-xsrf': 'cypress',
'Content-Type': contentType || 'application/json',
Authorization,
...(version ? { 'Elastic-Api-Version': version } : {}),
},
...(body ? { body } : {}),
});
Expand Down Expand Up @@ -75,13 +79,15 @@ const plugin: Cypress.PluginConfig = (on, config) => {
path: '/api/fleet/epm/packages',
body: Buffer.from(zipContent, 'base64'),
contentType: 'application/zip',
version: API_VERSIONS.public.v1,
});
},

async uninstallTestPackage(packageName: string) {
return kibanaFetch({
method: 'DELETE',
path: `/api/fleet/epm/packages/${packageName}`,
version: API_VERSIONS.public.v1,
});
},
});
Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/fleet/cypress/tasks/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { API_VERSIONS } from '../../common/constants';

export function cleanupAgentPolicies() {
cy.request('/api/fleet/agent_policies').then((response: any) => {
Expand All @@ -14,7 +15,7 @@ export function cleanupAgentPolicies() {
method: 'POST',
url: '/api/fleet/agent_policies/delete',
body: { agentPolicyId: policy.id },
headers: { 'kbn-xsrf': 'kibana' },
headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});
});
});
Expand All @@ -28,7 +29,7 @@ export function unenrollAgent() {
method: 'POST',
url: `api/fleet/agents/${agent.id}/unenroll`,
body: { revoke: true },
headers: { 'kbn-xsrf': 'kibana' },
headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});
});
}
Expand All @@ -43,7 +44,7 @@ export function cleanupDownloadSources() {
cy.request({
method: 'DELETE',
url: `/api/fleet/agent_download_sources/${ds.id}`,
headers: { 'kbn-xsrf': 'kibana' },
headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
});
});
});
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/fleet/cypress/tasks/fleet_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { API_VERSIONS } from '../../common/constants';

import { createAgentDoc } from './agents';

const FLEET_SERVER_POLICY_ID = 'fleet-server-policy';
Expand Down Expand Up @@ -66,7 +68,7 @@ export function setFleetServerHost(host = 'https://fleetserver:8220') {
cy.request({
method: 'POST',
url: '/api/fleet/fleet_server_hosts',
headers: { 'kbn-xsrf': 'xx' },
headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
body: {
name: 'Default host',
host_urls: [host],
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/fleet/cypress/tasks/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
import { AGENT_POLICY_SYSTEM_MONITORING_CHECKBOX, EXISTING_HOSTS_TAB } from '../screens/fleet';
import { TOAST_CLOSE_BTN, CONFIRM_MODAL } from '../screens/navigation';

import { API_VERSIONS } from '../../common/constants';

export const addIntegration = ({ useExistingPolicy } = { useExistingPolicy: false }) => {
cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click();
if (useExistingPolicy) {
Expand Down Expand Up @@ -54,7 +56,7 @@ export const deleteIntegrations = async () => {
response.body.items.forEach((policy: any) => ids.push(policy.id));
cy.request({
url: `/api/fleet/package_policies/delete`,
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
body: `{ "packagePolicyIds": ${JSON.stringify(ids)}, "force": true }`,
method: 'POST',
});
Expand All @@ -64,7 +66,7 @@ export const deleteIntegrations = async () => {
export const installPackageWithVersion = (integration: string, version: string) => {
cy.request({
url: `/api/fleet/epm/packages/${integration}/${version}`,
headers: { 'kbn-xsrf': 'cypress' },
headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` },
body: '{ "force": true }',
method: 'POST',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { FormattedMessage } from '@kbn/i18n-react';

import { AGENTS_PREFIX } from '../../../constants';
import { sendDeleteAgentPolicy, useStartServices, useConfig, sendRequest } from '../../../hooks';
import { API_VERSIONS } from '../../../../../../common/constants';

interface Props {
children: (deleteAgentPolicy: DeleteAgentPolicy) => React.ReactElement;
Expand Down Expand Up @@ -104,6 +105,7 @@ export const AgentPolicyDeleteProvider: React.FunctionComponent<Props> = ({
query: {
kuery: `${AGENTS_PREFIX}.policy_id : ${agentPolicyToCheck}`,
},
version: API_VERSIONS.public.v1,
});
setAgentsCount(data?.total || 0);
setIsLoadingAgentsCount(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';

import { useStartServices, sendRequest, sendDeletePackagePolicy, useConfig } from '../hooks';
import { AGENT_API_ROUTES, AGENTS_PREFIX } from '../../common/constants';
import { AGENT_API_ROUTES, AGENTS_PREFIX, API_VERSIONS } from '../../common/constants';
import type { AgentPolicy } from '../types';

interface Props {
Expand Down Expand Up @@ -55,6 +55,7 @@ export const PackagePolicyDeleteProvider: React.FunctionComponent<Props> = ({
perPage: 1,
kuery: `${AGENTS_PREFIX}.policy_id : ${agentPolicy.id}`,
},
version: API_VERSIONS.public.v1,
});
setAgentsCount(data?.total || 0);
setIsLoadingAgentsCount(false);
Expand Down
Loading