Skip to content

Commit

Permalink
Remove license check from Ingest Node Pipelines UI (elastic#100189)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed May 29, 2021
1 parent 22b7991 commit cc16331
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 173 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_pipelines/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": ["licensing", "management", "features", "share"],
"requiredPlugins": ["management", "features", "share"],
"optionalPlugins": ["security", "usageCollection"],
"configPath": ["xpack", "ingest_pipelines"],
"requiredBundles": ["esUiShared", "kibanaReact"]
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/ingest_pipelines/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* 2.0.
*/

import { PluginInitializerContext } from '../../../../src/core/server';
import { IngestPipelinesPlugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
return new IngestPipelinesPlugin(initializerContext);
export function plugin() {
return new IngestPipelinesPlugin();
}
32 changes: 3 additions & 29 deletions x-pack/plugins/ingest_pipelines/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,22 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import { CoreSetup, Plugin } from 'kibana/server';

import { PluginInitializerContext, CoreSetup, Plugin, Logger } from 'kibana/server';

import { PLUGIN_ID, PLUGIN_MIN_LICENSE_TYPE } from '../common/constants';

import { License } from './services';
import { ApiRoutes } from './routes';
import { handleEsError } from './shared_imports';
import { Dependencies } from './types';

export class IngestPipelinesPlugin implements Plugin<void, void, any, any> {
private readonly logger: Logger;
private readonly license: License;
private readonly apiRoutes: ApiRoutes;

constructor({ logger }: PluginInitializerContext) {
this.logger = logger.get();
this.license = new License();
constructor() {
this.apiRoutes = new ApiRoutes();
}

public setup({ http }: CoreSetup, { licensing, security, features }: Dependencies) {
this.logger.debug('ingest_pipelines: setup');

public setup({ http }: CoreSetup, { security, features }: Dependencies) {
const router = http.createRouter();

this.license.setup(
{
pluginId: PLUGIN_ID,
minimumLicenseType: PLUGIN_MIN_LICENSE_TYPE,
defaultErrorMessage: i18n.translate('xpack.ingestPipelines.licenseCheckErrorMessage', {
defaultMessage: 'License check failed',
}),
},
{
licensing,
logger: this.logger,
}
);

features.registerElasticsearchFeature({
id: 'ingest_pipelines',
management: {
Expand All @@ -61,7 +36,6 @@ export class IngestPipelinesPlugin implements Plugin<void, void, any, any> {

this.apiRoutes.setup({
router,
license: this.license,
config: {
isSecurityEnabled: () => security !== undefined && security.license.isEnabled(),
},
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/ingest_pipelines/server/routes/api/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const bodySchema = schema.object({

export const registerCreateRoute = ({
router,
license,
lib: { handleEsError },
}: RouteDependencies): void => {
router.post(
Expand All @@ -30,7 +29,7 @@ export const registerCreateRoute = ({
body: bodySchema,
},
},
license.guardApiRoute(async (ctx, req, res) => {
async (ctx, req, res) => {
const { client: clusterClient } = ctx.core.elasticsearch;
const pipeline = req.body as Pipeline;

Expand Down Expand Up @@ -74,6 +73,6 @@ export const registerCreateRoute = ({
} catch (error) {
return handleEsError({ error, response: res });
}
})
}
);
};
6 changes: 3 additions & 3 deletions x-pack/plugins/ingest_pipelines/server/routes/api/delete.ts
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: `${API_BASE_PATH}/{names}`,
validate: {
params: paramsSchema,
},
},
license.guardApiRoute(async (ctx, req, res) => {
async (ctx, req, res) => {
const { client: clusterClient } = ctx.core.elasticsearch;
const { names } = req.params;
const pipelineNames = 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 @@ -17,7 +17,6 @@ const paramsSchema = schema.object({

export const registerDocumentsRoute = ({
router,
license,
lib: { handleEsError },
}: RouteDependencies): void => {
router.get(
Expand All @@ -27,7 +26,7 @@ export const registerDocumentsRoute = ({
params: paramsSchema,
},
},
license.guardApiRoute(async (ctx, req, res) => {
async (ctx, req, res) => {
const { client: clusterClient } = ctx.core.elasticsearch;
const { index, id } = req.params;

Expand All @@ -46,6 +45,6 @@ export const registerDocumentsRoute = ({
} catch (error) {
return handleEsError({ error, response: res });
}
})
}
);
};
41 changes: 17 additions & 24 deletions x-pack/plugins/ingest_pipelines/server/routes/api/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,25 @@ const paramsSchema = schema.object({
name: schema.string(),
});

export const registerGetRoutes = ({
router,
license,
lib: { handleEsError },
}: RouteDependencies): void => {
export const registerGetRoutes = ({ router, lib: { handleEsError } }: RouteDependencies): void => {
// Get all pipelines
router.get(
{ path: API_BASE_PATH, validate: false },
license.guardApiRoute(async (ctx, req, res) => {
const { client: clusterClient } = ctx.core.elasticsearch;
router.get({ path: API_BASE_PATH, validate: false }, async (ctx, req, res) => {
const { client: clusterClient } = ctx.core.elasticsearch;

try {
const { body: pipelines } = await clusterClient.asCurrentUser.ingest.getPipeline();
try {
const { body: pipelines } = await clusterClient.asCurrentUser.ingest.getPipeline();

return res.ok({ body: deserializePipelines(pipelines) });
} catch (error) {
const esErrorResponse = handleEsError({ error, response: res });
if (esErrorResponse.status === 404) {
// ES returns 404 when there are no pipelines
// Instead, we return an empty array and 200 status back to the client
return res.ok({ body: [] });
}
return esErrorResponse;
return res.ok({ body: deserializePipelines(pipelines) });
} catch (error) {
const esErrorResponse = handleEsError({ error, response: res });
if (esErrorResponse.status === 404) {
// ES returns 404 when there are no pipelines
// Instead, we return an empty array and 200 status back to the client
return res.ok({ body: [] });
}
})
);
return esErrorResponse;
}
});

// Get single pipeline
router.get(
Expand All @@ -50,7 +43,7 @@ export const registerGetRoutes = ({
params: paramsSchema,
},
},
license.guardApiRoute(async (ctx, req, res) => {
async (ctx, req, res) => {
const { client: clusterClient } = ctx.core.elasticsearch;
const { name } = req.params;

Expand All @@ -68,6 +61,6 @@ export const registerGetRoutes = ({
} catch (error) {
return handleEsError({ error, response: res });
}
})
}
);
};
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: `${API_BASE_PATH}/privileges`,
validate: false,
},
license.guardApiRoute(async (ctx, req, res) => {
async (ctx, req, res) => {
const privilegesResult: Privileges = {
hasAllPrivileges: true,
missingPrivileges: {
Expand Down Expand Up @@ -51,6 +51,6 @@ export const registerPrivilegesRoute = ({ license, router, config }: RouteDepend
privilegesResult.hasAllPrivileges = hasAllPrivileges;

return res.ok({ body: privilegesResult });
})
}
);
};
5 changes: 2 additions & 3 deletions x-pack/plugins/ingest_pipelines/server/routes/api/simulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const bodySchema = schema.object({

export const registerSimulateRoute = ({
router,
license,
lib: { handleEsError },
}: RouteDependencies): void => {
router.post(
Expand All @@ -29,7 +28,7 @@ export const registerSimulateRoute = ({
body: bodySchema,
},
},
license.guardApiRoute(async (ctx, req, res) => {
async (ctx, req, res) => {
const { client: clusterClient } = ctx.core.elasticsearch;

const { pipeline, documents, verbose } = req.body;
Expand All @@ -47,6 +46,6 @@ export const registerSimulateRoute = ({
} catch (error) {
return handleEsError({ error, response: res });
}
})
}
);
};
5 changes: 2 additions & 3 deletions x-pack/plugins/ingest_pipelines/server/routes/api/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const paramsSchema = schema.object({

export const registerUpdateRoute = ({
router,
license,
lib: { handleEsError },
}: RouteDependencies): void => {
router.put(
Expand All @@ -30,7 +29,7 @@ export const registerUpdateRoute = ({
params: paramsSchema,
},
},
license.guardApiRoute(async (ctx, req, res) => {
async (ctx, req, res) => {
const { client: clusterClient } = ctx.core.elasticsearch;
const { name } = req.params;
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -54,6 +53,6 @@ export const registerUpdateRoute = ({
} catch (error) {
return handleEsError({ error, response: res });
}
})
}
);
};
8 changes: 0 additions & 8 deletions x-pack/plugins/ingest_pipelines/server/services/index.ts

This file was deleted.

84 changes: 0 additions & 84 deletions x-pack/plugins/ingest_pipelines/server/services/license.ts

This file was deleted.

Loading

0 comments on commit cc16331

Please sign in to comment.