-
Notifications
You must be signed in to change notification settings - Fork 67
/
ElasticSearch.service.ts
81 lines (75 loc) 路 2.23 KB
/
ElasticSearch.service.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
import {IElasticSearch, SupportedDataStores, TDataStoreService, TRawElasticSearch} from 'types/DataStore.types';
import Validator from 'utils/Validator';
const ElasticSearchService = (): TDataStoreService => ({
async getRequest({dataStore = {}}, dataStoreType = SupportedDataStores.OpenSearch) {
const values = dataStore[dataStoreType || SupportedDataStores.OpenSearch] as IElasticSearch;
const {
certificateFile = new File([''], 'certificate'),
addresses = [],
index = '',
username = '',
password = '',
insecureSkipVerify = false,
} = values;
const certificate = await certificateFile.text();
return Promise.resolve({
name: dataStoreType,
type: dataStoreType,
[dataStoreType]: {
index,
username,
password,
addresses,
certificate,
insecureSkipVerify,
},
});
},
validateDraft({dataStore = {}, dataStoreType}) {
const values = dataStore[dataStoreType || SupportedDataStores.OpenSearch] as IElasticSearch;
const {addresses = [], index = ''} = values;
const [address] = addresses;
if (!index || !Validator.url(address)) return Promise.resolve(false);
return Promise.resolve(true);
},
getInitialValues(
defaultDataStore = {name: '', type: SupportedDataStores.OpenSearch},
dataStoreType = SupportedDataStores.OpenSearch
) {
const {
index = '',
username = '',
password = '',
addresses = [''],
certificate = '',
insecureSkipVerify = false,
} = (defaultDataStore[dataStoreType] as TRawElasticSearch) ?? {};
const draftDataStore: IElasticSearch = {
index,
username,
password,
addresses,
certificateFile: certificate ? new File([certificate], 'certificate') : undefined,
insecureSkipVerify,
};
return {
dataStore: {
[dataStoreType]: draftDataStore,
name: dataStoreType,
type: dataStoreType,
},
dataStoreType,
};
},
getIsOtlpBased() {
return false;
},
getPublicInfo({opensearch = {}}) {
const {addresses = [], index = ''} = opensearch;
return {
Address: addresses.join(', '),
Index: index,
};
},
});
export default ElasticSearchService();