[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:
parent
90de711c27
commit
23bb1aa700
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { first } from 'rxjs/operators';
|
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 { CoreSetup } from 'src/core/server';
|
||||||
|
|
||||||
import { SecurityPluginSetup } from '../../security/server';
|
import { SecurityPluginSetup } from '../../security/server';
|
||||||
|
@ -14,12 +14,19 @@ import { SpacesServiceSetup } from '../../spaces/server';
|
||||||
import { ConfigType } from './config';
|
import { ConfigType } from './config';
|
||||||
import { initRoutes } from './routes/init_routes';
|
import { initRoutes } from './routes/init_routes';
|
||||||
import { ListClient } from './services/lists/client';
|
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 { createConfig$ } from './create_config';
|
||||||
import { getSpaceId } from './get_space_id';
|
import { getSpaceId } from './get_space_id';
|
||||||
import { getUser } from './get_user';
|
import { getUser } from './get_user';
|
||||||
|
|
||||||
export class ListPlugin {
|
export class ListPlugin
|
||||||
|
implements Plugin<Promise<ListPluginSetup>, ListsPluginStart, PluginsSetup> {
|
||||||
private readonly logger: Logger;
|
private readonly logger: Logger;
|
||||||
private spaces: SpacesServiceSetup | undefined | null;
|
private spaces: SpacesServiceSetup | undefined | null;
|
||||||
private config: ConfigType | undefined | null;
|
private config: ConfigType | undefined | null;
|
||||||
|
@ -29,7 +36,7 @@ export class ListPlugin {
|
||||||
this.logger = this.initializerContext.logger.get();
|
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)
|
const config = await createConfig$(this.initializerContext)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
.toPromise();
|
.toPromise();
|
||||||
|
@ -44,6 +51,17 @@ export class ListPlugin {
|
||||||
core.http.registerRouteHandlerContext('lists', this.createRouteHandlerContext());
|
core.http.registerRouteHandlerContext('lists', this.createRouteHandlerContext());
|
||||||
const router = core.http.createRouter();
|
const router = core.http.createRouter();
|
||||||
initRoutes(router);
|
initRoutes(router);
|
||||||
|
|
||||||
|
return {
|
||||||
|
getListClient: (apiCaller, spaceId, user): ListClient => {
|
||||||
|
return new ListClient({
|
||||||
|
callCluster: apiCaller,
|
||||||
|
config,
|
||||||
|
spaceId,
|
||||||
|
user,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public start(): void {
|
public start(): void {
|
||||||
|
@ -74,8 +92,6 @@ export class ListPlugin {
|
||||||
new ListClient({
|
new ListClient({
|
||||||
callCluster: callAsCurrentUser,
|
callCluster: callAsCurrentUser,
|
||||||
config,
|
config,
|
||||||
request,
|
|
||||||
security,
|
|
||||||
spaceId,
|
spaceId,
|
||||||
user,
|
user,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
|
|
||||||
import { PassThrough, Readable } from 'stream';
|
import { PassThrough, Readable } from 'stream';
|
||||||
|
|
||||||
import { APICaller, KibanaRequest } from 'kibana/server';
|
import { APICaller } from 'kibana/server';
|
||||||
|
|
||||||
import { SecurityPluginSetup } from '../../../../security/server';
|
|
||||||
import {
|
import {
|
||||||
Description,
|
Description,
|
||||||
DescriptionOrUndefined,
|
DescriptionOrUndefined,
|
||||||
|
@ -24,10 +23,8 @@ import { ConfigType } from '../../config';
|
||||||
export interface ConstructorOptions {
|
export interface ConstructorOptions {
|
||||||
callCluster: APICaller;
|
callCluster: APICaller;
|
||||||
config: ConfigType;
|
config: ConfigType;
|
||||||
request: KibanaRequest;
|
|
||||||
spaceId: string;
|
spaceId: string;
|
||||||
user: string;
|
user: string;
|
||||||
security: SecurityPluginSetup | undefined | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetListOptions {
|
export interface GetListOptions {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
* 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 { SecurityPluginSetup } from '../../security/server';
|
||||||
import { SpacesPluginSetup } from '../../spaces/server';
|
import { SpacesPluginSetup } from '../../spaces/server';
|
||||||
|
@ -12,12 +12,21 @@ import { SpacesPluginSetup } from '../../spaces/server';
|
||||||
import { ListClient } from './services/lists/client';
|
import { ListClient } from './services/lists/client';
|
||||||
|
|
||||||
export type ContextProvider = IContextProvider<RequestHandler<unknown, unknown, unknown>, 'lists'>;
|
export type ContextProvider = IContextProvider<RequestHandler<unknown, unknown, unknown>, 'lists'>;
|
||||||
|
export type ListsPluginStart = void;
|
||||||
export interface PluginsSetup {
|
export interface PluginsSetup {
|
||||||
security: SecurityPluginSetup | undefined | null;
|
security: SecurityPluginSetup | undefined | null;
|
||||||
spaces: SpacesPluginSetup | 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 }>;
|
export type ContextProviderReturn = Promise<{ getListClient: () => ListClient }>;
|
||||||
declare module 'src/core/server' {
|
declare module 'src/core/server' {
|
||||||
interface RequestHandlerContext {
|
interface RequestHandlerContext {
|
||||||
|
|
Loading…
Reference in a new issue