mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
[Defend Workflows] Adjust headers in fleet api (#165823)
This commit is contained in:
parent
8c39735fcf
commit
630a95bc10
28 changed files with 172 additions and 26 deletions
|
@ -141,6 +141,7 @@ const uploadPipeline = (pipelineContent: string | object) => {
|
|||
) {
|
||||
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/fleet_cypress.yml'));
|
||||
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/defend_workflows.yml'));
|
||||
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/osquery_cypress.yml'));
|
||||
}
|
||||
|
||||
if (
|
||||
|
|
|
@ -59,6 +59,8 @@ export {
|
|||
// dashboards ids
|
||||
DASHBOARD_LOCATORS_IDS,
|
||||
FLEET_ENROLLMENT_API_PREFIX,
|
||||
API_VERSIONS,
|
||||
APP_API_ROUTES,
|
||||
} from './constants';
|
||||
export {
|
||||
// Route services
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
import React from 'react';
|
||||
|
||||
import { API_VERSIONS } from '../../../../../../../common/constants';
|
||||
|
||||
import type { UseRequestConfig } from '../../../../hooks';
|
||||
import { useRequest } from '../../../../hooks';
|
||||
import type { GetAgentStatusResponse } from '../../../../types';
|
||||
|
@ -21,6 +23,7 @@ export function useGetAgentStatus(policyId?: string, options?: RequestOptions) {
|
|||
policyId,
|
||||
},
|
||||
method: 'get',
|
||||
version: API_VERSIONS.public.v1,
|
||||
...options,
|
||||
});
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { API_VERSIONS } from '../../../../../../../../common/constants';
|
||||
|
||||
import type {
|
||||
PackagePolicy,
|
||||
GetAgentPoliciesResponse,
|
||||
|
@ -75,6 +77,7 @@ export const usePackagePoliciesWithAgentPolicy = (
|
|||
full: true,
|
||||
ignoreMissing: true,
|
||||
},
|
||||
version: API_VERSIONS.public.v1,
|
||||
shouldSendRequest: agentPoliciesIds.length > 0,
|
||||
} as SendConditionalRequestConfig);
|
||||
|
||||
|
|
|
@ -109,6 +109,7 @@ export const useConditionalRequest = <D = any, E = RequestError>(
|
|||
path: config.path,
|
||||
query: config.query,
|
||||
body: config.body,
|
||||
version: config.version,
|
||||
});
|
||||
if (res.error) {
|
||||
throw res.error;
|
||||
|
|
|
@ -201,6 +201,7 @@ async function getAgentPolicy(id: string) {
|
|||
'Content-Type': 'application/json',
|
||||
'kbn-xsrf': 'kibana',
|
||||
'x-elastic-product-origin': 'fleet',
|
||||
'Elastic-Api-Version': PUBLIC_VERSION_V1,
|
||||
},
|
||||
});
|
||||
const data = await res.json();
|
||||
|
@ -346,6 +347,7 @@ async function bumpAgentPolicyRevision(id: string, policy: any) {
|
|||
'Content-Type': 'application/json',
|
||||
'kbn-xsrf': 'kibana',
|
||||
'x-elastic-product-origin': 'fleet',
|
||||
'Elastic-Api-Version': PUBLIC_VERSION_V1,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -294,6 +294,9 @@ export const loadAgentPolicy = () =>
|
|||
monitoring_enabled: ['logs', 'metrics'],
|
||||
inactivity_timeout: 1209600,
|
||||
},
|
||||
headers: {
|
||||
'Elastic-Api-Version': API_VERSIONS.public.v1,
|
||||
},
|
||||
url: '/api/fleet/agent_policies',
|
||||
}).then((response) => response.body.item);
|
||||
|
||||
|
@ -301,5 +304,8 @@ export const cleanupAgentPolicy = (agentPolicyId: string) =>
|
|||
request({
|
||||
method: 'POST',
|
||||
body: { agentPolicyId },
|
||||
headers: {
|
||||
'Elastic-Api-Version': API_VERSIONS.public.v1,
|
||||
},
|
||||
url: '/api/fleet/agent_policies/delete',
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { API_VERSIONS } from '../../common/constants';
|
||||
import { DEFAULT_POLICY } from '../screens/fleet';
|
||||
import {
|
||||
ADD_POLICY_BTN,
|
||||
|
@ -125,7 +126,7 @@ export const deleteIntegrations = async (integrationName: string) => {
|
|||
.then(() => {
|
||||
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)} }`,
|
||||
method: 'POST',
|
||||
});
|
||||
|
@ -135,7 +136,7 @@ export const deleteIntegrations = async (integrationName: string) => {
|
|||
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',
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@ import type { AxiosResponse } from 'axios';
|
|||
import type { DeleteByQueryResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { KbnClient } from '@kbn/test';
|
||||
import type { Agent, FleetServerAgent, GetOneAgentResponse } from '@kbn/fleet-plugin/common';
|
||||
import { AGENT_API_ROUTES } from '@kbn/fleet-plugin/common';
|
||||
import { AGENT_API_ROUTES, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
import type { HostMetadata } from '../types';
|
||||
import { FleetAgentGenerator } from '../data_generators/fleet_agent_generator';
|
||||
import { wrapErrorAndRejectPromise } from './utils';
|
||||
|
@ -90,6 +90,7 @@ const fetchFleetAgent = async (kbnClient: KbnClient, agentId: string): Promise<A
|
|||
.request({
|
||||
path: AGENT_API_ROUTES.INFO_PATTERN.replace('{agentId}', agentId),
|
||||
method: 'GET',
|
||||
headers: { 'elastic-api-version': API_VERSIONS.public.v1 },
|
||||
})
|
||||
.catch(wrapErrorAndRejectPromise)) as AxiosResponse<GetOneAgentResponse>
|
||||
).data.item;
|
||||
|
|
|
@ -16,7 +16,11 @@ import type {
|
|||
DeleteAgentPolicyResponse,
|
||||
PostDeletePackagePoliciesResponse,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import { AGENT_POLICY_API_ROUTES, PACKAGE_POLICY_API_ROUTES } from '@kbn/fleet-plugin/common';
|
||||
import {
|
||||
AGENT_POLICY_API_ROUTES,
|
||||
PACKAGE_POLICY_API_ROUTES,
|
||||
API_VERSIONS,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import { memoize } from 'lodash';
|
||||
import { getEndpointPackageInfo } from '../utils/package';
|
||||
import type { PolicyData } from '../types';
|
||||
|
@ -61,6 +65,9 @@ export const indexFleetEndpointPolicy = async (
|
|||
agentPolicy = (await kbnClient
|
||||
.request({
|
||||
path: AGENT_POLICY_API_ROUTES.CREATE_PATTERN,
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
method: 'POST',
|
||||
body: newAgentPolicyData,
|
||||
})
|
||||
|
@ -101,6 +108,9 @@ export const indexFleetEndpointPolicy = async (
|
|||
path: PACKAGE_POLICY_API_ROUTES.CREATE_PATTERN,
|
||||
method: 'POST',
|
||||
body: newPackagePolicyData,
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
})
|
||||
.catch(wrapErrorAndRejectPromise)) as AxiosResponse<CreatePackagePolicyResponse>;
|
||||
|
||||
|
@ -135,6 +145,9 @@ export const deleteIndexedFleetEndpointPolicies = async (
|
|||
(await kbnClient
|
||||
.request({
|
||||
path: PACKAGE_POLICY_API_ROUTES.DELETE_PATTERN,
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
method: 'POST',
|
||||
body: {
|
||||
packagePolicyIds: indexData.integrationPolicies.map((policy) => policy.id),
|
||||
|
@ -153,6 +166,9 @@ export const deleteIndexedFleetEndpointPolicies = async (
|
|||
(await kbnClient
|
||||
.request({
|
||||
path: AGENT_POLICY_API_ROUTES.DELETE_PATTERN,
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
method: 'POST',
|
||||
body: {
|
||||
agentPolicyId: agentPolicy.id,
|
||||
|
|
|
@ -13,7 +13,12 @@ import type {
|
|||
IBulkInstallPackageHTTPError,
|
||||
PostFleetSetupResponse,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import { AGENTS_SETUP_API_ROUTES, EPM_API_ROUTES, SETUP_API_ROUTE } from '@kbn/fleet-plugin/common';
|
||||
import {
|
||||
AGENTS_SETUP_API_ROUTES,
|
||||
EPM_API_ROUTES,
|
||||
SETUP_API_ROUTE,
|
||||
API_VERSIONS,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import { ToolingLog } from '@kbn/tooling-log';
|
||||
import { UsageTracker } from './usage_tracker';
|
||||
import { EndpointDataLoadingError, retryOnError, wrapErrorAndRejectPromise } from './utils';
|
||||
|
@ -43,6 +48,7 @@ export const setupFleetForEndpoint = async (
|
|||
const setupResponse = (await kbnClient
|
||||
.request({
|
||||
path: SETUP_API_ROUTE,
|
||||
headers: { 'Elastic-Api-Version': API_VERSIONS.public.v1 },
|
||||
method: 'POST',
|
||||
})
|
||||
.catch(wrapErrorAndRejectPromise)) as AxiosResponse<PostFleetSetupResponse>;
|
||||
|
@ -64,6 +70,9 @@ export const setupFleetForEndpoint = async (
|
|||
.request({
|
||||
path: AGENTS_SETUP_API_ROUTES.CREATE_PATTERN,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
})
|
||||
.catch(wrapErrorAndRejectPromise)) as AxiosResponse<PostFleetSetupResponse>;
|
||||
|
||||
|
@ -118,6 +127,9 @@ export const installOrUpgradeEndpointFleetPackage = async (
|
|||
query: {
|
||||
prerelease: true,
|
||||
},
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
})
|
||||
.catch(wrapErrorAndRejectPromise)) as AxiosResponse<BulkInstallPackagesResponse>;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import type { AxiosResponse } from 'axios';
|
|||
|
||||
import type { KbnClient } from '@kbn/test';
|
||||
import type { GetInfoResponse } from '@kbn/fleet-plugin/common';
|
||||
import { epmRouteService } from '@kbn/fleet-plugin/common';
|
||||
import { API_VERSIONS, epmRouteService } from '@kbn/fleet-plugin/common';
|
||||
|
||||
export const getEndpointPackageInfo = async (
|
||||
kbnClient: KbnClient
|
||||
|
@ -18,6 +18,7 @@ export const getEndpointPackageInfo = async (
|
|||
const endpointPackage = (
|
||||
(await kbnClient.request({
|
||||
path,
|
||||
headers: { 'Elastic-Api-Version': API_VERSIONS.public.v1 },
|
||||
method: 'GET',
|
||||
})) as AxiosResponse<GetInfoResponse>
|
||||
).data.item;
|
||||
|
|
|
@ -10,7 +10,7 @@ import type {
|
|||
UpdatePackagePolicy,
|
||||
UpdatePackagePolicyResponse,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import { packagePolicyRouteService } from '@kbn/fleet-plugin/common';
|
||||
import { packagePolicyRouteService, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
import { request } from './common';
|
||||
import { ProtectionModes } from '../../../../common/endpoint/types';
|
||||
|
||||
|
@ -24,6 +24,9 @@ export const enableAllPolicyProtections = (
|
|||
return request<GetOnePackagePolicyResponse>({
|
||||
method: 'GET',
|
||||
url: packagePolicyRouteService.getInfoPath(endpointPolicyId),
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
}).then(({ body: { item: endpointPolicy } }) => {
|
||||
const {
|
||||
created_by: _createdBy,
|
||||
|
@ -58,6 +61,9 @@ export const enableAllPolicyProtections = (
|
|||
method: 'PUT',
|
||||
url: packagePolicyRouteService.getUpdatePath(endpointPolicyId),
|
||||
body: updatedEndpointPolicy,
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -69,6 +75,9 @@ export const setCustomProtectionUpdatesManifestVersion = (
|
|||
return request<GetOnePackagePolicyResponse>({
|
||||
method: 'GET',
|
||||
url: packagePolicyRouteService.getInfoPath(endpointPolicyId),
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
}).then(({ body: { item: endpointPolicy } }) => {
|
||||
const {
|
||||
created_by: _createdBy,
|
||||
|
@ -91,6 +100,9 @@ export const setCustomProtectionUpdatesManifestVersion = (
|
|||
method: 'PUT',
|
||||
url: packagePolicyRouteService.getUpdatePath(endpointPolicyId),
|
||||
body: updatedEndpointPolicy,
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -103,6 +115,6 @@ export const setCustomProtectionUpdatesNote = (
|
|||
method: 'POST',
|
||||
url: `/api/endpoint/protection_updates_note/${endpointPolicyId}`,
|
||||
body: { note },
|
||||
headers: { 'Elastic-Api-Version': '2023-10-31' },
|
||||
headers: { 'Elastic-Api-Version': API_VERSIONS.public.v1 },
|
||||
});
|
||||
};
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
agentRouteService,
|
||||
epmRouteService,
|
||||
packagePolicyRouteService,
|
||||
API_VERSIONS,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import type { PutAgentReassignResponse } from '@kbn/fleet-plugin/common/types';
|
||||
import type { IndexedFleetEndpointPolicyResponse } from '../../../../common/endpoint/data_loaders/index_fleet_endpoint_policy';
|
||||
|
@ -24,6 +25,9 @@ export const getEndpointIntegrationVersion = (): Cypress.Chainable<string> =>
|
|||
request<GetInfoResponse>({
|
||||
url: epmRouteService.getInfoPath('endpoint'),
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
}).then((response) => response.body.item.version);
|
||||
|
||||
export const getAgentByHostName = (hostname: string): Cypress.Chainable<Agent> =>
|
||||
|
@ -33,6 +37,9 @@ export const getAgentByHostName = (hostname: string): Cypress.Chainable<Agent> =
|
|||
qs: {
|
||||
kuery: `local_metadata.host.hostname: "${hostname}"`,
|
||||
},
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
}).then((response) => response.body.items[0]);
|
||||
|
||||
export const reassignAgentPolicy = (
|
||||
|
@ -45,6 +52,9 @@ export const reassignAgentPolicy = (
|
|||
body: {
|
||||
policy_id: agentPolicyId,
|
||||
},
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
});
|
||||
|
||||
export const yieldEndpointPolicyRevision = (): Cypress.Chainable<number> =>
|
||||
|
@ -54,6 +64,9 @@ export const yieldEndpointPolicyRevision = (): Cypress.Chainable<number> =>
|
|||
qs: {
|
||||
kuery: 'ingest-package-policies.package.name: endpoint',
|
||||
},
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
}).then(({ body }) => {
|
||||
return body.items?.[0]?.revision ?? -1;
|
||||
});
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
DefaultPolicyRuleNotificationMessage,
|
||||
} from '../../../../common/endpoint/models/policy_config';
|
||||
import { set } from 'lodash';
|
||||
import { API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
|
||||
const useQueryMock = _useQuery as jest.Mock;
|
||||
|
||||
|
@ -60,6 +61,7 @@ describe('When using the `useGetFileInfo()` hook', () => {
|
|||
|
||||
expect(apiMocks.responseProvider.endpointPackagePolicy).toHaveBeenCalledWith({
|
||||
path: `/api/fleet/package_policies/${policy.id}`,
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
||||
import type { IHttpFetchError } from '@kbn/core-http-browser';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { packagePolicyRouteService } from '@kbn/fleet-plugin/common';
|
||||
import { packagePolicyRouteService, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
import {
|
||||
DefaultPolicyNotificationMessage,
|
||||
DefaultPolicyRuleNotificationMessage,
|
||||
|
@ -45,7 +45,8 @@ export const useFetchEndpointPolicy = (
|
|||
...options,
|
||||
queryFn: async () => {
|
||||
const apiResponse = await http.get<GetPolicyResponse>(
|
||||
packagePolicyRouteService.getInfoPath(policyId)
|
||||
packagePolicyRouteService.getInfoPath(policyId),
|
||||
{ version: API_VERSIONS.public.v1 }
|
||||
);
|
||||
|
||||
applyDefaultsToPolicyIfNeeded(apiResponse.item);
|
||||
|
|
|
@ -12,7 +12,7 @@ import type { PolicyData } from '../../../../common/endpoint/types';
|
|||
import { allFleetHttpMocks } from '../../mocks';
|
||||
import { FleetPackagePolicyGenerator } from '../../../../common/endpoint/data_generators/fleet_package_policy_generator';
|
||||
import { useFetchAgentByAgentPolicySummary } from './use_fetch_endpoint_policy_agent_summary';
|
||||
import { agentRouteService } from '@kbn/fleet-plugin/common';
|
||||
import { agentRouteService, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
|
||||
const useQueryMock = _useQuery as jest.Mock;
|
||||
|
||||
|
@ -57,6 +57,7 @@ describe('When using the `useFetchEndpointPolicyAgentSummary()` hook', () => {
|
|||
expect(apiMocks.responseProvider.agentStatus).toHaveBeenCalledWith({
|
||||
path: agentRouteService.getStatusPath(),
|
||||
query: { policyId: policy.policy_id },
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
expect(data).toEqual({
|
||||
total: 50,
|
||||
|
|
|
@ -9,7 +9,7 @@ import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|||
import type { IHttpFetchError } from '@kbn/core-http-browser';
|
||||
import type { GetAgentStatusResponse } from '@kbn/fleet-plugin/common';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { agentRouteService } from '@kbn/fleet-plugin/common';
|
||||
import { agentRouteService, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
import { useHttp } from '../../../common/lib/kibana';
|
||||
|
||||
type EndpointPolicyAgentSummary = GetAgentStatusResponse['results'];
|
||||
|
@ -30,6 +30,7 @@ export const useFetchAgentByAgentPolicySummary = (
|
|||
return (
|
||||
await http.get<GetAgentStatusResponse>(agentRouteService.getStatusPath(), {
|
||||
query: { policyId: agentPolicyId },
|
||||
version: API_VERSIONS.public.v1,
|
||||
})
|
||||
).results;
|
||||
},
|
||||
|
|
|
@ -17,7 +17,7 @@ import type { RenderHookResult } from '@testing-library/react-hooks/src/types';
|
|||
import { useUpdateEndpointPolicy } from './use_update_endpoint_policy';
|
||||
import type { PolicyData } from '../../../../common/endpoint/types';
|
||||
import { FleetPackagePolicyGenerator } from '../../../../common/endpoint/data_generators/fleet_package_policy_generator';
|
||||
import { packagePolicyRouteService } from '@kbn/fleet-plugin/common';
|
||||
import { API_VERSIONS, packagePolicyRouteService } from '@kbn/fleet-plugin/common';
|
||||
import { getPolicyDataForUpdate } from '../../../../common/endpoint/service/policy';
|
||||
|
||||
const useMutationMock = _useMutation as jest.Mock;
|
||||
|
@ -64,6 +64,7 @@ describe('When using the `useFetchEndpointPolicyAgentSummary()` hook', () => {
|
|||
expect(apiMocks.responseProvider.updateEndpointPolicy).toHaveBeenCalledWith({
|
||||
path: packagePolicyRouteService.getUpdatePath(policy.id),
|
||||
body: JSON.stringify(getPolicyDataForUpdate(policy)),
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
|
||||
expect(result).toEqual({ item: expect.any(Object) });
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
||||
import type { IHttpFetchError } from '@kbn/core-http-browser';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { packagePolicyRouteService } from '@kbn/fleet-plugin/common';
|
||||
import { packagePolicyRouteService, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
import { getPolicyDataForUpdate } from '../../../../common/endpoint/service/policy';
|
||||
import { useHttp } from '../../../common/lib/kibana';
|
||||
import type { PolicyData } from '../../../../common/endpoint/types';
|
||||
|
@ -39,6 +39,7 @@ export const useUpdateEndpointPolicy = (
|
|||
|
||||
return http.put(packagePolicyRouteService.getUpdatePath(policy.id), {
|
||||
body: JSON.stringify(update),
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
}, options);
|
||||
};
|
||||
|
|
|
@ -20,7 +20,7 @@ import { expectIsViewOnly, getPolicySettingsFormTestSubjects } from '../policy_s
|
|||
import { cloneDeep, set } from 'lodash';
|
||||
import { ProtectionModes } from '../../../../../../common/endpoint/types';
|
||||
import { waitFor, cleanup } from '@testing-library/react';
|
||||
import { packagePolicyRouteService } from '@kbn/fleet-plugin/common';
|
||||
import { packagePolicyRouteService, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
import { getPolicyDataForUpdate } from '../../../../../../common/endpoint/service/policy';
|
||||
import { getDeferred } from '../../../../mocks/utils';
|
||||
|
||||
|
@ -133,6 +133,7 @@ describe('When rendering PolicySettingsLayout', () => {
|
|||
expect(apiMocks.responseProvider.updateEndpointPolicy).toHaveBeenCalledWith({
|
||||
path: packagePolicyRouteService.getUpdatePath(policyData.id),
|
||||
body: JSON.stringify(getPolicyDataForUpdate(expectedUpdatedPolicy)),
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { sendGetPackagePolicy, sendGetEndpointSecurityPackage } from './ingest';
|
||||
import { httpServiceMock } from '@kbn/core/public/mocks';
|
||||
import { PACKAGE_POLICY_API_ROOT, epmRouteService } from '@kbn/fleet-plugin/common';
|
||||
import { PACKAGE_POLICY_API_ROOT, epmRouteService, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
import { policyListApiPathHandlers } from '../../pages/policy/store/test_mock_utils';
|
||||
|
||||
describe('ingest service', () => {
|
||||
|
@ -20,7 +20,9 @@ describe('ingest service', () => {
|
|||
describe('sendGetPackagePolicy()', () => {
|
||||
it('builds correct API path', async () => {
|
||||
await sendGetPackagePolicy(http, '123');
|
||||
expect(http.get).toHaveBeenCalledWith(`${PACKAGE_POLICY_API_ROOT}/123`, undefined);
|
||||
expect(http.get).toHaveBeenCalledWith(`${PACKAGE_POLICY_API_ROOT}/123`, {
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
});
|
||||
it('supports http options', async () => {
|
||||
await sendGetPackagePolicy(http, '123', { query: { page: 1 } });
|
||||
|
@ -28,6 +30,7 @@ describe('ingest service', () => {
|
|||
query: {
|
||||
page: 1,
|
||||
},
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -37,7 +40,9 @@ describe('ingest service', () => {
|
|||
const path = epmRouteService.getInfoPath('endpoint');
|
||||
http.get.mockReturnValue(Promise.resolve(policyListApiPathHandlers()[path]()));
|
||||
await sendGetEndpointSecurityPackage(http);
|
||||
expect(http.get).toHaveBeenCalledWith(path);
|
||||
expect(http.get).toHaveBeenCalledWith(path, {
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw if package is not found', async () => {
|
||||
|
|
|
@ -11,7 +11,7 @@ import type {
|
|||
GetPackagePoliciesResponse,
|
||||
GetInfoResponse,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import { epmRouteService } from '@kbn/fleet-plugin/common';
|
||||
import { epmRouteService, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
|
||||
import type { NewPolicyData } from '../../../../common/endpoint/types';
|
||||
import type { GetPolicyResponse, UpdatePolicyResponse } from '../../pages/policy/types';
|
||||
|
@ -34,7 +34,10 @@ export const sendGetPackagePolicy = (
|
|||
packagePolicyId: string,
|
||||
options?: HttpFetchOptions
|
||||
) => {
|
||||
return http.get<GetPolicyResponse>(`${INGEST_API_PACKAGE_POLICIES}/${packagePolicyId}`, options);
|
||||
return http.get<GetPolicyResponse>(`${INGEST_API_PACKAGE_POLICIES}/${packagePolicyId}`, {
|
||||
...options,
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -50,6 +53,7 @@ export const sendBulkGetPackagePolicies = (
|
|||
) => {
|
||||
return http.post<GetPackagePoliciesResponse>(`${INGEST_API_PACKAGE_POLICIES}/_bulk_get`, {
|
||||
...options,
|
||||
version: API_VERSIONS.public.v1,
|
||||
body: JSON.stringify({
|
||||
ids: packagePolicyIds,
|
||||
ignoreMissing: true,
|
||||
|
@ -73,6 +77,7 @@ export const sendPutPackagePolicy = (
|
|||
): Promise<UpdatePolicyResponse> => {
|
||||
return http.put(`${INGEST_API_PACKAGE_POLICIES}/${packagePolicyId}`, {
|
||||
...options,
|
||||
version: API_VERSIONS.public.v1,
|
||||
body: JSON.stringify(packagePolicy),
|
||||
});
|
||||
};
|
||||
|
@ -92,6 +97,7 @@ export const sendGetFleetAgentStatusForPolicy = (
|
|||
): Promise<GetAgentStatusResponse> => {
|
||||
return http.get(INGEST_API_FLEET_AGENT_STATUS, {
|
||||
...options,
|
||||
version: API_VERSIONS.public.v1,
|
||||
query: {
|
||||
policyId,
|
||||
},
|
||||
|
@ -105,7 +111,9 @@ export const sendGetEndpointSecurityPackage = async (
|
|||
http: HttpStart
|
||||
): Promise<GetInfoResponse['item']> => {
|
||||
const path = epmRouteService.getInfoPath('endpoint');
|
||||
const endpointPackageResponse = await http.get<GetInfoResponse>(path);
|
||||
const endpointPackageResponse = await http.get<GetInfoResponse>(path, {
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
const endpointPackageInfo = endpointPackageResponse.item;
|
||||
if (!endpointPackageInfo) {
|
||||
throw new Error('Endpoint package was not found.');
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { httpServiceMock } from '@kbn/core/public/mocks';
|
||||
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common';
|
||||
import { PACKAGE_POLICY_API_ROUTES } from '@kbn/fleet-plugin/common/constants/routes';
|
||||
import { API_VERSIONS, PACKAGE_POLICY_API_ROUTES } from '@kbn/fleet-plugin/common/constants';
|
||||
import { sendGetEndpointSpecificPackagePolicies } from './policies';
|
||||
|
||||
describe('ingest service', () => {
|
||||
|
@ -24,6 +24,7 @@ describe('ingest service', () => {
|
|||
query: {
|
||||
kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: endpoint`,
|
||||
},
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
});
|
||||
it('supports additional KQL to be defined on input for query params', async () => {
|
||||
|
@ -36,6 +37,7 @@ describe('ingest service', () => {
|
|||
perPage: 10,
|
||||
page: 1,
|
||||
},
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import type { HttpFetchOptions, HttpStart } from '@kbn/core/public';
|
||||
import type { GetPackagePoliciesRequest } from '@kbn/fleet-plugin/common';
|
||||
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common';
|
||||
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
import type { GetPolicyListResponse } from '../../pages/policy/types';
|
||||
import { INGEST_API_PACKAGE_POLICIES } from './ingest';
|
||||
|
||||
|
@ -29,5 +29,6 @@ export const sendGetEndpointSpecificPackagePolicies = (
|
|||
options?.query?.kuery ? `${options.query.kuery} and ` : ''
|
||||
}${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: endpoint`,
|
||||
},
|
||||
version: API_VERSIONS.public.v1,
|
||||
});
|
||||
};
|
||||
|
|
|
@ -19,6 +19,7 @@ import {
|
|||
agentPolicyRouteService,
|
||||
agentRouteService,
|
||||
AGENTS_INDEX,
|
||||
API_VERSIONS,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import { ToolingLog } from '@kbn/tooling-log';
|
||||
import type { KbnClient } from '@kbn/test';
|
||||
|
@ -106,6 +107,9 @@ export const fetchFleetAgents = async (
|
|||
.request<GetAgentsResponse>({
|
||||
method: 'GET',
|
||||
path: AGENT_API_ROUTES.LIST_PATTERN,
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
query: options,
|
||||
})
|
||||
.catch(catchAxiosErrorFormatAndThrow)
|
||||
|
@ -160,6 +164,9 @@ export const fetchFleetServerUrl = async (kbnClient: KbnClient): Promise<string
|
|||
.request<GetFleetServerHostsResponse>({
|
||||
method: 'GET',
|
||||
path: fleetServerHostsRoutesService.getListPath(),
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
query: {
|
||||
perPage: 100,
|
||||
},
|
||||
|
@ -197,6 +204,9 @@ export const fetchAgentPolicyEnrollmentKey = async (
|
|||
.request<GetEnrollmentAPIKeysResponse>({
|
||||
method: 'GET',
|
||||
path: enrollmentAPIKeyRouteService.getListPath(),
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
query: { kuery: `policy_id: "${agentPolicyId}"` },
|
||||
})
|
||||
.catch(catchAxiosErrorFormatAndThrow)
|
||||
|
@ -222,6 +232,9 @@ export const fetchAgentPolicyList = async (
|
|||
.request<GetAgentPoliciesResponse>({
|
||||
method: 'GET',
|
||||
path: agentPolicyRouteService.getListPath(),
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
query: options,
|
||||
})
|
||||
.catch(catchAxiosErrorFormatAndThrow)
|
||||
|
@ -323,6 +336,7 @@ export const getAgentDownloadUrl = async (
|
|||
* Given a stack version number, function will return the closest Agent download version available
|
||||
* for download. THis could be the actual version passed in or lower.
|
||||
* @param version
|
||||
* @param log
|
||||
*/
|
||||
export const getLatestAgentDownloadVersion = async (
|
||||
version: string,
|
||||
|
@ -386,6 +400,9 @@ export const unEnrollFleetAgent = async (
|
|||
method: 'POST',
|
||||
path: agentRouteService.getUnenrollPath(agentId),
|
||||
body: { revoke: force },
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
})
|
||||
.catch(catchAxiosErrorFormatAndThrow);
|
||||
|
||||
|
|
|
@ -17,8 +17,9 @@ import {
|
|||
FLEET_SERVER_PACKAGE,
|
||||
PACKAGE_POLICY_API_ROUTES,
|
||||
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
|
||||
API_VERSIONS,
|
||||
APP_API_ROUTES,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import { APP_API_ROUTES } from '@kbn/fleet-plugin/common/constants';
|
||||
import type {
|
||||
FleetServerHost,
|
||||
GenerateServiceTokenResponse,
|
||||
|
@ -87,6 +88,9 @@ const getFleetServerPackagePolicy = async (): Promise<PackagePolicy | undefined>
|
|||
.request<GetPackagePoliciesResponse>({
|
||||
method: 'GET',
|
||||
path: PACKAGE_POLICY_API_ROUTES.LIST_PATTERN,
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
query: {
|
||||
perPage: 1,
|
||||
kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: "${FLEET_SERVER_PACKAGE}"`,
|
||||
|
@ -121,6 +125,9 @@ const getOrCreateFleetServerAgentPolicyId = async (): Promise<string> => {
|
|||
.request<CreateAgentPolicyResponse>({
|
||||
method: 'POST',
|
||||
path: AGENT_POLICY_API_ROUTES.CREATE_PATTERN,
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
body: {
|
||||
name: `Fleet Server policy (${Math.random().toString(32).substring(2)})`,
|
||||
description: `Created by CLI Tool via: ${__filename}`,
|
||||
|
@ -150,6 +157,9 @@ const generateFleetServiceToken = async (): Promise<string> => {
|
|||
.request<GenerateServiceTokenResponse>({
|
||||
method: 'POST',
|
||||
path: APP_API_ROUTES.GENERATE_SERVICE_TOKEN_PATTERN,
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
body: {},
|
||||
})
|
||||
.then((response) => response.data.value);
|
||||
|
@ -279,6 +289,9 @@ const configureFleetIfNeeded = async () => {
|
|||
const fleetOutputs = await kbnClient
|
||||
.request<GetOutputsResponse>({
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
path: outputRoutesService.getListPath(),
|
||||
})
|
||||
.then((response) => response.data);
|
||||
|
@ -318,6 +331,9 @@ const configureFleetIfNeeded = async () => {
|
|||
await kbnClient
|
||||
.request<GetOneOutputResponse>({
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
path: outputRoutesService.getUpdatePath(id),
|
||||
body: update,
|
||||
})
|
||||
|
@ -356,6 +372,9 @@ const addFleetServerHostToFleetSettings = async (
|
|||
.request<PostFleetServerHostsResponse>({
|
||||
method: 'POST',
|
||||
path: fleetServerHostsRoutesService.getCreatePath(),
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
body: newFleetHostEntry,
|
||||
})
|
||||
.catch(catchAxiosErrorFormatAndThrow)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import axios from 'axios';
|
||||
import semver from 'semver';
|
||||
import { map } from 'lodash';
|
||||
import { PackagePolicy, CreatePackagePolicyResponse } from '@kbn/fleet-plugin/common';
|
||||
import { PackagePolicy, CreatePackagePolicyResponse, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||
import { KbnClient } from '@kbn/test';
|
||||
import {
|
||||
GetEnrollmentAPIKeysResponse,
|
||||
|
@ -26,7 +26,10 @@ export const getInstalledIntegration = async (kbnClient: KbnClient, integrationN
|
|||
} = await kbnClient.request<{ item: PackagePolicy }>({
|
||||
method: 'GET',
|
||||
path: `/api/fleet/epm/packages/${integrationName}`,
|
||||
headers: DEFAULT_HEADERS,
|
||||
headers: {
|
||||
...DEFAULT_HEADERS,
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
});
|
||||
|
||||
return item;
|
||||
|
@ -46,6 +49,9 @@ export const createAgentPolicy = async (
|
|||
} = await kbnClient.request<CreateAgentPolicyResponse>({
|
||||
method: 'POST',
|
||||
path: `/api/fleet/agent_policies?sys_monitoring=true`,
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
body: {
|
||||
name: agentPolicyName,
|
||||
description: '',
|
||||
|
@ -62,6 +68,9 @@ export const createAgentPolicy = async (
|
|||
log.info('Getting agent enrollment key');
|
||||
const { data: apiKeys } = await kbnClient.request<GetEnrollmentAPIKeysResponse>({
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
path: '/api/fleet/enrollment_api_keys',
|
||||
});
|
||||
|
||||
|
@ -79,6 +88,9 @@ export const addIntegrationToAgentPolicy = async (
|
|||
return kbnClient.request<CreatePackagePolicyResponse>({
|
||||
method: 'POST',
|
||||
path: '/api/fleet/package_policies',
|
||||
headers: {
|
||||
'elastic-api-version': API_VERSIONS.public.v1,
|
||||
},
|
||||
body: {
|
||||
policy_id: agentPolicyId,
|
||||
package: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue