-
Notifications
You must be signed in to change notification settings - Fork 173
/
get-config.js
43 lines (36 loc) · 1.39 KB
/
get-config.js
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
/*
* Wazuh app - Resolve function to parse configuration file
* Copyright (C) 2015-2022 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import { WAZUH_DEFAULT_APP_CONFIG } from '../../../common/constants';
export async function getWzConfig($q, genericReq, wazuhConfig) {
const defaultConfig = { ...WAZUH_DEFAULT_APP_CONFIG };
try {
const config = await genericReq.request('GET', '/utils/configuration', {});
if (!config || !config.data || !config.data.data)
throw new Error('No config available');
const ymlContent = config.data.data;
if (
typeof ymlContent === 'object' &&
(Object.keys(ymlContent) || []).length
) {
// Replace default values with custom values from wazuh.yml file
for (const key in ymlContent) {
defaultConfig[key] = ymlContent[key];
}
}
wazuhConfig.setConfig(defaultConfig);
} catch (error) {
wazuhConfig.setConfig(defaultConfig);
console.log('Error parsing wazuh.yml, using default values.'); // eslint-disable-line
console.log(error.message || error); // eslint-disable-line
}
return $q.resolve(defaultConfig);
}