From 23bb1aa7002b5f0bc23fefcc9f8a6018d509fbdf Mon Sep 17 00:00:00 2001 From: Frank Hassanabad Date: Wed, 6 May 2020 14:56:09 -0600 Subject: [PATCH] [SIEM][Lists] Fixes up contracts to work outside of requests ## Summary Fixes up the API contracts to work outside of a request and as a regular plugin. * Removes space and request stuff that is not needed * Adds in plugin ability with space id and user name being pushed down --- x-pack/plugins/lists/server/plugin.ts | 28 +++++++++++++++---- .../server/services/lists/client_types.ts | 5 +--- x-pack/plugins/lists/server/types.ts | 13 +++++++-- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/lists/server/plugin.ts b/x-pack/plugins/lists/server/plugin.ts index 2498c36967a5..5facf981c098 100644 --- a/x-pack/plugins/lists/server/plugin.ts +++ b/x-pack/plugins/lists/server/plugin.ts @@ -5,7 +5,7 @@ */ import { first } from 'rxjs/operators'; -import { Logger, PluginInitializerContext } from 'kibana/server'; +import { Logger, Plugin, PluginInitializerContext } from 'kibana/server'; import { CoreSetup } from 'src/core/server'; import { SecurityPluginSetup } from '../../security/server'; @@ -14,12 +14,19 @@ import { SpacesServiceSetup } from '../../spaces/server'; import { ConfigType } from './config'; import { initRoutes } from './routes/init_routes'; import { ListClient } from './services/lists/client'; -import { ContextProvider, ContextProviderReturn, PluginsSetup } from './types'; +import { + ContextProvider, + ContextProviderReturn, + ListPluginSetup, + ListsPluginStart, + PluginsSetup, +} from './types'; import { createConfig$ } from './create_config'; import { getSpaceId } from './get_space_id'; import { getUser } from './get_user'; -export class ListPlugin { +export class ListPlugin + implements Plugin, ListsPluginStart, PluginsSetup> { private readonly logger: Logger; private spaces: SpacesServiceSetup | undefined | null; private config: ConfigType | undefined | null; @@ -29,7 +36,7 @@ export class ListPlugin { this.logger = this.initializerContext.logger.get(); } - public async setup(core: CoreSetup, plugins: PluginsSetup): Promise { + public async setup(core: CoreSetup, plugins: PluginsSetup): Promise { const config = await createConfig$(this.initializerContext) .pipe(first()) .toPromise(); @@ -44,6 +51,17 @@ export class ListPlugin { core.http.registerRouteHandlerContext('lists', this.createRouteHandlerContext()); const router = core.http.createRouter(); initRoutes(router); + + return { + getListClient: (apiCaller, spaceId, user): ListClient => { + return new ListClient({ + callCluster: apiCaller, + config, + spaceId, + user, + }); + }, + }; } public start(): void { @@ -74,8 +92,6 @@ export class ListPlugin { new ListClient({ callCluster: callAsCurrentUser, config, - request, - security, spaceId, user, }), diff --git a/x-pack/plugins/lists/server/services/lists/client_types.ts b/x-pack/plugins/lists/server/services/lists/client_types.ts index 2cc58c02dbfc..d66575e7a30d 100644 --- a/x-pack/plugins/lists/server/services/lists/client_types.ts +++ b/x-pack/plugins/lists/server/services/lists/client_types.ts @@ -6,9 +6,8 @@ import { PassThrough, Readable } from 'stream'; -import { APICaller, KibanaRequest } from 'kibana/server'; +import { APICaller } from 'kibana/server'; -import { SecurityPluginSetup } from '../../../../security/server'; import { Description, DescriptionOrUndefined, @@ -24,10 +23,8 @@ import { ConfigType } from '../../config'; export interface ConstructorOptions { callCluster: APICaller; config: ConfigType; - request: KibanaRequest; spaceId: string; user: string; - security: SecurityPluginSetup | undefined | null; } export interface GetListOptions { diff --git a/x-pack/plugins/lists/server/types.ts b/x-pack/plugins/lists/server/types.ts index e0e4495d47c3..d7c3208e556f 100644 --- a/x-pack/plugins/lists/server/types.ts +++ b/x-pack/plugins/lists/server/types.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { IContextProvider, RequestHandler } from 'kibana/server'; +import { APICaller, IContextProvider, RequestHandler } from 'kibana/server'; import { SecurityPluginSetup } from '../../security/server'; import { SpacesPluginSetup } from '../../spaces/server'; @@ -12,12 +12,21 @@ import { SpacesPluginSetup } from '../../spaces/server'; import { ListClient } from './services/lists/client'; export type ContextProvider = IContextProvider, 'lists'>; - +export type ListsPluginStart = void; export interface PluginsSetup { security: SecurityPluginSetup | undefined | null; spaces: SpacesPluginSetup | undefined | null; } +export type GetListClientType = ( + dataClient: APICaller, + spaceId: string, + user: string +) => ListClient; +export interface ListPluginSetup { + getListClient: GetListClientType; +} + export type ContextProviderReturn = Promise<{ getListClient: () => ListClient }>; declare module 'src/core/server' { interface RequestHandlerContext {