diff --git a/x-pack/plugins/index_management/kibana.json b/x-pack/plugins/index_management/kibana.json index 5dcff0ba942e1..cd29e7b9ee1cd 100644 --- a/x-pack/plugins/index_management/kibana.json +++ b/x-pack/plugins/index_management/kibana.json @@ -3,7 +3,7 @@ "version": "kibana", "server": true, "ui": true, - "requiredPlugins": ["home", "licensing", "management", "features", "share"], + "requiredPlugins": ["home", "management", "features", "share"], "optionalPlugins": ["security", "usageCollection", "fleet"], "configPath": ["xpack", "index_management"], "requiredBundles": [ diff --git a/x-pack/plugins/index_management/server/plugin.ts b/x-pack/plugins/index_management/server/plugin.ts index d2ef5a7eed6e7..35d25eb452b84 100644 --- a/x-pack/plugins/index_management/server/plugin.ts +++ b/x-pack/plugins/index_management/server/plugin.ts @@ -5,11 +5,9 @@ * 2.0. */ -import { i18n } from '@kbn/i18n'; import { CoreSetup, Plugin, - Logger, PluginInitializerContext, ILegacyCustomClusterClient, } from 'src/core/server'; @@ -17,7 +15,7 @@ import { import { PLUGIN } from '../common/constants/plugin'; import { Dependencies } from './types'; import { ApiRoutes } from './routes'; -import { License, IndexDataEnricher } from './services'; +import { IndexDataEnricher } from './services'; import { isEsError, handleEsError, parseEsError } from './shared_imports'; import { elasticsearchJsPlugin } from './client/elasticsearch'; import type { IndexManagementRequestHandlerContext } from './types'; @@ -36,38 +34,20 @@ async function getCustomEsClient(getStartServices: CoreSetup['getStartServices'] export class IndexMgmtServerPlugin implements Plugin { private readonly apiRoutes: ApiRoutes; - private readonly license: License; - private readonly logger: Logger; private readonly indexDataEnricher: IndexDataEnricher; private dataManagementESClient?: ILegacyCustomClusterClient; constructor(initContext: PluginInitializerContext) { - this.logger = initContext.logger.get(); this.apiRoutes = new ApiRoutes(); - this.license = new License(); this.indexDataEnricher = new IndexDataEnricher(); } setup( { http, getStartServices }: CoreSetup, - { features, licensing, security }: Dependencies + { features, security }: Dependencies ): IndexManagementPluginSetup { const router = http.createRouter(); - this.license.setup( - { - pluginId: PLUGIN.id, - minimumLicenseType: PLUGIN.minimumLicenseType, - defaultErrorMessage: i18n.translate('xpack.idxMgmt.licenseCheckErrorMessage', { - defaultMessage: 'License check failed', - }), - }, - { - licensing, - logger: this.logger, - } - ); - features.registerElasticsearchFeature({ id: PLUGIN.id, management: { @@ -97,7 +77,6 @@ export class IndexMgmtServerPlugin implements Plugin security !== undefined && security.license.isEnabled(), }, diff --git a/x-pack/plugins/index_management/server/routes/api/component_templates/create.ts b/x-pack/plugins/index_management/server/routes/api/component_templates/create.ts index a6c0592e035e7..4bf05b44c43a7 100644 --- a/x-pack/plugins/index_management/server/routes/api/component_templates/create.ts +++ b/x-pack/plugins/index_management/server/routes/api/component_templates/create.ts @@ -12,11 +12,7 @@ import { RouteDependencies } from '../../../types'; import { addBasePath } from '../index'; import { componentTemplateSchema } from './schema_validation'; -export const registerCreateRoute = ({ - router, - license, - lib: { isEsError }, -}: RouteDependencies): void => { +export const registerCreateRoute = ({ router, lib: { isEsError } }: RouteDependencies): void => { router.post( { path: addBasePath('/component_templates'), @@ -24,7 +20,7 @@ export const registerCreateRoute = ({ body: componentTemplateSchema, }, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { callAsCurrentUser } = ctx.dataManagement!.client; const serializedComponentTemplate = serializeComponentTemplate(req.body); @@ -73,6 +69,6 @@ export const registerCreateRoute = ({ throw error; } - }) + } ); }; diff --git a/x-pack/plugins/index_management/server/routes/api/component_templates/delete.ts b/x-pack/plugins/index_management/server/routes/api/component_templates/delete.ts index abf04da638caf..d30f54f6e44ad 100644 --- a/x-pack/plugins/index_management/server/routes/api/component_templates/delete.ts +++ b/x-pack/plugins/index_management/server/routes/api/component_templates/delete.ts @@ -14,7 +14,7 @@ const paramsSchema = schema.object({ names: schema.string(), }); -export const registerDeleteRoute = ({ router, license }: RouteDependencies): void => { +export const registerDeleteRoute = ({ router }: RouteDependencies): void => { router.delete( { path: addBasePath('/component_templates/{names}'), @@ -22,7 +22,7 @@ export const registerDeleteRoute = ({ router, license }: RouteDependencies): voi params: paramsSchema, }, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { callAsCurrentUser } = ctx.dataManagement!.client; const { names } = req.params; const componentNames = names.split(','); @@ -48,6 +48,6 @@ export const registerDeleteRoute = ({ router, license }: RouteDependencies): voi ); return res.ok({ body: response }); - }) + } ); }; diff --git a/x-pack/plugins/index_management/server/routes/api/component_templates/get.ts b/x-pack/plugins/index_management/server/routes/api/component_templates/get.ts index 552aa5a9a2888..a5d70e65f870a 100644 --- a/x-pack/plugins/index_management/server/routes/api/component_templates/get.ts +++ b/x-pack/plugins/index_management/server/routes/api/component_templates/get.ts @@ -19,11 +19,11 @@ const paramsSchema = schema.object({ name: schema.string(), }); -export function registerGetAllRoute({ router, license, lib: { isEsError } }: RouteDependencies) { +export function registerGetAllRoute({ router, lib: { isEsError } }: RouteDependencies) { // Get all component templates router.get( { path: addBasePath('/component_templates'), validate: false }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { callAsCurrentUser } = ctx.dataManagement!.client; try { @@ -56,7 +56,7 @@ export function registerGetAllRoute({ router, license, lib: { isEsError } }: Rou throw error; } - }) + } ); // Get single component template @@ -67,7 +67,7 @@ export function registerGetAllRoute({ router, license, lib: { isEsError } }: Rou params: paramsSchema, }, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { callAsCurrentUser } = ctx.dataManagement!.client; const { name } = req.params; @@ -96,6 +96,6 @@ export function registerGetAllRoute({ router, license, lib: { isEsError } }: Rou throw error; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.test.ts b/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.test.ts index 62fb228a34ced..eccf2d945785f 100644 --- a/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.test.ts +++ b/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.test.ts @@ -8,7 +8,6 @@ import { httpServerMock, httpServiceMock } from 'src/core/server/mocks'; import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; -import { License } from '../../../services/license'; import { IndexDataEnricher } from '../../../services/index_data_enricher'; import { registerPrivilegesRoute } from './privileges'; @@ -47,9 +46,6 @@ describe('GET privileges', () => { registerPrivilegesRoute({ router, - license: { - guardApiRoute: (route: any) => route, - } as License, config: { isSecurityEnabled: () => true, }, @@ -118,9 +114,6 @@ describe('GET privileges', () => { registerPrivilegesRoute({ router, - license: { - guardApiRoute: (route: any) => route, - } as License, config: { isSecurityEnabled: () => false, }, diff --git a/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.ts b/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.ts index 1ed6555eb3806..62ad93453091e 100644 --- a/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.ts +++ b/x-pack/plugins/index_management/server/routes/api/component_templates/privileges.ts @@ -17,13 +17,13 @@ const extractMissingPrivileges = (privilegesObject: { [key: string]: boolean } = return privileges; }, []); -export const registerPrivilegesRoute = ({ license, router, config }: RouteDependencies) => { +export const registerPrivilegesRoute = ({ router, config }: RouteDependencies) => { router.get( { path: addBasePath('/component_templates/privileges'), validate: false, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const privilegesResult: Privileges = { hasAllPrivileges: true, missingPrivileges: { @@ -66,6 +66,6 @@ export const registerPrivilegesRoute = ({ license, router, config }: RouteDepend } catch (e) { throw e; } - }) + } ); }; diff --git a/x-pack/plugins/index_management/server/routes/api/component_templates/update.ts b/x-pack/plugins/index_management/server/routes/api/component_templates/update.ts index 42b53ab6ee25b..ee94b8f2b0082 100644 --- a/x-pack/plugins/index_management/server/routes/api/component_templates/update.ts +++ b/x-pack/plugins/index_management/server/routes/api/component_templates/update.ts @@ -15,11 +15,7 @@ const paramsSchema = schema.object({ name: schema.string(), }); -export const registerUpdateRoute = ({ - router, - license, - lib: { isEsError }, -}: RouteDependencies): void => { +export const registerUpdateRoute = ({ router, lib: { isEsError } }: RouteDependencies): void => { router.put( { path: addBasePath('/component_templates/{name}'), @@ -28,7 +24,7 @@ export const registerUpdateRoute = ({ params: paramsSchema, }, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { callAsCurrentUser } = ctx.dataManagement!.client; const { name } = req.params; const { template, version, _meta } = req.body; @@ -57,6 +53,6 @@ export const registerUpdateRoute = ({ throw error; } - }) + } ); }; diff --git a/x-pack/plugins/index_management/server/routes/api/data_streams/register_delete_route.ts b/x-pack/plugins/index_management/server/routes/api/data_streams/register_delete_route.ts index 476228cfce2fc..49166f4823a02 100644 --- a/x-pack/plugins/index_management/server/routes/api/data_streams/register_delete_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/data_streams/register_delete_route.ts @@ -15,13 +15,13 @@ const bodySchema = schema.object({ dataStreams: schema.arrayOf(schema.string()), }); -export function registerDeleteRoute({ router, license }: RouteDependencies) { +export function registerDeleteRoute({ router }: RouteDependencies) { router.post( { path: addBasePath('/delete_data_streams'), validate: { body: bodySchema }, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { callAsCurrentUser } = ctx.dataManagement!.client; const { dataStreams } = req.body as TypeOf; @@ -48,6 +48,6 @@ export function registerDeleteRoute({ router, license }: RouteDependencies) { ); return res.ok({ body: response }); - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts b/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts index 9573b9cc6436f..1ce7c14f0a209 100644 --- a/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts @@ -103,18 +103,13 @@ const getDataStreamsPrivileges = (client: ElasticsearchClient, names: string[]) }); }; -export function registerGetAllRoute({ - router, - license, - lib: { handleEsError }, - config, -}: RouteDependencies) { +export function registerGetAllRoute({ router, lib: { handleEsError }, config }: RouteDependencies) { const querySchema = schema.object({ includeStats: schema.maybe(schema.oneOf([schema.literal('true'), schema.literal('false')])), }); router.get( { path: addBasePath('/data_streams'), validate: { query: querySchema } }, - license.guardApiRoute(async (ctx, req, response) => { + async (ctx, req, response) => { const { asCurrentUser } = ctx.core.elasticsearch.client; const includeStats = (req.query as TypeOf).includeStats === 'true'; @@ -151,16 +146,11 @@ export function registerGetAllRoute({ } catch (error) { return handleEsError({ error, response }); } - }) + } ); } -export function registerGetOneRoute({ - router, - license, - lib: { handleEsError }, - config, -}: RouteDependencies) { +export function registerGetOneRoute({ router, lib: { handleEsError }, config }: RouteDependencies) { const paramsSchema = schema.object({ name: schema.string(), }); @@ -169,7 +159,7 @@ export function registerGetOneRoute({ path: addBasePath('/data_streams/{name}'), validate: { params: paramsSchema }, }, - license.guardApiRoute(async (ctx, req, response) => { + async (ctx, req, response) => { const { name } = req.params as TypeOf; const { asCurrentUser } = ctx.core.elasticsearch.client; try { @@ -207,6 +197,6 @@ export function registerGetOneRoute({ } catch (error) { return handleEsError({ error, response }); } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_clear_cache_route.ts b/x-pack/plugins/index_management/server/routes/api/indices/register_clear_cache_route.ts index 2f5da4b1d8957..593f0cda6886e 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_clear_cache_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_clear_cache_route.ts @@ -14,10 +14,10 @@ const bodySchema = schema.object({ indices: schema.arrayOf(schema.string()), }); -export function registerClearCacheRoute({ router, license, lib }: RouteDependencies) { +export function registerClearCacheRoute({ router, lib }: RouteDependencies) { router.post( { path: addBasePath('/indices/clear_cache'), validate: { body: bodySchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const payload = req.body as typeof bodySchema.type; const { indices = [] } = payload; @@ -40,6 +40,6 @@ export function registerClearCacheRoute({ router, license, lib }: RouteDependenc // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_close_route.ts b/x-pack/plugins/index_management/server/routes/api/indices/register_close_route.ts index 1a0babfc3a5b1..777adcd055709 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_close_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_close_route.ts @@ -14,10 +14,10 @@ const bodySchema = schema.object({ indices: schema.arrayOf(schema.string()), }); -export function registerCloseRoute({ router, license, lib }: RouteDependencies) { +export function registerCloseRoute({ router, lib }: RouteDependencies) { router.post( { path: addBasePath('/indices/close'), validate: { body: bodySchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const payload = req.body as typeof bodySchema.type; const { indices = [] } = payload; @@ -40,6 +40,6 @@ export function registerCloseRoute({ router, license, lib }: RouteDependencies) // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_delete_route.ts b/x-pack/plugins/index_management/server/routes/api/indices/register_delete_route.ts index 9a022d4595d1c..914835089a438 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_delete_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_delete_route.ts @@ -14,10 +14,10 @@ const bodySchema = schema.object({ indices: schema.arrayOf(schema.string()), }); -export function registerDeleteRoute({ router, license, lib }: RouteDependencies) { +export function registerDeleteRoute({ router, lib }: RouteDependencies) { router.post( { path: addBasePath('/indices/delete'), validate: { body: bodySchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const body = req.body as typeof bodySchema.type; const { indices = [] } = body; @@ -40,6 +40,6 @@ export function registerDeleteRoute({ router, license, lib }: RouteDependencies) // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_flush_route.ts b/x-pack/plugins/index_management/server/routes/api/indices/register_flush_route.ts index b064f3520004a..bb1759a034cc7 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_flush_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_flush_route.ts @@ -14,10 +14,10 @@ const bodySchema = schema.object({ indices: schema.arrayOf(schema.string()), }); -export function registerFlushRoute({ router, license, lib }: RouteDependencies) { +export function registerFlushRoute({ router, lib }: RouteDependencies) { router.post( { path: addBasePath('/indices/flush'), validate: { body: bodySchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const body = req.body as typeof bodySchema.type; const { indices = [] } = body; @@ -40,6 +40,6 @@ export function registerFlushRoute({ router, license, lib }: RouteDependencies) // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_forcemerge_route.ts b/x-pack/plugins/index_management/server/routes/api/indices/register_forcemerge_route.ts index 1c14f660b98c6..6f0e8f0fec567 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_forcemerge_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_forcemerge_route.ts @@ -15,7 +15,7 @@ const bodySchema = schema.object({ maxNumSegments: schema.maybe(schema.number()), }); -export function registerForcemergeRoute({ router, license, lib }: RouteDependencies) { +export function registerForcemergeRoute({ router, lib }: RouteDependencies) { router.post( { path: addBasePath('/indices/forcemerge'), @@ -23,7 +23,7 @@ export function registerForcemergeRoute({ router, license, lib }: RouteDependenc body: bodySchema, }, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { maxNumSegments, indices = [] } = req.body as typeof bodySchema.type; const params = { expandWildcards: 'none', @@ -47,6 +47,6 @@ export function registerForcemergeRoute({ router, license, lib }: RouteDependenc // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_freeze_route.ts b/x-pack/plugins/index_management/server/routes/api/indices/register_freeze_route.ts index b669d78f2ba59..4b1281e0f2121 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_freeze_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_freeze_route.ts @@ -14,10 +14,10 @@ const bodySchema = schema.object({ indices: schema.arrayOf(schema.string()), }); -export function registerFreezeRoute({ router, license, lib }: RouteDependencies) { +export function registerFreezeRoute({ router, lib }: RouteDependencies) { router.post( { path: addBasePath('/indices/freeze'), validate: { body: bodySchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const body = req.body as typeof bodySchema.type; const { indices = [] } = body; @@ -42,6 +42,6 @@ export function registerFreezeRoute({ router, license, lib }: RouteDependencies) // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_list_route.ts b/x-pack/plugins/index_management/server/routes/api/indices/register_list_route.ts index 0b253b9fe66c9..47c454e96c8e2 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_list_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_list_route.ts @@ -9,26 +9,23 @@ import { fetchIndices } from '../../../lib/fetch_indices'; import { RouteDependencies } from '../../../types'; import { addBasePath } from '../index'; -export function registerListRoute({ router, license, indexDataEnricher, lib }: RouteDependencies) { - router.get( - { path: addBasePath('/indices'), validate: false }, - license.guardApiRoute(async (ctx, req, res) => { - try { - const indices = await fetchIndices( - ctx.core.elasticsearch.legacy.client.callAsCurrentUser, - indexDataEnricher - ); - return res.ok({ body: indices }); - } catch (e) { - if (lib.isEsError(e)) { - return res.customError({ - statusCode: e.statusCode, - body: e, - }); - } - // Case: default - throw e; +export function registerListRoute({ router, indexDataEnricher, lib }: RouteDependencies) { + router.get({ path: addBasePath('/indices'), validate: false }, async (ctx, req, res) => { + try { + const indices = await fetchIndices( + ctx.core.elasticsearch.legacy.client.callAsCurrentUser, + indexDataEnricher + ); + return res.ok({ body: indices }); + } catch (e) { + if (lib.isEsError(e)) { + return res.customError({ + statusCode: e.statusCode, + body: e, + }); } - }) - ); + // Case: default + throw e; + } + }); } diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_open_route.ts b/x-pack/plugins/index_management/server/routes/api/indices/register_open_route.ts index a35ddfcf4d91b..cad57ce60de65 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_open_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_open_route.ts @@ -14,10 +14,10 @@ const bodySchema = schema.object({ indices: schema.arrayOf(schema.string()), }); -export function registerOpenRoute({ router, license, lib }: RouteDependencies) { +export function registerOpenRoute({ router, lib }: RouteDependencies) { router.post( { path: addBasePath('/indices/open'), validate: { body: bodySchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const body = req.body as typeof bodySchema.type; const { indices = [] } = body; @@ -40,6 +40,6 @@ export function registerOpenRoute({ router, license, lib }: RouteDependencies) { // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_refresh_route.ts b/x-pack/plugins/index_management/server/routes/api/indices/register_refresh_route.ts index f69d2d90a5b8f..e2c0155e28086 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_refresh_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_refresh_route.ts @@ -14,10 +14,10 @@ const bodySchema = schema.object({ indices: schema.arrayOf(schema.string()), }); -export function registerRefreshRoute({ router, license, lib }: RouteDependencies) { +export function registerRefreshRoute({ router, lib }: RouteDependencies) { router.post( { path: addBasePath('/indices/refresh'), validate: { body: bodySchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const body = req.body as typeof bodySchema.type; const { indices = [] } = body; @@ -40,6 +40,6 @@ export function registerRefreshRoute({ router, license, lib }: RouteDependencies // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_reload_route.ts b/x-pack/plugins/index_management/server/routes/api/indices/register_reload_route.ts index 04b7d760fc1d6..8d83cd21f427d 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_reload_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_reload_route.ts @@ -17,15 +17,10 @@ const bodySchema = schema.maybe( }) ); -export function registerReloadRoute({ - router, - license, - indexDataEnricher, - lib, -}: RouteDependencies) { +export function registerReloadRoute({ router, indexDataEnricher, lib }: RouteDependencies) { router.post( { path: addBasePath('/indices/reload'), validate: { body: bodySchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { indexNames = [] } = (req.body as typeof bodySchema.type) ?? {}; try { @@ -45,6 +40,6 @@ export function registerReloadRoute({ // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/indices/register_unfreeze_route.ts b/x-pack/plugins/index_management/server/routes/api/indices/register_unfreeze_route.ts index 3cda4d6b5f168..45102f4874129 100644 --- a/x-pack/plugins/index_management/server/routes/api/indices/register_unfreeze_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/indices/register_unfreeze_route.ts @@ -14,10 +14,10 @@ const bodySchema = schema.object({ indices: schema.arrayOf(schema.string()), }); -export function registerUnfreezeRoute({ router, license, lib }: RouteDependencies) { +export function registerUnfreezeRoute({ router, lib }: RouteDependencies) { router.post( { path: addBasePath('/indices/unfreeze'), validate: { body: bodySchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { indices = [] } = req.body as typeof bodySchema.type; const params = { path: `/${encodeURIComponent(indices.join(','))}/_unfreeze`, @@ -37,6 +37,6 @@ export function registerUnfreezeRoute({ router, license, lib }: RouteDependencie // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/mapping/register_mapping_route.ts b/x-pack/plugins/index_management/server/routes/api/mapping/register_mapping_route.ts index f0b62bacdee42..406ceba16c8bd 100644 --- a/x-pack/plugins/index_management/server/routes/api/mapping/register_mapping_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/mapping/register_mapping_route.ts @@ -21,10 +21,10 @@ function formatHit(hit: { [key: string]: { mappings: any } }, indexName: string) }; } -export function registerMappingRoute({ router, license, lib }: RouteDependencies) { +export function registerMappingRoute({ router, lib }: RouteDependencies) { router.get( { path: addBasePath('/mapping/{indexName}'), validate: { params: paramsSchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { indexName } = req.params as typeof paramsSchema.type; const params = { expand_wildcards: 'none', @@ -48,6 +48,6 @@ export function registerMappingRoute({ router, license, lib }: RouteDependencies // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/settings/register_load_route.ts b/x-pack/plugins/index_management/server/routes/api/settings/register_load_route.ts index 7a661a9e9e4f4..276b326929e8f 100644 --- a/x-pack/plugins/index_management/server/routes/api/settings/register_load_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/settings/register_load_route.ts @@ -21,10 +21,10 @@ function formatHit(hit: { [key: string]: {} }) { return hit[key]; } -export function registerLoadRoute({ router, license, lib }: RouteDependencies) { +export function registerLoadRoute({ router, lib }: RouteDependencies) { router.get( { path: addBasePath('/settings/{indexName}'), validate: { params: paramsSchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { indexName } = req.params as typeof paramsSchema.type; const params = { expandWildcards: 'none', @@ -50,6 +50,6 @@ export function registerLoadRoute({ router, license, lib }: RouteDependencies) { // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/settings/register_update_route.ts b/x-pack/plugins/index_management/server/routes/api/settings/register_update_route.ts index 4c153d6293a79..b4f12b91083df 100644 --- a/x-pack/plugins/index_management/server/routes/api/settings/register_update_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/settings/register_update_route.ts @@ -16,13 +16,13 @@ const paramsSchema = schema.object({ indexName: schema.string(), }); -export function registerUpdateRoute({ router, license, lib }: RouteDependencies) { +export function registerUpdateRoute({ router, lib }: RouteDependencies) { router.put( { path: addBasePath('/settings/{indexName}'), validate: { body: bodySchema, params: paramsSchema }, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { indexName } = req.params as typeof paramsSchema.type; const params = { ignoreUnavailable: true, @@ -48,6 +48,6 @@ export function registerUpdateRoute({ router, license, lib }: RouteDependencies) // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/stats/register_stats_route.ts b/x-pack/plugins/index_management/server/routes/api/stats/register_stats_route.ts index f8385711b55fe..42a3012ea8e17 100644 --- a/x-pack/plugins/index_management/server/routes/api/stats/register_stats_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/stats/register_stats_route.ts @@ -23,10 +23,10 @@ function formatHit(hit: { _shards: any; indices: { [key: string]: any } }, index }; } -export function registerStatsRoute({ router, license, lib }: RouteDependencies) { +export function registerStatsRoute({ router, lib }: RouteDependencies) { router.get( { path: addBasePath('/stats/{indexName}'), validate: { params: paramsSchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { indexName } = req.params as typeof paramsSchema.type; const params = { expand_wildcards: 'none', @@ -49,6 +49,6 @@ export function registerStatsRoute({ router, license, lib }: RouteDependencies) // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/templates/register_create_route.ts b/x-pack/plugins/index_management/server/routes/api/templates/register_create_route.ts index 97e3c380e13ec..d8a236bdebd15 100644 --- a/x-pack/plugins/index_management/server/routes/api/templates/register_create_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/templates/register_create_route.ts @@ -15,10 +15,10 @@ import { saveTemplate, doesTemplateExist } from './lib'; const bodySchema = templateSchema; -export function registerCreateRoute({ router, license, lib }: RouteDependencies) { +export function registerCreateRoute({ router, lib }: RouteDependencies) { router.post( { path: addBasePath('/index_templates'), validate: { body: bodySchema } }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { callAsCurrentUser } = ctx.dataManagement!.client; const template = req.body as TemplateDeserialized; const { @@ -64,6 +64,6 @@ export function registerCreateRoute({ router, license, lib }: RouteDependencies) // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/templates/register_delete_route.ts b/x-pack/plugins/index_management/server/routes/api/templates/register_delete_route.ts index e258fafa534e3..083964dec9edc 100644 --- a/x-pack/plugins/index_management/server/routes/api/templates/register_delete_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/templates/register_delete_route.ts @@ -22,13 +22,13 @@ const bodySchema = schema.object({ ), }); -export function registerDeleteRoute({ router, license }: RouteDependencies) { +export function registerDeleteRoute({ router }: RouteDependencies) { router.post( { path: addBasePath('/delete_index_templates'), validate: { body: bodySchema }, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { callAsCurrentUser } = ctx.dataManagement!.client; const { templates } = req.body as TypeOf; const response: { templatesDeleted: Array; errors: any[] } = { @@ -60,6 +60,6 @@ export function registerDeleteRoute({ router, license }: RouteDependencies) { ); return res.ok({ body: response }); - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/templates/register_get_routes.ts b/x-pack/plugins/index_management/server/routes/api/templates/register_get_routes.ts index 006532cfd4dbe..bd000186d91c4 100644 --- a/x-pack/plugins/index_management/server/routes/api/templates/register_get_routes.ts +++ b/x-pack/plugins/index_management/server/routes/api/templates/register_get_routes.ts @@ -17,32 +17,29 @@ import { getCloudManagedTemplatePrefix } from '../../../lib/get_managed_template import { RouteDependencies } from '../../../types'; import { addBasePath } from '../index'; -export function registerGetAllRoute({ router, license }: RouteDependencies) { - router.get( - { path: addBasePath('/index_templates'), validate: false }, - license.guardApiRoute(async (ctx, req, res) => { - const { callAsCurrentUser } = ctx.dataManagement!.client; - const cloudManagedTemplatePrefix = await getCloudManagedTemplatePrefix(callAsCurrentUser); - - const legacyTemplatesEs = await callAsCurrentUser('indices.getTemplate'); - const { index_templates: templatesEs } = await callAsCurrentUser( - 'dataManagement.getComposableIndexTemplates' - ); - - const legacyTemplates = deserializeLegacyTemplateList( - legacyTemplatesEs, - cloudManagedTemplatePrefix - ); - const templates = deserializeTemplateList(templatesEs, cloudManagedTemplatePrefix); - - const body = { - templates, - legacyTemplates, - }; - - return res.ok({ body }); - }) - ); +export function registerGetAllRoute({ router }: RouteDependencies) { + router.get({ path: addBasePath('/index_templates'), validate: false }, async (ctx, req, res) => { + const { callAsCurrentUser } = ctx.dataManagement!.client; + const cloudManagedTemplatePrefix = await getCloudManagedTemplatePrefix(callAsCurrentUser); + + const legacyTemplatesEs = await callAsCurrentUser('indices.getTemplate'); + const { index_templates: templatesEs } = await callAsCurrentUser( + 'dataManagement.getComposableIndexTemplates' + ); + + const legacyTemplates = deserializeLegacyTemplateList( + legacyTemplatesEs, + cloudManagedTemplatePrefix + ); + const templates = deserializeTemplateList(templatesEs, cloudManagedTemplatePrefix); + + const body = { + templates, + legacyTemplates, + }; + + return res.ok({ body }); + }); } const paramsSchema = schema.object({ @@ -54,13 +51,13 @@ const querySchema = schema.object({ legacy: schema.maybe(schema.oneOf([schema.literal('true'), schema.literal('false')])), }); -export function registerGetOneRoute({ router, license, lib }: RouteDependencies) { +export function registerGetOneRoute({ router, lib }: RouteDependencies) { router.get( { path: addBasePath('/index_templates/{name}'), validate: { params: paramsSchema, query: querySchema }, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { name } = req.params as TypeOf; const { callAsCurrentUser } = ctx.dataManagement!.client; @@ -106,6 +103,6 @@ export function registerGetOneRoute({ router, license, lib }: RouteDependencies) // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/templates/register_simulate_route.ts b/x-pack/plugins/index_management/server/routes/api/templates/register_simulate_route.ts index f4554bd2fb1fa..0c3d8faea628c 100644 --- a/x-pack/plugins/index_management/server/routes/api/templates/register_simulate_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/templates/register_simulate_route.ts @@ -12,13 +12,13 @@ import { addBasePath } from '../index'; const bodySchema = schema.object({}, { unknowns: 'allow' }); -export function registerSimulateRoute({ router, license, lib }: RouteDependencies) { +export function registerSimulateRoute({ router, lib }: RouteDependencies) { router.post( { path: addBasePath('/index_templates/simulate'), validate: { body: bodySchema }, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { callAsCurrentUser } = ctx.dataManagement!.client; const template = req.body as TypeOf; @@ -42,6 +42,6 @@ export function registerSimulateRoute({ router, license, lib }: RouteDependencie // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/routes/api/templates/register_update_route.ts b/x-pack/plugins/index_management/server/routes/api/templates/register_update_route.ts index f0070408768cb..07a7d457f0473 100644 --- a/x-pack/plugins/index_management/server/routes/api/templates/register_update_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/templates/register_update_route.ts @@ -18,13 +18,13 @@ const paramsSchema = schema.object({ name: schema.string(), }); -export function registerUpdateRoute({ router, license, lib }: RouteDependencies) { +export function registerUpdateRoute({ router, lib }: RouteDependencies) { router.put( { path: addBasePath('/index_templates/{name}'), validate: { body: bodySchema, params: paramsSchema }, }, - license.guardApiRoute(async (ctx, req, res) => { + async (ctx, req, res) => { const { callAsCurrentUser } = ctx.dataManagement!.client; const { name } = req.params as typeof paramsSchema.type; const template = req.body as TemplateDeserialized; @@ -58,6 +58,6 @@ export function registerUpdateRoute({ router, license, lib }: RouteDependencies) // Case: default throw e; } - }) + } ); } diff --git a/x-pack/plugins/index_management/server/services/index.ts b/x-pack/plugins/index_management/server/services/index.ts index 3af5117e2b7aa..576d7c46fa086 100644 --- a/x-pack/plugins/index_management/server/services/index.ts +++ b/x-pack/plugins/index_management/server/services/index.ts @@ -5,6 +5,4 @@ * 2.0. */ -export { License } from './license'; - export { IndexDataEnricher, Enricher } from './index_data_enricher'; diff --git a/x-pack/plugins/index_management/server/services/license.ts b/x-pack/plugins/index_management/server/services/license.ts deleted file mode 100644 index 0898c01a1e466..0000000000000 --- a/x-pack/plugins/index_management/server/services/license.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { Logger } from 'src/core/server'; -import type { KibanaRequest, KibanaResponseFactory, RequestHandler } from 'kibana/server'; - -import { LicensingPluginSetup } from '../../../licensing/server'; -import { LicenseType } from '../../../licensing/common/types'; -import type { IndexManagementRequestHandlerContext } from '../types'; - -export interface LicenseStatus { - isValid: boolean; - message?: string; -} - -interface SetupSettings { - pluginId: string; - minimumLicenseType: LicenseType; - defaultErrorMessage: string; -} - -export class License { - private licenseStatus: LicenseStatus = { - isValid: false, - message: 'Invalid License', - }; - - setup( - { pluginId, minimumLicenseType, defaultErrorMessage }: SetupSettings, - { licensing, logger }: { licensing: LicensingPluginSetup; logger: Logger } - ) { - licensing.license$.subscribe((license) => { - const { state, message } = license.check(pluginId, minimumLicenseType); - const hasRequiredLicense = state === 'valid'; - - if (hasRequiredLicense) { - this.licenseStatus = { isValid: true }; - } else { - this.licenseStatus = { - isValid: false, - message: message || defaultErrorMessage, - }; - if (message) { - logger.info(message); - } - } - }); - } - - guardApiRoute( - handler: RequestHandler - ) { - const license = this; - - return function licenseCheck( - ctx: Context, - request: KibanaRequest, - response: KibanaResponseFactory - ) { - const licenseStatus = license.getStatus(); - - if (!licenseStatus.isValid) { - return response.customError({ - body: { - message: licenseStatus.message || '', - }, - statusCode: 403, - }); - } - - return handler(ctx, request, response); - }; - } - - getStatus() { - return this.licenseStatus; - } -} diff --git a/x-pack/plugins/index_management/server/types.ts b/x-pack/plugins/index_management/server/types.ts index 0854733d5db59..c980279d5bf30 100644 --- a/x-pack/plugins/index_management/server/types.ts +++ b/x-pack/plugins/index_management/server/types.ts @@ -14,7 +14,7 @@ import type { import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server'; import { LicensingPluginSetup } from '../../licensing/server'; import { SecurityPluginSetup } from '../../security/server'; -import { License, IndexDataEnricher } from './services'; +import { IndexDataEnricher } from './services'; import { isEsError, parseEsError, handleEsError } from './shared_imports'; export interface Dependencies { @@ -25,7 +25,6 @@ export interface Dependencies { export interface RouteDependencies { router: IndexManagementRouter; - license: License; config: { isSecurityEnabled: () => boolean; };