Skip to content

Commit

Permalink
[Fleet] Remove deprecated epm APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Oct 31, 2024
1 parent 9c90029 commit f742465
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 187 deletions.
7 changes: 2 additions & 5 deletions x-pack/plugins/fleet/common/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ export const LIMITED_CONCURRENCY_ROUTE_TAG = 'ingest:limited-concurrency';
const EPM_PACKAGES_MANY = `${EPM_API_ROOT}/packages`;
const EPM_PACKAGES_INSTALLED = `${EPM_API_ROOT}/packages/installed`;
const EPM_PACKAGES_BULK = `${EPM_PACKAGES_MANY}/_bulk`;
const EPM_PACKAGES_ONE_DEPRECATED = `${EPM_PACKAGES_MANY}/{pkgkey}`;
const EPM_PACKAGES_ONE_WITHOUT_VERSION = `${EPM_PACKAGES_MANY}/{pkgName}`;
const EPM_PACKAGES_ONE = `${EPM_PACKAGES_MANY}/{pkgName}/{pkgVersion}`;
export const EPM_API_ROUTES = {
BULK_INSTALL_PATTERN: EPM_PACKAGES_BULK,
LIST_PATTERN: EPM_PACKAGES_MANY,
INSTALLED_LIST_PATTERN: EPM_PACKAGES_INSTALLED,
LIMITED_LIST_PATTERN: `${EPM_PACKAGES_MANY}/limited`,
INFO_WITHOUT_VERSION_PATTERN: EPM_PACKAGES_ONE_WITHOUT_VERSION,
INFO_PATTERN: EPM_PACKAGES_ONE,
DATA_STREAMS_PATTERN: `${EPM_API_ROOT}/data_streams`,
INSTALL_FROM_REGISTRY_PATTERN: EPM_PACKAGES_ONE,
Expand All @@ -45,10 +46,6 @@ export const EPM_API_ROUTES = {
BULK_ASSETS_PATTERN: `${EPM_API_ROOT}/bulk_assets`,
INPUTS_PATTERN: `${EPM_API_ROOT}/templates/{pkgName}/{pkgVersion}/inputs`,

INFO_PATTERN_DEPRECATED: EPM_PACKAGES_ONE_DEPRECATED,
INSTALL_FROM_REGISTRY_PATTERN_DEPRECATED: EPM_PACKAGES_ONE_DEPRECATED,
DELETE_PATTERN_DEPRECATED: EPM_PACKAGES_ONE_DEPRECATED,

REAUTHORIZE_TRANSFORMS: `${EPM_PACKAGES_ONE}/transforms/authorize`,
};

Expand Down
163 changes: 31 additions & 132 deletions x-pack/plugins/fleet/server/routes/epm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* 2.0.
*/

import type { IKibanaResponse } from '@kbn/core/server';

import { parseExperimentalConfigValue } from '../../../common/experimental_features';

import { API_VERSIONS } from '../../../common/constants';
Expand All @@ -20,32 +18,20 @@ import {
} from '../../services/security';
import type { FleetAuthzRouteConfig } from '../../services/security/types';

import type {
DeletePackageResponse,
GetInfoResponse,
InstallPackageResponse,
UpdatePackageResponse,
} from '../../../common/types';

import { EPM_API_ROUTES } from '../../constants';
import { splitPkgKey } from '../../services/epm/registry';
import {
GetCategoriesRequestSchema,
GetPackagesRequestSchema,
GetInstalledPackagesRequestSchema,
GetFileRequestSchema,
GetInfoRequestSchema,
GetInfoRequestSchemaDeprecated,
GetBulkAssetsRequestSchema,
InstallPackageFromRegistryRequestSchema,
InstallPackageFromRegistryRequestSchemaDeprecated,
InstallPackageByUploadRequestSchema,
DeletePackageRequestSchema,
DeletePackageRequestSchemaDeprecated,
BulkInstallPackagesFromRegistryRequestSchema,
GetStatsRequestSchema,
UpdatePackageRequestSchema,
UpdatePackageRequestSchemaDeprecated,
ReauthorizeTransformRequestSchema,
GetDataStreamsRequestSchema,
CreateCustomIntegrationRequestSchema,
Expand Down Expand Up @@ -301,6 +287,37 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
getFileHandler
);

router.versioned
.get({
path: EPM_API_ROUTES.INFO_WITHOUT_VERSION_PATTERN,
fleetAuthz: (fleetAuthz: FleetAuthz): boolean =>
calculateRouteAuthz(
fleetAuthz,
getRouteRequiredAuthz('get', EPM_API_ROUTES.INFO_WITHOUT_VERSION_PATTERN)
).granted,
description: `Get package`,
options: {
tags: ['oas-tag:Elastic Package Manager (EPM)'],
},
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: {
request: GetInfoRequestSchema,
response: {
200: {
body: () => GetInfoResponseSchema,
},
400: {
body: genericErrorResponse,
},
},
},
},
getInfoHandler
);

router.versioned
.get({
path: EPM_API_ROUTES.INFO_PATTERN,
Expand Down Expand Up @@ -648,124 +665,6 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
getBulkAssetsHandler
);

// deprecated since 8.0
// This endpoint should be marked as internal but the router selects this endpoint over the new GET one
// For now keeping it public
router.versioned
.get({
path: EPM_API_ROUTES.INFO_PATTERN_DEPRECATED,
fleetAuthz: (fleetAuthz: FleetAuthz): boolean =>
calculateRouteAuthz(
fleetAuthz,
getRouteRequiredAuthz('get', EPM_API_ROUTES.INFO_PATTERN_DEPRECATED)
).granted,
// @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo}
deprecated: true,
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: { request: GetInfoRequestSchemaDeprecated },
},
async (context, request, response) => {
const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any;
const resp: IKibanaResponse<GetInfoResponse> = await getInfoHandler(
context,
newRequest,
response
);
if (resp.payload?.item) {
// returning item as well here, because pkgVersion is optional in new GET endpoint, and if not specified, the router selects the deprecated route
return response.ok({ body: { item: resp.payload.item, response: resp.payload.item } });
}
return resp;
}
);

router.versioned
.put({
path: EPM_API_ROUTES.INFO_PATTERN_DEPRECATED,
fleetAuthz: {
integrations: { writePackageSettings: true },
},
// @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo}
deprecated: true,
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: { request: UpdatePackageRequestSchemaDeprecated },
},
async (context, request, response) => {
const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any;
const resp: IKibanaResponse<UpdatePackageResponse> = await updatePackageHandler(
context,
newRequest,
response
);
if (resp.payload?.item) {
return response.ok({ body: { response: resp.payload.item } });
}
return resp;
}
);

// This endpoint should be marked as internal but the router selects this endpoint over the new POST
router.versioned
.post({
path: EPM_API_ROUTES.INSTALL_FROM_REGISTRY_PATTERN_DEPRECATED,
fleetAuthz: INSTALL_PACKAGES_AUTHZ,
// @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo}
deprecated: true,
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: { request: InstallPackageFromRegistryRequestSchemaDeprecated },
},
async (context, request, response) => {
const newRequest = {
...request,
params: splitPkgKey(request.params.pkgkey),
query: request.query,
} as any;
const resp: IKibanaResponse<InstallPackageResponse> =
await installPackageFromRegistryHandler(context, newRequest, response);
if (resp.payload?.items) {
return response.ok({ body: { ...resp.payload, response: resp.payload.items } });
}
return resp;
}
);

router.versioned
.delete({
path: EPM_API_ROUTES.DELETE_PATTERN_DEPRECATED,
fleetAuthz: {
integrations: { removePackages: true },
},
// @ts-expect-error TODO(https://github.com/elastic/kibana/issues/196095): Replace {RouteDeprecationInfo}
deprecated: true,
})
.addVersion(
{
version: API_VERSIONS.public.v1,
validate: { request: DeletePackageRequestSchemaDeprecated },
},
async (context, request, response) => {
const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any;
const resp: IKibanaResponse<DeletePackageResponse> = await deletePackageHandler(
context,
newRequest,
response
);
if (resp.payload?.items) {
return response.ok({ body: { response: resp.payload.items } });
}
return resp;
}
);

// Update transforms with es-secondary-authorization headers,
// append authorized_by to transform's _meta, and start transforms
router.versioned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const ROUTE_AUTHZ_REQUIREMENTS = deepFreeze<Record<string, FleetRouteRequiredAut
},
},
},
[`get:${EPM_API_ROUTES.INFO_PATTERN_DEPRECATED}`]: {
[`get:${EPM_API_ROUTES.INFO_WITHOUT_VERSION_PATTERN}`]: {
any: {
integrations: {
readPackageInfo: true,
Expand Down
48 changes: 0 additions & 48 deletions x-pack/plugins/fleet/server/types/rest_spec/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,18 +494,6 @@ export const GetBulkAssetsRequestSchema = {
}),
};

export const GetInfoRequestSchemaDeprecated = {
params: schema.object({
pkgkey: schema.string(),
}),
query: schema.object({
ignoreUnverified: schema.maybe(schema.boolean()),
prerelease: schema.maybe(schema.boolean()),
full: schema.maybe(schema.boolean()),
withMetadata: schema.boolean({ defaultValue: false }),
}),
};

export const UpdatePackageRequestSchema = {
params: schema.object({
pkgName: schema.string(),
Expand All @@ -516,15 +504,6 @@ export const UpdatePackageRequestSchema = {
}),
};

export const UpdatePackageRequestSchemaDeprecated = {
params: schema.object({
pkgkey: schema.string(),
}),
body: schema.object({
keepPoliciesUpToDate: schema.boolean(),
}),
};

export const GetStatsRequestSchema = {
params: schema.object({
pkgName: schema.string(),
Expand Down Expand Up @@ -562,22 +541,6 @@ export const ReauthorizeTransformRequestSchema = {
}),
};

export const InstallPackageFromRegistryRequestSchemaDeprecated = {
params: schema.object({
pkgkey: schema.string(),
}),
query: schema.object({
prerelease: schema.maybe(schema.boolean()),
ignoreMappingUpdateErrors: schema.boolean({ defaultValue: false }),
skipDataStreamRollover: schema.boolean({ defaultValue: false }),
}),
body: schema.nullable(
schema.object({
force: schema.boolean(),
})
),
};

export const BulkInstallPackagesFromRegistryRequestSchema = {
query: schema.object({
prerelease: schema.maybe(schema.boolean()),
Expand Down Expand Up @@ -661,17 +624,6 @@ export const DeleteKibanaAssetsRequestSchema = {
}),
};

export const DeletePackageRequestSchemaDeprecated = {
params: schema.object({
pkgkey: schema.string(),
}),
body: schema.nullable(
schema.object({
force: schema.boolean(),
})
),
};

export const GetInputsRequestSchema = {
params: schema.object({
pkgName: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const fleetGetPackageHttpMock = httpHandlerMockFactory<FleetGetPackageHtt
{
id: 'endpointPackage',
method: 'get',
path: EPM_API_ROUTES.INFO_PATTERN_DEPRECATED,
path: EPM_API_ROUTES.INFO_WITHOUT_VERSION_PATTERN,
handler() {
const generator = new EndpointDocGenerator('seed');

Expand Down

0 comments on commit f742465

Please sign in to comment.