forked from opensearch-project/dashboards-reporting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.ts
112 lines (98 loc) · 2.97 KB
/
plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import {
PluginInitializerContext,
CoreSetup,
CoreStart,
Plugin,
Logger,
ILegacyClusterClient,
} from '../../../src/core/server';
import opensearchReportsPlugin from './backend/opensearch-reports-plugin';
import {
ReportsDashboardsPluginSetup,
ReportsDashboardsPluginStart,
} from './types';
import registerRoutes from './routes';
import { NotificationsPlugin } from './clusters/notificationsPlugin';
import { buildConfig, ReportingConfigType } from './config';
import { ReportingConfig } from './config/config';
export interface ReportsPluginRequestContext {
logger: Logger;
opensearchClient: ILegacyClusterClient;
}
//@ts-ignore
declare module 'kibana/server' {
interface RequestHandlerContext {
reports_plugin: ReportsPluginRequestContext;
}
}
export class ReportsDashboardsPlugin
implements
Plugin<ReportsDashboardsPluginSetup, ReportsDashboardsPluginStart> {
private readonly logger: Logger;
private readonly initializerContext: PluginInitializerContext<
ReportingConfigType
>;
private reportingConfig?: ReportingConfig;
constructor(context: PluginInitializerContext<ReportingConfigType>) {
this.logger = context.logger.get();
this.initializerContext = context;
}
public async setup(core: CoreSetup) {
this.logger.debug('reports-dashboards: Setup');
try {
const config = await buildConfig(
this.initializerContext,
core,
this.logger
);
this.reportingConfig = config;
this.logger.debug('Setup complete');
} catch (error) {
this.logger.error(
`Error in Reporting setup, reporting may not function properly`
);
this.logger.error(error);
}
if (!this.reportingConfig) {
throw new Error('Reporting Config is not initialized');
}
const router = core.http.createRouter();
// Deprecated API. Switch to the new opensearch client as soon as https://github.com/elastic/kibana/issues/35508 done.
const opensearchReportsClient: ILegacyClusterClient = core.opensearch.legacy.createClient(
'opensearch_reports',
{
plugins: [opensearchReportsPlugin, NotificationsPlugin],
}
);
const notificationsClient: ILegacyClusterClient = core.opensearch.legacy.createClient(
'opensearch_notifications',
{
plugins: [NotificationsPlugin],
}
);
// Register server side APIs
registerRoutes(router, this.reportingConfig);
// put logger into route handler context, so that we don't need to pass through parameters
core.http.registerRouteHandlerContext(
//@ts-ignore
'reporting_plugin',
(context, request) => {
return {
logger: this.logger,
opensearchReportsClient,
notificationsClient,
};
}
);
return {};
}
public start(core: CoreStart) {
this.logger.debug('reports-dashboards: Started');
return {};
}
public stop() {}
}