Skip to content

Commit

Permalink
Preliminary refactoring: folder restructuring and creating API hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
banderror committed Oct 13, 2022
1 parent 0980919 commit 72dbef3
Show file tree
Hide file tree
Showing 1,175 changed files with 4,110 additions and 5,032 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ x-pack/test/threat_intelligence_cypress @elastic/protections-experience


# Security Intelligence And Analytics
/x-pack/plugins/security_solution/server/lib/detection_engine/rules/prepackaged_rules @elastic/security-intelligence-analytics
/x-pack/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/content/prepackaged_rules @elastic/security-intelligence-analytics


# Security Asset Management
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ export const RISK_SCORE_DELETE_STORED_SCRIPT = `${INTERNAL_RISK_SCORE_URL}/store
*/
export const INTERNAL_DETECTION_ENGINE_URL = '/internal/detection_engine' as const;
export const INTERNAL_DETECTION_ENGINE_RULES_URL = '/internal/detection_engine/rules' as const;
export const DETECTION_ENGINE_INSTALLED_INTEGRATIONS_URL =
`${INTERNAL_DETECTION_ENGINE_URL}/fleet/integrations/installed` as const;
export const DETECTION_ENGINE_ALERTS_INDEX_URL =
`${INTERNAL_DETECTION_ENGINE_URL}/signal/index` as const;
export const DETECTION_ENGINE_RULES_EXCEPTIONS_REFERENCE_URL =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { InstalledIntegrationArray } from '../common';
import type { InstalledIntegrationArray } from '../../model/installed_integrations';

export interface GetInstalledIntegrationsResponse {
installed_integrations: InstalledIntegrationArray;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { INTERNAL_DETECTION_ENGINE_URL as INTERNAL_URL } from '../../../constants';

export const GET_INSTALLED_INTEGRATIONS_URL =
`${INTERNAL_URL}/fleet/integrations/installed` as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './api/get_installed_integrations/response_schema';
export * from './api/urls';

export * from './model/installed_integrations';
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

export * from './installed_integrations';
export * from './pagination';
export * from './rule_params';
export * from './schemas';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

export * from './error_schema';
export * from './get_installed_integrations_response_schema';
export * from './find_exception_list_references_schema';
export * from './import_rules_schema';
export * from './prepackaged_rules_schema';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { waitFor, render, act } from '@testing-library/react';
import { AlertSummaryView } from './alert_summary_view';
import { mockAlertDetailsData } from './__mocks__';
import type { TimelineEventsDetailsItem } from '../../../../common/search_strategy';
import { useRuleWithFallback } from '../../../detections/containers/detection_engine/rules/use_rule_with_fallback';
import { useRuleWithFallback } from '../../../detection_engine/rule_management/logic/use_rule_with_fallback';

import { TestProviders, TestProvidersComponent } from '../../mock';
import { TimelineId } from '../../../../common/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import styled from 'styled-components';
import type { GetBasicDataFromDetailsData } from '../../../timelines/components/side_panel/event_details/helpers';
import { useBasicDataFromDetailsData } from '../../../timelines/components/side_panel/event_details/helpers';
import * as i18n from './translations';
import { useRuleWithFallback } from '../../../detections/containers/detection_engine/rules/use_rule_with_fallback';
import { useRuleWithFallback } from '../../../detection_engine/rule_management/logic/use_rule_with_fallback';
import { MarkdownRenderer } from '../markdown_editor';
import { LineClamp } from '../line_clamp';
import type { TimelineEventsDetailsItem } from '../../../../common/search_strategy';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import React, { useCallback, useState } from 'react';
import type {
ImportDataResponse,
ImportDataProps,
} from '../../../detections/containers/detection_engine/rules';
} from '../../../detection_engine/rule_management/logic';
import { useAppToasts } from '../../hooks/use_app_toasts';
import * as i18n from './translations';
import { showToasterMessage } from './utils';
Expand All @@ -48,6 +48,7 @@ interface ImportDataModalProps {
/**
* Modal component for importing Rules from a json file
*/
// TODO split into two: timelines and rules
export const ImportDataModalComponent = ({
checkBoxLabel,
closeModal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
ImportResponseError,
ImportRulesResponseError,
ExceptionsImportError,
} from '../../../detections/containers/detection_engine/rules';
} from '../../../detection_engine/rule_management/logic';

export const formatError = (
i18nFailedDetailedMessage: (message: string) => string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface UseGetInstalledJobReturn {
isLicensed: boolean;
}

// TODO react-query
export const useGetInstalledJob = (jobIds: string[]): UseGetInstalledJobReturn => {
const [jobs, setJobs] = useState<CombinedJobWithStats[]>([]);
const { addError } = useAppToasts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import { getJobsSummary } from '../api/get_jobs_summary';

const _getJobsSummary = withOptionalSignal(getJobsSummary);

// TODO rewrite to react-query
export const useGetJobsSummary = () => useAsync(_getJobsSummary);
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as i18n from './translations';

import type { RuleRisk } from '../../../../common/search_strategy';

import { RuleLink } from '../../../detections/pages/detection_engine/rules/all/use_columns';
import { RuleLink } from '../../../detection_engine/rule_management_ui/components/rules_table/use_columns';

export interface TopRiskScoreContributorsProps {
loading: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { Rule } from '../../../detections/containers/detection_engine/rules';
import type { Rule } from '../../../detection_engine/rule_management/logic';
import * as i18n from '../../../detections/pages/detection_engine/rules/translations';
import { isMlRule } from '../../../../common/machine_learning/helpers';
import * as detectionI18n from '../../../detections/pages/detection_engine/translations';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { GetInstalledIntegrationsResponse } from '../../../../../common/detection_engine/fleet_integrations';
import type {
FetchInstalledIntegrationsArgs,
IFleetIntegrationsApiClient,
} from '../api_client_interface';

export const fleetIntegrationsApi: jest.Mocked<IFleetIntegrationsApiClient> = {
fetchInstalledIntegrations: jest
.fn<Promise<GetInstalledIntegrationsResponse>, [FetchInstalledIntegrationsArgs]>()
.mockResolvedValue({
installed_integrations: [
{
package_name: 'atlassian_bitbucket',
package_title: 'Atlassian Bitbucket',
package_version: '1.0.1',
integration_name: 'audit',
integration_title: 'Audit Logs',
is_enabled: true,
},
{
package_name: 'system',
package_title: 'System',
package_version: '1.6.4',
is_enabled: true,
},
],
}),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './api_client';
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { GetInstalledIntegrationsResponse } from '../../../../common/detection_engine/fleet_integrations';
import { GET_INSTALLED_INTEGRATIONS_URL } from '../../../../common/detection_engine/fleet_integrations';
import { KibanaServices } from '../../../common/lib/kibana';

import type {
FetchInstalledIntegrationsArgs,
IFleetIntegrationsApiClient,
} from './api_client_interface';

export const fleetIntegrationsApi: IFleetIntegrationsApiClient = {
fetchInstalledIntegrations: (
args: FetchInstalledIntegrationsArgs
): Promise<GetInstalledIntegrationsResponse> => {
const { packages, signal } = args;

return http().fetch<GetInstalledIntegrationsResponse>(GET_INSTALLED_INTEGRATIONS_URL, {
method: 'GET',
query: {
packages: packages?.sort()?.join(','),
},
signal,
});
},
};

const http = () => KibanaServices.get().http;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { GetInstalledIntegrationsResponse } from '../../../../common/detection_engine/fleet_integrations';

export interface IFleetIntegrationsApiClient {
/**
* Fetch all installed integrations.
* @throws An error if response is not OK
*/
fetchInstalledIntegrations(
args: FetchInstalledIntegrationsArgs
): Promise<GetInstalledIntegrationsResponse>;
}

export interface FetchInstalledIntegrationsArgs {
/**
* Array of Fleet packages to filter for.
*/
packages?: string[];

/**
* Optional signal for cancelling the request.
*/
signal?: AbortSignal;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './api_client_interface';
export * from './api_client';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './api';
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

import type { List } from '@kbn/securitysolution-io-ts-list-types';
import type { CreateRulesSchema } from '../../../../../../common/detection_engine/schemas/request';
import type { Rule } from '../../../../containers/detection_engine/rules';
import type { CreateRulesSchema } from '../../../../../common/detection_engine/schemas/request';
import type { Rule } from '../../../rule_management/logic';
import {
getListMock,
getEndpointListMock,
} from '../../../../../../common/detection_engine/schemas/types/lists.mock';
} from '../../../../../common/detection_engine/schemas/types/lists.mock';
import type {
DefineStepRuleJson,
ScheduleStepRuleJson,
Expand All @@ -21,7 +21,7 @@ import type {
ActionsStepRule,
ScheduleStepRule,
DefineStepRule,
} from '../types';
} from '../../../../detections/pages/detection_engine/rules/types';
import {
getTimeTypeValue,
formatDefineStepData,
Expand All @@ -38,8 +38,8 @@ import {
mockScheduleStepRule,
mockAboutStepRule,
mockActionsStepRule,
} from '../all/__mocks__/mock';
import { getThreatMock } from '../../../../../../common/detection_engine/schemas/types/threat.mock';
} from '../../../rule_management_ui/components/rules_table/__mocks__/mock';
import { getThreatMock } from '../../../../../common/detection_engine/schemas/types/threat.mock';
import type { Threat, Threats } from '@kbn/securitysolution-io-ts-alerting-types';

describe('helpers', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import type {
Type,
} from '@kbn/securitysolution-io-ts-alerting-types';
import { ENDPOINT_LIST_ID } from '@kbn/securitysolution-list-constants';
import { NOTIFICATION_THROTTLE_NO_ACTIONS } from '../../../../../../common/constants';
import { assertUnreachable } from '../../../../../../common/utility_types';
import { NOTIFICATION_THROTTLE_NO_ACTIONS } from '../../../../../common/constants';
import { assertUnreachable } from '../../../../../common/utility_types';
import {
transformAlertToRuleAction,
transformAlertToRuleResponseAction,
} from '../../../../../../common/detection_engine/transform_actions';
} from '../../../../../common/detection_engine/transform_actions';

import type {
AboutStepRule,
Expand All @@ -41,10 +41,10 @@ import type {
ActionsStepRuleJson,
RuleStepsFormData,
RuleStep,
} from '../types';
import { DataSourceType } from '../types';
import type { CreateRulesSchema } from '../../../../../../common/detection_engine/schemas/request';
import { stepActionsDefaultValue } from '../../../../components/rules/step_rule_actions';
} from '../../../../detections/pages/detection_engine/rules/types';
import { DataSourceType } from '../../../../detections/pages/detection_engine/rules/types';
import type { CreateRulesSchema } from '../../../../../common/detection_engine/schemas/request';
import { stepActionsDefaultValue } from '../../../../detections/components/rules/step_rule_actions';

export const getTimeTypeValue = (time: string): { unit: Unit; value: number } => {
const timeObj: { unit: Unit; value: number } = {
Expand Down
Loading

0 comments on commit 72dbef3

Please sign in to comment.