Skip to content

Commit 23bb1aa

Browse files
[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
1 parent 90de711 commit 23bb1aa

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

x-pack/plugins/lists/server/plugin.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { first } from 'rxjs/operators';
8-
import { Logger, PluginInitializerContext } from 'kibana/server';
8+
import { Logger, Plugin, PluginInitializerContext } from 'kibana/server';
99
import { CoreSetup } from 'src/core/server';
1010

1111
import { SecurityPluginSetup } from '../../security/server';
@@ -14,12 +14,19 @@ import { SpacesServiceSetup } from '../../spaces/server';
1414
import { ConfigType } from './config';
1515
import { initRoutes } from './routes/init_routes';
1616
import { ListClient } from './services/lists/client';
17-
import { ContextProvider, ContextProviderReturn, PluginsSetup } from './types';
17+
import {
18+
ContextProvider,
19+
ContextProviderReturn,
20+
ListPluginSetup,
21+
ListsPluginStart,
22+
PluginsSetup,
23+
} from './types';
1824
import { createConfig$ } from './create_config';
1925
import { getSpaceId } from './get_space_id';
2026
import { getUser } from './get_user';
2127

22-
export class ListPlugin {
28+
export class ListPlugin
29+
implements Plugin<Promise<ListPluginSetup>, ListsPluginStart, PluginsSetup> {
2330
private readonly logger: Logger;
2431
private spaces: SpacesServiceSetup | undefined | null;
2532
private config: ConfigType | undefined | null;
@@ -29,7 +36,7 @@ export class ListPlugin {
2936
this.logger = this.initializerContext.logger.get();
3037
}
3138

32-
public async setup(core: CoreSetup, plugins: PluginsSetup): Promise<void> {
39+
public async setup(core: CoreSetup, plugins: PluginsSetup): Promise<ListPluginSetup> {
3340
const config = await createConfig$(this.initializerContext)
3441
.pipe(first())
3542
.toPromise();
@@ -44,6 +51,17 @@ export class ListPlugin {
4451
core.http.registerRouteHandlerContext('lists', this.createRouteHandlerContext());
4552
const router = core.http.createRouter();
4653
initRoutes(router);
54+
55+
return {
56+
getListClient: (apiCaller, spaceId, user): ListClient => {
57+
return new ListClient({
58+
callCluster: apiCaller,
59+
config,
60+
spaceId,
61+
user,
62+
});
63+
},
64+
};
4765
}
4866

4967
public start(): void {
@@ -74,8 +92,6 @@ export class ListPlugin {
7492
new ListClient({
7593
callCluster: callAsCurrentUser,
7694
config,
77-
request,
78-
security,
7995
spaceId,
8096
user,
8197
}),

x-pack/plugins/lists/server/services/lists/client_types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
import { PassThrough, Readable } from 'stream';
88

9-
import { APICaller, KibanaRequest } from 'kibana/server';
9+
import { APICaller } from 'kibana/server';
1010

11-
import { SecurityPluginSetup } from '../../../../security/server';
1211
import {
1312
Description,
1413
DescriptionOrUndefined,
@@ -24,10 +23,8 @@ import { ConfigType } from '../../config';
2423
export interface ConstructorOptions {
2524
callCluster: APICaller;
2625
config: ConfigType;
27-
request: KibanaRequest;
2826
spaceId: string;
2927
user: string;
30-
security: SecurityPluginSetup | undefined | null;
3128
}
3229

3330
export interface GetListOptions {

x-pack/plugins/lists/server/types.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,29 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { IContextProvider, RequestHandler } from 'kibana/server';
7+
import { APICaller, IContextProvider, RequestHandler } from 'kibana/server';
88

99
import { SecurityPluginSetup } from '../../security/server';
1010
import { SpacesPluginSetup } from '../../spaces/server';
1111

1212
import { ListClient } from './services/lists/client';
1313

1414
export type ContextProvider = IContextProvider<RequestHandler<unknown, unknown, unknown>, 'lists'>;
15-
15+
export type ListsPluginStart = void;
1616
export interface PluginsSetup {
1717
security: SecurityPluginSetup | undefined | null;
1818
spaces: SpacesPluginSetup | undefined | null;
1919
}
2020

21+
export type GetListClientType = (
22+
dataClient: APICaller,
23+
spaceId: string,
24+
user: string
25+
) => ListClient;
26+
export interface ListPluginSetup {
27+
getListClient: GetListClientType;
28+
}
29+
2130
export type ContextProviderReturn = Promise<{ getListClient: () => ListClient }>;
2231
declare module 'src/core/server' {
2332
interface RequestHandlerContext {

0 commit comments

Comments
 (0)