[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
This commit is contained in:
Frank Hassanabad 2020-05-06 14:56:09 -06:00 committed by GitHub
parent 90de711c27
commit 23bb1aa700
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 12 deletions

View file

@ -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<Promise<ListPluginSetup>, 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<void> {
public async setup(core: CoreSetup, plugins: PluginsSetup): Promise<ListPluginSetup> {
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,
}),

View file

@ -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 {

View file

@ -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<RequestHandler<unknown, unknown, unknown>, '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 {