Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Machi3mfl committed Dec 24, 2024
1 parent f42c941 commit 1b69592
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
66 changes: 33 additions & 33 deletions plugins/wazuh-core/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,23 +408,23 @@ export enum SettingCategory {
API_CONNECTION,
}

export type TPluginSettingOptionsTextArea = {
export interface TPluginSettingOptionsTextArea {
maxRows?: number;
minRows?: number;
maxLength?: number;
};
}

export type TPluginSettingOptionsSelect = {
export interface TPluginSettingOptionsSelect {
select: { text: string; value: any }[];
};
}

export type TPluginSettingOptionsEditor = {
export interface TPluginSettingOptionsEditor {
editor: {
language: string;
};
};
}

export type TPluginSettingOptionsFile = {
export interface TPluginSettingOptionsFile {
file: {
type: 'image';
extensions?: string[];
Expand All @@ -445,34 +445,24 @@ export type TPluginSettingOptionsFile = {
resolveStaticURL: (filename: string) => string;
};
};
};
}

export type TPluginSettingOptionsNumber = {
export interface TPluginSettingOptionsNumber {
number: {
min?: number;
max?: number;
integer?: boolean;
};
};
}

export type TPluginSettingOptionsSwitch = {
export interface TPluginSettingOptionsSwitch {
switch: {
values: {
disabled: { label?: string; value: any };
enabled: { label?: string; value: any };
};
};
};

export type TPlugginSettingOptionsObjectOf = {
objectOf: {
[key: string]: TPluginSetting;
};
};

type TPluginSettingOptionsArrayOf = {
arrayOf: TPluginSetting;
};
}

export enum EpluginSettingType {
text = 'text',
Expand All @@ -488,6 +478,24 @@ export enum EpluginSettingType {
objectOf = 'objectOf',
}

export interface TPluginSettingOptionsObjectOf {
/* eslint-disable no-use-before-define */
objectOf: Record<string, TPluginSetting>;
}

interface TPluginSettingOptionsArrayOf {
arrayOf: TPluginSetting;
}

type TPlugingSettingOptions =
| TPluginSettingOptionsTextArea
| TPluginSettingOptionsSelect
| TPluginSettingOptionsEditor
| TPluginSettingOptionsFile
| TPluginSettingOptionsNumber
| TPluginSettingOptionsSwitch
| TPluginSettingOptionsObjectOf
| TPluginSettingOptionsArrayOf;
export interface TPluginSetting {
// Define the text displayed in the UI.
title: string;
Expand All @@ -498,21 +506,13 @@ export interface TPluginSetting {
// Type.
type: EpluginSettingType;
source: EConfigurationProviders;
options?:
| TPluginSettingOptionsTextArea
| TPluginSettingOptionsSelect
| TPluginSettingOptionsEditor
| TPluginSettingOptionsFile
| TPluginSettingOptionsNumber
| TPluginSettingOptionsSwitch
| TPlugginSettingOptionsObjectOf
| TPluginSettingOptionsArrayOf;
options?: TPlugingSettingOptions;
// Default value.
defaultValue: any;
validate?: (value: any) => string | undefined;
}

export const PLUGIN_SETTINGS: { [key: string]: TPluginSetting } = {
export const PLUGIN_SETTINGS: Record<string, TPluginSetting> = {
'alerts.sample.prefix': {
title: 'Sample alerts prefix',
description:
Expand Down Expand Up @@ -618,7 +618,7 @@ export const PLUGIN_SETTINGS: { [key: string]: TPluginSetting } = {
defaultValue: false,
validate: SettingsValidator.isBoolean,
},
/*`# The following configuration is the default structure to define a host.
/* `# The following configuration is the default structure to define a host.
#
# hosts:
# # Host ID / name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { EConfigurationProviders } from '../../../common/constants';

export class UISettingsConfigProvider implements IConfigurationProvider {
private name: string = EConfigurationProviders.PLUGIN_UI_SETTINGS;
constructor(private uiSettings: IUiSettingsClient) {}

constructor(private readonly uiSettings: IUiSettingsClient) {}

setName(name: string): void {
this.name = name;
Expand All @@ -28,19 +29,20 @@ export class UISettingsConfigProvider implements IConfigurationProvider {

async getAll() {
const settings = this.uiSettings.getAll();
// loop and get all settings that have the category wazuhCore
const wazuhCoreSettings = Object.keys(settings).reduce(
(acc, key) => {
if (
settings[key].category &&
settings[key].category.includes('wazuhCore')
) {
acc[key] = settings[key];
}
return acc;
},
{} as Record<string, PublicUiSettingsParams & UserProvidedValues>,
);
const wazuhCoreSettings: Record<
string,
PublicUiSettingsParams & UserProvidedValues
> = {};

for (const key in settings) {
if (
settings[key].category &&
settings[key].category.includes('wazuhCore')
) {
wazuhCoreSettings[key] = settings[key];
}
}

return wazuhCoreSettings;
}
}

0 comments on commit 1b69592

Please sign in to comment.