Remove license check from Index Management (#100188)
This commit is contained in:
parent
67b8a43684
commit
1c5b302fea
|
@ -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": [
|
||||
|
|
|
@ -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<IndexManagementPluginSetup, void, any, any> {
|
||||
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<IndexManagementRequestHandlerContext>();
|
||||
|
||||
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<IndexManagementPluginSetup,
|
|||
|
||||
this.apiRoutes.setup({
|
||||
router,
|
||||
license: this.license,
|
||||
config: {
|
||||
isSecurityEnabled: () => security !== undefined && security.license.isEnabled(),
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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 });
|
||||
})
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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<typeof bodySchema>;
|
||||
|
||||
|
@ -48,6 +48,6 @@ export function registerDeleteRoute({ router, license }: RouteDependencies) {
|
|||
);
|
||||
|
||||
return res.ok({ body: response });
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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<typeof querySchema>).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<typeof paramsSchema>;
|
||||
const { asCurrentUser } = ctx.core.elasticsearch.client;
|
||||
try {
|
||||
|
@ -207,6 +197,6 @@ export function registerGetOneRoute({
|
|||
} catch (error) {
|
||||
return handleEsError({ error, response });
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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<typeof bodySchema>;
|
||||
const response: { templatesDeleted: Array<TemplateDeserialized['name']>; errors: any[] } = {
|
||||
|
@ -60,6 +60,6 @@ export function registerDeleteRoute({ router, license }: RouteDependencies) {
|
|||
);
|
||||
|
||||
return res.ok({ body: response });
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
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 legacyTemplatesEs = await callAsCurrentUser('indices.getTemplate');
|
||||
const { index_templates: templatesEs } = await callAsCurrentUser(
|
||||
'dataManagement.getComposableIndexTemplates'
|
||||
);
|
||||
|
||||
const legacyTemplates = deserializeLegacyTemplateList(
|
||||
legacyTemplatesEs,
|
||||
cloudManagedTemplatePrefix
|
||||
);
|
||||
const templates = deserializeTemplateList(templatesEs, cloudManagedTemplatePrefix);
|
||||
const legacyTemplates = deserializeLegacyTemplateList(
|
||||
legacyTemplatesEs,
|
||||
cloudManagedTemplatePrefix
|
||||
);
|
||||
const templates = deserializeTemplateList(templatesEs, cloudManagedTemplatePrefix);
|
||||
|
||||
const body = {
|
||||
templates,
|
||||
legacyTemplates,
|
||||
};
|
||||
const body = {
|
||||
templates,
|
||||
legacyTemplates,
|
||||
};
|
||||
|
||||
return res.ok({ body });
|
||||
})
|
||||
);
|
||||
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<typeof paramsSchema>;
|
||||
const { callAsCurrentUser } = ctx.dataManagement!.client;
|
||||
|
||||
|
@ -106,6 +103,6 @@ export function registerGetOneRoute({ router, license, lib }: RouteDependencies)
|
|||
// Case: default
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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<typeof bodySchema>;
|
||||
|
||||
|
@ -42,6 +42,6 @@ export function registerSimulateRoute({ router, license, lib }: RouteDependencie
|
|||
// Case: default
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,4 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
export { License } from './license';
|
||||
|
||||
export { IndexDataEnricher, Enricher } from './index_data_enricher';
|
||||
|
|
|
@ -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<P, Q, B, Context extends IndexManagementRequestHandlerContext>(
|
||||
handler: RequestHandler<P, Q, B, Context>
|
||||
) {
|
||||
const license = this;
|
||||
|
||||
return function licenseCheck(
|
||||
ctx: Context,
|
||||
request: KibanaRequest<P, Q, B>,
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -9987,7 +9987,6 @@
|
|||
"xpack.idxMgmt.indexTemplatesList.viewCloudManagedTemplateLabel": "クラウド管理されたテンプレート",
|
||||
"xpack.idxMgmt.indexTemplatesList.viewManagedTemplateLabel": "管理されたテンプレート",
|
||||
"xpack.idxMgmt.indexTemplatesList.viewSystemTemplateLabel": "システムテンプレート",
|
||||
"xpack.idxMgmt.licenseCheckErrorMessage": "ライセンス確認失敗",
|
||||
"xpack.idxMgmt.mappingsEditor.addFieldButtonLabel": "フィールドの追加",
|
||||
"xpack.idxMgmt.mappingsEditor.addMultiFieldTooltipLabel": "同じフィールドを異なる方法でインデックスするために、マルチフィールドを追加します。",
|
||||
"xpack.idxMgmt.mappingsEditor.addPropertyButtonLabel": "プロパティを追加",
|
||||
|
|
|
@ -10116,7 +10116,6 @@
|
|||
"xpack.idxMgmt.indexTemplatesList.viewCloudManagedTemplateLabel": "云托管模板",
|
||||
"xpack.idxMgmt.indexTemplatesList.viewManagedTemplateLabel": "托管模板",
|
||||
"xpack.idxMgmt.indexTemplatesList.viewSystemTemplateLabel": "系统模板",
|
||||
"xpack.idxMgmt.licenseCheckErrorMessage": "许可证检查失败",
|
||||
"xpack.idxMgmt.mappingsEditor.addFieldButtonLabel": "添加字段",
|
||||
"xpack.idxMgmt.mappingsEditor.addMultiFieldTooltipLabel": "添加多字段以使用不同的方式索引相同的字段。",
|
||||
"xpack.idxMgmt.mappingsEditor.addPropertyButtonLabel": "添加属性",
|
||||
|
|
Loading…
Reference in a new issue