Skip to content

Commit

Permalink
Merge branch 'master' into change/401-remove-legacy-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
yenienserrano authored Dec 16, 2024
2 parents 7714990 + bf0537c commit 10b9113
Show file tree
Hide file tree
Showing 85 changed files with 14,269 additions and 868 deletions.
82 changes: 75 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
'react-hooks',
'@typescript-eslint',
'unicorn',
'import',
'prettier',
'@stylistic',
],
Expand All @@ -52,14 +53,20 @@ module.exports = {
message:
"Don't use arrow functions in class properties. Use a function instead.",
},
{
selector:
'MemberExpression > LogicalExpression[operator="||"]:has(Identifier):has(ObjectExpression[properties.length=0])',
message: 'Use optional chaining operator instead (?.).',
},
{
selector:
'MemberExpression > LogicalExpression[operator="||"]:has(Identifier):has(ArrayExpression[elements.length=0])',
message: 'Use optional chaining operator instead (?.).',
},
],
'prefer-arrow-callback': 'error',
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
'arrow-body-style': [
'error',
'as-needed',
{ requireReturnForObjectLiteral: true },
],
'arrow-body-style': ['error', 'as-needed'],
'no-unreachable': 'error',
'no-fallthrough': [
'error',
Expand All @@ -81,7 +88,7 @@ module.exports = {
'block-scoped-var': 'error',
'default-case': 'error',
'default-case-last': 'error',
'default-param-last': 'error',
'default-param-last': 'off',
eqeqeq: ['error', 'always'],
'no-var': 'error',
/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -162,6 +169,7 @@ module.exports = {
/* -------------------------------------------------------------------------- */
/* unicorn */
/* -------------------------------------------------------------------------- */
'unicorn/prefer-module': 'off',
'unicorn/prefer-ternary': 'off',
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/custom-error-definition.md
'unicorn/custom-error-definition': 'error',
Expand Down Expand Up @@ -202,14 +210,44 @@ module.exports = {
/* -------------------------------------------------------------------------- */
/* @typescript-eslint */
/* -------------------------------------------------------------------------- */
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
// Whether to check all, some, or no arguments.
args: 'after-used',
// Regular expressions of argument names to not check for usage.
argsIgnorePattern: '^_',
// Whether to check catch block arguments.
caughtErrors: 'all',
// Regular expressions of catch block argument names to not check for usage.
caughtErrorsIgnorePattern: '^_',
// Regular expressions of destructured array variable names to not check for usage.
destructuredArrayIgnorePattern: '^_',
// Whether to ignore classes with at least one static initialization block.
ignoreClassWithStaticInitBlock: false,
// Whether to ignore sibling properties in `...` destructurings.
ignoreRestSiblings: false,
// Whether to report variables that match any of the valid ignore pattern options if they have been used.
reportUsedIgnorePattern: true,
// Whether to check all variables or only locally-declared variables.
vars: 'all',
// Regular expressions of variable names to not check for usage.
varsIgnorePattern: '[iI]gnored$',
},
],
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/no-extraneous-class': 'off',
'@typescript-eslint/method-signature-style': ['error', 'property'],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/naming-convention': [
'error',
{ selector: 'default', format: ['camelCase'] },
{
selector: 'default',
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow',
},
{
selector: ['objectLiteralProperty', 'typeProperty'],
format: null,
Expand All @@ -225,6 +263,12 @@ module.exports = {
{
selector: ['variable'],
modifiers: ['global'],
format: ['UPPER_CASE', 'camelCase', 'PascalCase'],
},
{
selector: ['variable'],
modifiers: ['global'],
types: ['boolean', 'number', 'string'],
format: ['UPPER_CASE'],
},
{
Expand Down Expand Up @@ -308,5 +352,29 @@ module.exports = {
],
},
},
{
// constants files
files: ['plugins/**/constants.{ts,js}'],
rules: {
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'variable',
modifiers: ['global'],
format: ['UPPER_CASE'],
},
],
},
},
{
files: ['plugins/**/*.test.{js,jsx,ts,tsx}'],
rules: {
'@typescript-eslint/no-empty-function': [
'error',
{ allow: ['arrowFunctions'] },
],
'@typescript-eslint/no-unused-vars': 'off',
},
},
],
};
5 changes: 3 additions & 2 deletions .github/workflows/dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,17 @@ jobs:
cd /home/node/kbn/plugins/${{ matrix.plugins.container_path }} && yarn && ${{ inputs.command }};
'
- name: Get the plugin version
- name: Get the plugin version and and format reference name
run: |
echo "githubReference=$(echo ${{ inputs.reference }} | sed 's/\//-/g')" >> $GITHUB_ENV
echo "version=$(jq -r '.version' $(pwd)/wazuh/plugins/main/package.json)" >> $GITHUB_ENV
echo "revision=$(jq -r '.revision' $(pwd)/wazuh/plugins/main/package.json)" >> $GITHUB_ENV
- name: Step 04 - Upload artifact to GitHub
if: ${{ inputs.artifact_name && inputs.artifact_path }}
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.artifact_name }}_${{ env.version }}-${{ env.revision }}_${{ inputs.reference }}.zip
name: ${{ inputs.artifact_name }}_${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip
path: ${{ matrix.plugins.path }}/${{ inputs.artifact_path }}
if-no-files-found: 'error'

Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/manual-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ jobs:
ref: ${{ inputs.reference }}
path: wazuh

- name: Step 02 - Get version and revision
- name: Step 02 - Set variables
run: |
echo "githubReference=$(echo ${{ inputs.reference }} | sed 's/\//-/g')" >> $GITHUB_ENV
echo "currentDir=$(pwd -P)" >> $GITHUB_ENV
echo "version=$(jq -r '.version' $(pwd)/wazuh/plugins/main/package.json)" >> $GITHUB_ENV
echo "revision=$(jq -r '.revision' $(pwd)/wazuh/plugins/main/package.json)" >> $GITHUB_ENV
Expand All @@ -55,11 +56,11 @@ jobs:
- name: Step 03 - Download the plugin's source code
uses: actions/download-artifact@v3
with:
name: wazuh-dashboard-plugins_${{ env.version }}-${{ env.revision }}_${{ inputs.reference }}.zip
path: ${{ env.currentDir }}/wazuh/scripts/test-packages/wazuh-dashboard-plugins_${{ env.version }}-${{ env.revision }}_${{ inputs.reference }}.zip
name: wazuh-dashboard-plugins_${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip
path: ${{ env.currentDir }}/wazuh/scripts/test-packages/wazuh-dashboard-plugins_${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip

- name: Step 04 - Build the Docker image
run: |
echo "current=${{ env.currentDir }}"
cd ./wazuh/scripts/test-packages
docker build --build-arg OSD_VERSION=${{ env.versionPlatform }} --build-arg PACKAGE_NAME=wazuh-dashboard-plugins_${{ env.version }}-${{ env.revision }}_${{ inputs.reference }}.zip -f osd-test-packages.Dockerfile ./
docker build --build-arg OSD_VERSION=${{ env.versionPlatform }} --build-arg PACKAGE_NAME=wazuh-dashboard-plugins_${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip -f osd-test-packages.Dockerfile ./
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to the Wazuh app project will be documented in this file.

- Support for Wazuh 5.0.0
- Added creation of report definition when creating dashboard by reference and the button to reset the report [#7091](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7091)
- Added a frontend http client to core plugin [#7000](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7000)
- Added an initilization service to core plugin to run the initilization tasks related to user scope [#7145](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7145)

### Removed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { EuiButton, EuiEmptyPrompt, EuiLink } from '@elastic/eui';
import { withGuardAsync } from '../../../../common/hocs';
import { getSavedObjects } from '../../../../../kibana-services';
import { SavedObject } from '../../../../../react-services';
import { NOT_TIME_FIELD_NAME_INDEX_PATTERN } from '../../../../../../common/constants';
import { EuiButton, EuiEmptyPrompt, EuiLink } from '@elastic/eui';
import { webDocumentationLink } from '../../../../../../common/services/web_documentation';
import { vulnerabilityDetection } from '../../../../../utils/applications';
import { LoadingSpinnerDataSource } from '../../../../common/loading/loading-spinner-data-source';
import NavigationService from '../../../../../react-services/navigation-service';
import { NavigationService } from '../../../../../react-services/navigation-service';

const INDEX_PATTERN_CREATION_NO_INDEX = 'INDEX_PATTERN_CREATION_NO_INDEX';

Expand All @@ -20,15 +20,16 @@ async function checkExistenceIndexPattern(indexPatternID: string) {
async function checkExistenceIndices(indexPatternId: string) {
try {
const fields = await SavedObject.getIndicesFields(indexPatternId);

return { exist: true, fields };
} catch (error) {
} catch {
return { exist: false };
}
}

async function createIndexPattern(indexPattern, fields: any) {
try {
await SavedObject.createSavedObjectIndexPattern(
await SavedObject.createSavedObject(
'index-pattern',
indexPattern,
{
Expand All @@ -51,7 +52,7 @@ export async function validateVulnerabilitiesStateDataSources({
try {
// Check the existence of related index pattern
const existIndexPattern = await checkExistenceIndexPattern(indexPatternID);
let indexPattern = existIndexPattern;
const indexPattern = existIndexPattern;

// If the idnex pattern does not exist, then check the existence of index
if (existIndexPattern?.error?.statusCode === 404) {
Expand All @@ -70,11 +71,13 @@ export async function validateVulnerabilitiesStateDataSources({
},
};
}

// If the some index match the index pattern, then create the index pattern
const resultCreateIndexPattern = await createIndexPattern(
indexPatternID,
fields,
);

if (resultCreateIndexPattern?.error) {
return {
ok: true,
Expand All @@ -86,6 +89,7 @@ export async function validateVulnerabilitiesStateDataSources({
},
};
}

/* WORKAROUND: Redirect to the root of Vulnerabilities Detection application that should
redirects to the Dashboard tab. We want to redirect to this view, because we need the
component is visible (visualizations) to ensure the process that defines the filters for the
Expand All @@ -95,6 +99,7 @@ export async function validateVulnerabilitiesStateDataSources({
*/
NavigationService.getInstance().navigateToApp(vulnerabilityDetection.id);
}

return {
ok: false,
data: { indexPattern },
Expand Down Expand Up @@ -127,10 +132,13 @@ const errorPromptBody = {
),
};

export const PromptCheckIndex = props => {
export const PromptCheckIndex = (props: {
error: { title: string; message: string; type?: string };
refresh: () => void;
}) => {
const { refresh } = props;
const { title, message } = props?.error;
const body = errorPromptBody?.[props?.error?.type] || <p>{message}</p>;
const { title, message } = props.error;
const body = errorPromptBody?.[props.error?.type] || <p>{message}</p>;

return (
<EuiEmptyPrompt
Expand All @@ -146,10 +154,12 @@ export const PromptCheckIndex = props => {
);
};

const mapStateToProps = state => ({
vulnerabilitiesStatesindexPatternID:
state.appConfig.data['vulnerabilities.pattern'],
});
const mapStateToProps = state => {
return {
vulnerabilitiesStatesindexPatternID:
state.appConfig.data['vulnerabilities.pattern'],
};
};

export const withVulnerabilitiesStateDataSource = compose(
connect(mapStateToProps),
Expand Down
68 changes: 47 additions & 21 deletions plugins/main/public/components/search-bar/query-language/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,58 @@
import { suggestItem } from '../../wz-search-bar';
import { AQL } from './aql';
import { WQL } from './wql';

type SearchBarQueryLanguage = {
description: string;
documentationLink?: string;
interface SearchBarProps {
suggestions: suggestItem[];
onItemClick: (currentInput: string) => (item: suggestItem) => void;
prepend?: React.ReactNode;
disableFocusTrap?: boolean;
isInvalid?: boolean;
onKeyPress?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
}

interface SearchBarQueryLanguage {
id: string;
label: string;
description: string;
documentationLink?: string;
getConfiguration?: () => any;
run: (input: string | undefined, params: any) => Promise<{
searchBarProps: any,
run: (
input: string | undefined,
params: any,
) => Promise<{
filterButtons?: React.ReactElement | null;
searchBarProps: SearchBarProps;
output: {
language: string,
unifiedQuery: string,
query: string
}
language: string;
unifiedQuery?: string;
apiQuery?: {
q: string;
};
query: string;
};
}>;
transformInput: (unifiedQuery: string, options: {configuration: any, parameters: any}) => string;
};
transformInput?: (
unifiedQuery: string,
options: { configuration: any; parameters: any },
) => string;
transformUQLToQL?: (unifiedQuery: string) => string;
}

// Register the query languages
export const searchBarQueryLanguages: {
[key: string]: SearchBarQueryLanguage;
} = [AQL, WQL].reduce((accum, item) => {
if (accum[item.id]) {
throw new Error(`Query language with id: ${item.id} already registered.`);
function initializeSearchBarQueryLanguages() {
const languages = [AQL, WQL];
const result: Record<string, SearchBarQueryLanguage> = {};

for (const item of languages) {
if (result[item.id]) {
throw new Error(`Query language with id: ${item.id} already registered.`);
}

result[item.id] = item;
}
return {
...accum,
[item.id]: item,
};
}, {});

return result;
}

export const searchBarQueryLanguages = initializeSearchBarQueryLanguages();
Loading

0 comments on commit 10b9113

Please sign in to comment.