forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.ts
76 lines (58 loc) · 2.19 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
import {
PluginInitializerContext,
CoreSetup,
CoreStart,
Plugin,
Logger,
} from '../../../src/core/server';
import { AppPluginSetupDependencies, CspStorageProviderPluginSetup, CspStorageProviderPluginStart } from './types';
import { defineRoutes } from './routes';
import { CspClient } from 'src/plugins/xframe_options/server/types';
export class MyClient implements CspClient {
async exists(indexName: string): Promise<boolean> {
console.log(`*** MyClient receive exists call ${indexName}`);
// throw new Error('Method not implemented.');
return false;
}
async update(indexName: string, docName: string, body: {}): Promise<string> {
console.log(`*** MyClient receive update request ${indexName}, ${docName}, ${body}`);
return "sucess";
// throw new Error('Method not implemented.');
}
async search(indexName: string, docName: string): Promise<string> {
console.log(`*** MyClient receive update request ${indexName}, ${docName}`);
// throw new Error('Method not implemented.');
return "frame-ancestors 'self' file://* filesystem:";
}
}
export class CspStorageProviderPlugin
implements Plugin<CspStorageProviderPluginSetup, CspStorageProviderPluginStart> {
private readonly logger: Logger;
constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
}
private createClient(): CspClient {
return new MyClient();
}
public setup(core: CoreSetup, { xframeOptions }: AppPluginSetupDependencies) {
this.logger.debug('CspStorageProvider: Setup');
this.logger.info('CspStorageProvider: Setup');
const router = core.http.createRouter();
// console.log("*** xframeOptions" + xframeOptions);
const customClient = this.createClient();
if (customClient) {
this.logger.info('CspStorageProvider: Setup customClient is valid');
} else {
this.logger.info('CspStorageProvider: Setup customClient is invalid');
}
// xframeOptions.setCspClient(customClient);
// Register server side APIs
defineRoutes(router);
return {};
}
public start(core: CoreStart) {
this.logger.debug('CspStorageProvider: Started');
return {};
}
public stop() { }
}