Skip to content

Commit

Permalink
Remove license check from Index Management.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed May 16, 2021
1 parent ea8c92b commit 84eaf1e
Show file tree
Hide file tree
Showing 33 changed files with 128 additions and 270 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
25 changes: 2 additions & 23 deletions x-pack/plugins/index_management/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import {
CoreSetup,
Plugin,
Logger,
PluginInitializerContext,
ILegacyCustomClusterClient,
} from 'src/core/server';

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';
Expand All @@ -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: {
Expand Down Expand Up @@ -97,7 +77,6 @@ export class IndexMgmtServerPlugin implements Plugin<IndexManagementPluginSetup,

this.apiRoutes.setup({
router,
license: this.license,
config: {
isSecurityEnabled: () => security !== undefined && security.license.isEnabled(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ 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'),
validate: {
body: componentTemplateSchema,
},
},
license.guardApiRoute(async (ctx, req, res) => {
async (ctx, req, res) => {
const { callAsCurrentUser } = ctx.dataManagement!.client;

const serializedComponentTemplate = serializeComponentTemplate(req.body);
Expand Down Expand Up @@ -73,6 +69,6 @@ export const registerCreateRoute = ({

throw error;
}
})
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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}'),
validate: {
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(',');
Expand All @@ -48,6 +48,6 @@ export const registerDeleteRoute = ({ router, license }: RouteDependencies): voi
);

return res.ok({ body: response });
})
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -56,7 +56,7 @@ export function registerGetAllRoute({ router, license, lib: { isEsError } }: Rou

throw error;
}
})
}
);

// Get single component template
Expand All @@ -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;

Expand Down Expand Up @@ -96,6 +96,6 @@ export function registerGetAllRoute({ router, license, lib: { isEsError } }: Rou

throw error;
}
})
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -47,9 +46,6 @@ describe('GET privileges', () => {

registerPrivilegesRoute({
router,
license: {
guardApiRoute: (route: any) => route,
} as License,
config: {
isSecurityEnabled: () => true,
},
Expand Down Expand Up @@ -118,9 +114,6 @@ describe('GET privileges', () => {

registerPrivilegesRoute({
router,
license: {
guardApiRoute: (route: any) => route,
} as License,
config: {
isSecurityEnabled: () => false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -66,6 +66,6 @@ export const registerPrivilegesRoute = ({ license, router, config }: RouteDepend
} catch (e) {
throw e;
}
})
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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}'),
Expand All @@ -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;
Expand Down Expand Up @@ -57,6 +53,6 @@ export const registerUpdateRoute = ({

throw error;
}
})
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

Expand All @@ -48,6 +48,6 @@ export function registerDeleteRoute({ router, license }: RouteDependencies) {
);

return res.ok({ body: response });
})
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(),
});
Expand All @@ -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 {
Expand Down Expand Up @@ -207,6 +197,6 @@ export function registerGetOneRoute({
} catch (error) {
return handleEsError({ error, response });
}
})
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,6 +40,6 @@ export function registerClearCacheRoute({ router, license, lib }: RouteDependenc
// Case: default
throw e;
}
})
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,6 +40,6 @@ export function registerCloseRoute({ router, license, lib }: RouteDependencies)
// Case: default
throw e;
}
})
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,6 +40,6 @@ export function registerDeleteRoute({ router, license, lib }: RouteDependencies)
// Case: default
throw e;
}
})
}
);
}
Loading

0 comments on commit 84eaf1e

Please sign in to comment.