Skip to content

Commit

Permalink
fix: request changes and rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
Desvelao committed Nov 2, 2022
1 parent e36d4df commit 7ad0476
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions common/services/settings.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
formatLabelValuePair,
formatSettingValueToFile,
getSettingDependOnCustomizationIsEnabled
getCustomizationSetting
} from "./settings";

describe('[settings] Methods', () => {
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('[settings] Methods', () => {
});
});

describe('getSettingDependOnCustomizationIsEnabled: Get the value for the "customization." settings depending on the "customization.enabled" setting', () => {
describe('getCustomizationSetting: Get the value for the "customization." settings depending on the "customization.enabled" setting', () => {
it.only.each`
customizationEnabled | settingKey | configValue | expected
${true} | ${'customization.logo.app'} | ${'custom-image-app.png'} | ${'custom-image-app.png'}
Expand All @@ -54,7 +54,7 @@ describe('[settings] Methods', () => {
'customization.enabled': customizationEnabled,
[settingKey]: configValue
};
expect(getSettingDependOnCustomizationIsEnabled(configuration, settingKey)).toBe(expected);
expect(getCustomizationSetting(configuration, settingKey)).toBe(expected);
});
});
});
19 changes: 10 additions & 9 deletions common/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,21 @@ export function formatLabelValuePair(label, value){

/**
* Get the configuration value if the customization is enabled.
* @param options
* @returns
* @param configuration JSON object from `wazuh.yml`
* @param settingKey key of the setting
* @returns
*/
export function getSettingDependOnCustomizationIsEnabled(configuration: any, settingKey: string, overwriteDefaultValue?: any) {
export function getCustomizationSetting(configuration: {[key: string]: any }, settingKey: string): any {
const isCustomizationEnabled = typeof configuration['customization.enabled'] === 'undefined'
? getSettingDefaultValue('customization.enabled')
: configuration['customization.enabled'];
const defaultValue = typeof overwriteDefaultValue !== 'undefined'
? overwriteDefaultValue
: getSettingDefaultValue(settingKey);
const defaultValue = getSettingDefaultValue(settingKey);

return ( isCustomizationEnabled && settingKey.startsWith('customization') && settingKey !== 'customization.enabled')
? (typeof configuration[settingKey] !== 'undefined' ? resolveEmptySetting(settingKey, configuration[settingKey]) : defaultValue)
: defaultValue;
if ( isCustomizationEnabled && settingKey.startsWith('customization') && settingKey !== 'customization.enabled'){
return (typeof configuration[settingKey] !== 'undefined' ? resolveEmptySetting(settingKey, configuration[settingKey]) : defaultValue);
}else{
return defaultValue;
};
};

/**
Expand Down
8 changes: 4 additions & 4 deletions server/controllers/wazuh-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { KeyEquivalence } from '../../common/csv-key-equivalence';
import { ApiErrorEquivalence } from '../lib/api-errors-equivalence';
import apiRequestList from '../../common/api-info/endpoints';
import { HTTP_STATUS_CODES } from '../../common/constants';
import { getSettingDependOnCustomizationIsEnabled } from '../../common/services/settings';
import { getCustomizationSetting } from '../../common/services/settings';
import { addJobToQueue } from '../start/queue';
import fs from 'fs';
import { ManageHosts } from '../lib/manage-hosts';
Expand Down Expand Up @@ -1110,9 +1110,9 @@ export class WazuhApiCtrl {
const HEALTHCHECK_LOGO = 'customization.logo.healthcheck';

const logos= {
[SIDEBAR_LOGO]: getSettingDependOnCustomizationIsEnabled(configuration, SIDEBAR_LOGO),
[APP_LOGO]: getSettingDependOnCustomizationIsEnabled(configuration, APP_LOGO),
[HEALTHCHECK_LOGO]: getSettingDependOnCustomizationIsEnabled(configuration, HEALTHCHECK_LOGO),
[SIDEBAR_LOGO]: getCustomizationSetting(configuration, SIDEBAR_LOGO),
[APP_LOGO]: getCustomizationSetting(configuration, APP_LOGO),
[HEALTHCHECK_LOGO]: getCustomizationSetting(configuration, HEALTHCHECK_LOGO),
}

return response.ok({
Expand Down
8 changes: 4 additions & 4 deletions server/lib/reporting/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { log } from '../logger';
import * as TimSort from 'timsort';
import { getConfiguration } from '../get-configuration';
import { REPORTS_PRIMARY_COLOR} from '../../../common/constants';
import { getSettingDefaultValue, getSettingDependOnCustomizationIsEnabled } from '../../../common/services/settings';
import { getCustomizationSetting } from '../../../common/services/settings';

const COLORS = {
PRIMARY: REPORTS_PRIMARY_COLOR
Expand Down Expand Up @@ -619,9 +619,9 @@ export class ReportPrinter{
try {
const configuration = getConfiguration();

const pathToLogo = getSettingDependOnCustomizationIsEnabled(configuration, 'customization.logo.reports');
const pageHeader = getSettingDependOnCustomizationIsEnabled(configuration, 'customization.reports.header');
const pageFooter = getSettingDependOnCustomizationIsEnabled(configuration, 'customization.reports.footer');
const pathToLogo = getCustomizationSetting(configuration, 'customization.logo.reports');
const pageHeader = getCustomizationSetting(configuration, 'customization.reports.header');
const pageFooter = getCustomizationSetting(configuration, 'customization.reports.footer');

const document = this._printer.createPdfKitDocument({ ...pageConfiguration({ pathToLogo, pageHeader, pageFooter }), content: this._content });

Expand Down

0 comments on commit 7ad0476

Please sign in to comment.