diff --git a/x-pack/plugins/fleet/server/routes/epm/index.ts b/x-pack/plugins/fleet/server/routes/epm/index.ts index 7f92d0284292f..f24752530a501 100644 --- a/x-pack/plugins/fleet/server/routes/epm/index.ts +++ b/x-pack/plugins/fleet/server/routes/epm/index.ts @@ -287,37 +287,6 @@ 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, @@ -375,32 +344,6 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType }, updatePackageHandler ); - router.versioned - .post({ - path: EPM_API_ROUTES.INSTALL_FROM_REGISTRY_WITHOUT_VERSION_PATTERN, - fleetAuthz: INSTALL_PACKAGES_AUTHZ, - description: `Install package from registry`, - options: { - tags: ['oas-tag:Elastic Package Manager (EPM)'], - }, - }) - .addVersion( - { - version: API_VERSIONS.public.v1, - validate: { - request: InstallPackageFromRegistryRequestSchema, - response: { - 200: { - body: () => InstallPackageResponseSchema, - }, - 400: { - body: genericErrorResponse, - }, - }, - }, - }, - installPackageFromRegistryHandler - ); router.versioned .post({ @@ -582,7 +525,7 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType router.versioned .delete({ - path: EPM_API_ROUTES.DELETE_PATTERN_WITHOUT_VERSION_PATTERN, + path: EPM_API_ROUTES.DELETE_PATTERN, fleetAuthz: { integrations: { removePackages: true }, }, @@ -611,12 +554,10 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType ); router.versioned - .delete({ - path: EPM_API_ROUTES.DELETE_PATTERN, - fleetAuthz: { - integrations: { removePackages: true }, - }, - description: `Delete package`, + .get({ + path: EPM_API_ROUTES.VERIFICATION_KEY_ID, + fleetAuthz: READ_PACKAGE_INFO_AUTHZ, + description: `Get a package signature verification key ID`, options: { tags: ['oas-tag:Elastic Package Manager (EPM)'], }, @@ -625,10 +566,10 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType { version: API_VERSIONS.public.v1, validate: { - request: DeletePackageRequestSchema, + request: {}, response: { 200: { - body: () => DeletePackageResponseSchema, + body: () => GetVerificationKeyIdResponseSchema, }, 400: { body: genericErrorResponse, @@ -636,15 +577,41 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType }, }, }, - - deletePackageHandler + getVerificationKeyIdHandler ); router.versioned .get({ - path: EPM_API_ROUTES.VERIFICATION_KEY_ID, + path: EPM_API_ROUTES.DATA_STREAMS_PATTERN, fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - description: `Get a package signature verification key ID`, + description: `List data streams`, + options: { + tags: ['oas-tag:Data streams'], + }, + }) + .addVersion( + { + version: API_VERSIONS.public.v1, + validate: { + request: GetDataStreamsRequestSchema, + response: { + 200: { + body: () => GetDataStreamsResponseSchema, + }, + 400: { + body: genericErrorResponse, + }, + }, + }, + }, + getDataStreamsHandler + ); + + router.versioned + .post({ + path: EPM_API_ROUTES.BULK_ASSETS_PATTERN, + fleetAuthz: READ_PACKAGE_INFO_AUTHZ, + description: `Bulk get assets`, options: { tags: ['oas-tag:Elastic Package Manager (EPM)'], }, @@ -653,10 +620,10 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType { version: API_VERSIONS.public.v1, validate: { - request: {}, + request: GetBulkAssetsRequestSchema, response: { 200: { - body: () => GetVerificationKeyIdResponseSchema, + body: () => GetBulkAssetsResponseSchema, }, 400: { body: genericErrorResponse, @@ -664,26 +631,30 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType }, }, }, - getVerificationKeyIdHandler + getBulkAssetsHandler ); router.versioned .get({ - path: EPM_API_ROUTES.DATA_STREAMS_PATTERN, - fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - description: `List data streams`, + 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:Data streams'], + tags: ['oas-tag:Elastic Package Manager (EPM)'], }, }) .addVersion( { version: API_VERSIONS.public.v1, validate: { - request: GetDataStreamsRequestSchema, + request: GetInfoRequestSchema, response: { 200: { - body: () => GetDataStreamsResponseSchema, + body: () => GetInfoResponseSchema, }, 400: { body: genericErrorResponse, @@ -691,14 +662,14 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType }, }, }, - getDataStreamsHandler + getInfoHandler ); router.versioned .post({ - path: EPM_API_ROUTES.BULK_ASSETS_PATTERN, - fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - description: `Bulk get assets`, + path: EPM_API_ROUTES.INSTALL_FROM_REGISTRY_WITHOUT_VERSION_PATTERN, + fleetAuthz: INSTALL_PACKAGES_AUTHZ, + description: `Install package from registry`, options: { tags: ['oas-tag:Elastic Package Manager (EPM)'], }, @@ -707,10 +678,10 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType { version: API_VERSIONS.public.v1, validate: { - request: GetBulkAssetsRequestSchema, + request: InstallPackageFromRegistryRequestSchema, response: { 200: { - body: () => GetBulkAssetsResponseSchema, + body: () => InstallPackageResponseSchema, }, 400: { body: genericErrorResponse, @@ -718,7 +689,37 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType }, }, }, - getBulkAssetsHandler + installPackageFromRegistryHandler + ); + + router.versioned + .delete({ + path: EPM_API_ROUTES.DELETE_PATTERN_WITHOUT_VERSION_PATTERN, + fleetAuthz: { + integrations: { removePackages: true }, + }, + description: `Delete package`, + options: { + tags: ['oas-tag:Elastic Package Manager (EPM)'], + }, + }) + .addVersion( + { + version: API_VERSIONS.public.v1, + validate: { + request: DeletePackageRequestSchema, + response: { + 200: { + body: () => DeletePackageResponseSchema, + }, + 400: { + body: genericErrorResponse, + }, + }, + }, + }, + + deletePackageHandler ); // Update transforms with es-secondary-authorization headers, diff --git a/x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/rules/prebuilt_rules/delete_endpoint_fleet_package.ts b/x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/rules/prebuilt_rules/delete_endpoint_fleet_package.ts index e53e24f98de3b..cea8363d9085c 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/rules/prebuilt_rules/delete_endpoint_fleet_package.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/rules/prebuilt_rules/delete_endpoint_fleet_package.ts @@ -21,9 +21,9 @@ export async function deleteEndpointFleetPackage(supertest: SuperTest.Agent) { .set('elastic-api-version', '2023-10-31') .send(); - if (resp.status === 200 && resp.body.response.status === 'installed') { + if (resp.status === 200 && resp.body.item.status === 'installed') { await supertest - .delete(epmRouteService.getRemovePath(ENDPOINT_PACKAGE_NAME, resp.body.response.version)) + .delete(epmRouteService.getRemovePath(ENDPOINT_PACKAGE_NAME, resp.body.item.version)) .set('kbn-xsrf', 'true') .send({ force: true }); } diff --git a/x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/rules/prebuilt_rules/delete_prebuilt_rules_fleet_package.ts b/x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/rules/prebuilt_rules/delete_prebuilt_rules_fleet_package.ts index 930c9d39757f4..084d59c55df0d 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/rules/prebuilt_rules/delete_prebuilt_rules_fleet_package.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/detections_response/utils/rules/prebuilt_rules/delete_prebuilt_rules_fleet_package.ts @@ -21,11 +21,9 @@ export async function deletePrebuiltRulesFleetPackage(supertest: SuperTest.Agent .set('elastic-api-version', '2023-10-31') .send(); - if (resp.status === 200 && resp.body.response.status === 'installed') { + if (resp.status === 200 && resp.body.item.status === 'installed') { await supertest - .delete( - epmRouteService.getRemovePath(PREBUILT_RULES_PACKAGE_NAME, resp.body.response.version) - ) + .delete(epmRouteService.getRemovePath(PREBUILT_RULES_PACKAGE_NAME, resp.body.item.version)) .set('kbn-xsrf', 'true') .send({ force: true }); }