mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Logstash Plugin] Migrate authc.getCurrentUser usage to coreContext.security (#187180)
Part of https://github.com/elastic/kibana/issues/186574 ## Summary This PR migrates the Logstash Plugin's route handler for saving a pipeline, which consumes `authc.getCurrentUser`, to use `coreContext.security`. Background: This PR serves as an example of a plugin migrating away from depending on the Security plugin, which is a high priority effort for the last release before 9.0. ### Checklist Delete any items that are not applicable to this PR. - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
0a0bb1498e
commit
482f2a9503
4 changed files with 8 additions and 18 deletions
|
@ -8,12 +8,10 @@
|
|||
import { CoreSetup, CoreStart, Logger, Plugin, PluginInitializerContext } from '@kbn/core/server';
|
||||
import { LicensingPluginSetup } from '@kbn/licensing-plugin/server';
|
||||
import { PluginSetupContract as FeaturesPluginSetup } from '@kbn/features-plugin/server';
|
||||
import { SecurityPluginSetup } from '@kbn/security-plugin/server';
|
||||
import { registerRoutes } from './routes';
|
||||
|
||||
interface SetupDeps {
|
||||
licensing: LicensingPluginSetup;
|
||||
security?: SecurityPluginSetup;
|
||||
features: FeaturesPluginSetup;
|
||||
}
|
||||
|
||||
|
@ -27,7 +25,7 @@ export class LogstashPlugin implements Plugin {
|
|||
setup(core: CoreSetup, deps: SetupDeps) {
|
||||
this.logger.debug('Setting up Logstash plugin');
|
||||
|
||||
registerRoutes(core.http.createRouter(), deps.security);
|
||||
registerRoutes(core.http.createRouter());
|
||||
|
||||
deps.features.registerElasticsearchFeature({
|
||||
id: 'pipelines',
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { SecurityPluginSetup } from '@kbn/security-plugin/server';
|
||||
import type { LogstashPluginRouter } from '../types';
|
||||
import { registerClusterLoadRoute } from './cluster';
|
||||
import {
|
||||
|
@ -15,12 +14,12 @@ import {
|
|||
} from './pipeline';
|
||||
import { registerPipelinesListRoute, registerPipelinesDeleteRoute } from './pipelines';
|
||||
|
||||
export function registerRoutes(router: LogstashPluginRouter, security?: SecurityPluginSetup) {
|
||||
export function registerRoutes(router: LogstashPluginRouter) {
|
||||
registerClusterLoadRoute(router);
|
||||
|
||||
registerPipelineDeleteRoute(router);
|
||||
registerPipelineLoadRoute(router);
|
||||
registerPipelineSaveRoute(router, security);
|
||||
registerPipelineSaveRoute(router);
|
||||
|
||||
registerPipelinesListRoute(router);
|
||||
registerPipelinesDeleteRoute(router);
|
||||
|
|
|
@ -9,15 +9,11 @@ import { schema } from '@kbn/config-schema';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { wrapRouteWithLicenseCheck } from '@kbn/licensing-plugin/server';
|
||||
import { SecurityPluginSetup } from '@kbn/security-plugin/server';
|
||||
import { Pipeline } from '../../models/pipeline';
|
||||
import { checkLicense } from '../../lib/check_license';
|
||||
import type { LogstashPluginRouter } from '../../types';
|
||||
|
||||
export function registerPipelineSaveRoute(
|
||||
router: LogstashPluginRouter,
|
||||
security?: SecurityPluginSetup
|
||||
) {
|
||||
export function registerPipelineSaveRoute(router: LogstashPluginRouter) {
|
||||
router.put(
|
||||
{
|
||||
path: '/api/logstash/pipeline/{id}',
|
||||
|
@ -39,14 +35,12 @@ export function registerPipelineSaveRoute(
|
|||
wrapRouteWithLicenseCheck(
|
||||
checkLicense,
|
||||
router.handleLegacyErrors(async (context, request, response) => {
|
||||
const coreContext = await context.core;
|
||||
try {
|
||||
let username: string | undefined;
|
||||
if (security) {
|
||||
const user = await security.authc.getCurrentUser(request);
|
||||
username = user?.username;
|
||||
}
|
||||
const user = coreContext.security.authc.getCurrentUser();
|
||||
const username = user?.username;
|
||||
|
||||
const { client } = (await context.core).elasticsearch;
|
||||
const { client } = coreContext.elasticsearch;
|
||||
const pipeline = Pipeline.fromDownstreamJSON(request.body, request.params.id, username);
|
||||
|
||||
await client.asCurrentUser.logstash.putPipeline({
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
"@kbn/features-plugin",
|
||||
"@kbn/licensing-plugin",
|
||||
"@kbn/security-plugin",
|
||||
"@kbn/i18n",
|
||||
"@kbn/i18n-react",
|
||||
"@kbn/test-jest-helpers",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue