Skip to content

Commit

Permalink
Changed Asset Criticality file upload page to Entity Store Management…
Browse files Browse the repository at this point in the history
… page
  • Loading branch information
jaredburgettelastic committed Oct 14, 2024
1 parent a0a0051 commit b931655
Show file tree
Hide file tree
Showing 14 changed files with 539 additions and 210 deletions.
1 change: 1 addition & 0 deletions packages/deeplinks/security/deep_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export enum SecurityPageName {
entityAnalytics = 'entity_analytics',
entityAnalyticsManagement = 'entity_analytics-management',
entityAnalyticsAssetClassification = 'entity_analytics-asset-classification',
entityAnalyticsEntityStoreManagement = 'entity_analytics-entity_store_management',
coverageOverview = 'coverage-overview',
notes = 'notes',
}
2 changes: 2 additions & 0 deletions x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export const ENTITY_ANALYTICS_PATH = '/entity_analytics' as const;
export const ENTITY_ANALYTICS_MANAGEMENT_PATH = `/entity_analytics_management` as const;
export const ENTITY_ANALYTICS_ASSET_CRITICALITY_PATH =
`/entity_analytics_asset_criticality` as const;
export const ENTITY_ANALYTICS_ENTITY_STORE_MANAGEMENT_PATH =
`/entity_analytics_entity_store` as const;
export const APP_ALERTS_PATH = `${APP_PATH}${ALERTS_PATH}` as const;
export const APP_CASES_PATH = `${APP_PATH}${CASES_PATH}` as const;
export const APP_ENDPOINTS_PATH = `${APP_PATH}${ENDPOINTS_PATH}` as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const CATEGORIES: Array<SeparatorLinkCategory<SolutionPageName>> = [
type: LinkCategoryType.separator,
linkIds: [
SecurityPageName.entityAnalyticsManagement,
SecurityPageName.entityAnalyticsAssetClassification,
SecurityPageName.entityAnalyticsEntityStoreManagement,
], // Linked from the management cards landing.
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as i18n from './settings_translations';

const ENTITY_ANALYTICS_LINKS = [
SecurityPageName.entityAnalyticsManagement,
SecurityPageName.entityAnalyticsAssetClassification,
SecurityPageName.entityAnalyticsEntityStoreManagement,
];

export const createSettingsLinksFromManage = (manageLink: LinkItem): LinkItem[] => {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/security_solution/public/app/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const ENTITY_ANALYTICS_RISK_SCORE = i18n.translate(
}
);

export const ENTITY_STORE = i18n.translate('xpack.securitySolution.navigation.entityStore', {
defaultMessage: 'Entity Store',
});

export const NOTES = i18n.translate('xpack.securitySolution.navigation.notes', {
defaultMessage: 'Notes',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ describe('Security links', () => {
describe('isLinkUiSettingsAllowed', () => {
const SETTING_KEY = 'test setting';
const mockedLink: LinkItem = {
id: SecurityPageName.entityAnalyticsAssetClassification,
id: SecurityPageName.entityAnalyticsEntityStoreManagement,
title: 'test title',
path: '/test_path',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
*/
import { useMemo } from 'react';
import type {
DeleteEntityEngineResponse,
EntityType,
GetEntityEngineResponse,
InitEntityEngineResponse,
ListEntityEnginesResponse,
StopEntityEngineResponse,
} from '../../../common/api/entity_analytics';
import { API_VERSIONS } from '../../../common/entity_analytics/constants';
import type { EntityType } from '../../../common/api/entity_analytics/entity_store/common.gen';
import { useKibana } from '../../common/lib/kibana/kibana_react';

export const useEntityStoreRoutes = () => {
Expand All @@ -26,13 +28,28 @@ export const useEntityStoreRoutes = () => {
});
};

const stopEntityStore = async (entityType: EntityType) => {
return http.fetch<StopEntityEngineResponse>(`/api/entity_store/engines/${entityType}/stop`, {
method: 'POST',
version: API_VERSIONS.public.v1,
body: JSON.stringify({}),
});
};

const getEntityEngine = async (entityType: EntityType) => {
return http.fetch<GetEntityEngineResponse>(`/api/entity_store/engines/${entityType}`, {
method: 'GET',
version: API_VERSIONS.public.v1,
});
};

const deleteEntityEngine = async (entityType: EntityType) => {
return http.fetch<DeleteEntityEngineResponse>(`/api/entity_store/engines/${entityType}`, {
method: 'DELETE',
version: API_VERSIONS.public.v1,
});
};

const listEntityEngines = async () => {
return http.fetch<ListEntityEnginesResponse>(`/api/entity_store/engines`, {
method: 'GET',
Expand All @@ -42,7 +59,9 @@ export const useEntityStoreRoutes = () => {

return {
initEntityStore,
stopEntityStore,
getEntityEngine,
deleteEntityEngine,
listEntityEngines,
};
}, [http]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { ListEntityEnginesResponse } from '../../../../../common/api/entity
import { useEntityStoreRoutes } from '../../../api/entity_store';
import { useRiskEngineStatus } from '../../../api/hooks/use_risk_engine_status';

const ENTITY_STORE_ENGINE_STATUS = 'ENTITY_STORE_ENGINE_STATUS';
export const ENTITY_STORE_ENGINE_STATUS = 'ENTITY_STORE_ENGINE_STATUS';

interface Options {
disabled?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
* 2.0.
*/

import { useQuery } from '@tanstack/react-query';
import type { UseMutationOptions } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useCallback, useState } from 'react';

import { useEntityEngineStatus } from './use_entity_engine_status';
import type {
DeleteEntityEngineResponse,
InitEntityEngineResponse,
StopEntityEngineResponse,
} from '../../../../../common/api/entity_analytics';
import { useEntityStoreRoutes } from '../../../api/entity_store';
import { ENTITY_STORE_ENGINE_STATUS, useEntityEngineStatus } from './use_entity_engine_status';

const ENTITY_STORE_ENABLEMENT_INIT = 'ENTITY_STORE_ENABLEMENT_INIT';

Expand Down Expand Up @@ -45,3 +51,70 @@ export const useEntityStoreEnablement = () => {

return { enable };
};

export const INIT_ENTITY_ENGINE_STATUS_KEY = ['POST', 'INIT_ENTITY_ENGINE'];

export const useInvalidateEntityEngineStatusQuery = () => {
const queryClient = useQueryClient();

return useCallback(() => {
queryClient.invalidateQueries([ENTITY_STORE_ENGINE_STATUS], {
refetchType: 'active',
});
}, [queryClient]);
};

export const useInitEntityEngineMutation = (options?: UseMutationOptions<{}>) => {
const invalidateEntityEngineStatusQuery = useInvalidateEntityEngineStatusQuery();
const { initEntityStore } = useEntityStoreRoutes();
return useMutation<[InitEntityEngineResponse]>(() => Promise.all([initEntityStore('user')]), {
...options,
mutationKey: INIT_ENTITY_ENGINE_STATUS_KEY,
onSettled: (...args) => {
invalidateEntityEngineStatusQuery();

if (options?.onSettled) {
options.onSettled(...args);
}
},
});
};

export const STOP_ENTITY_ENGINE_STATUS_KEY = ['POST', 'STOP_ENTITY_ENGINE'];

export const useStopEntityEngineMutation = (options?: UseMutationOptions<{}>) => {
const invalidateEntityEngineStatusQuery = useInvalidateEntityEngineStatusQuery();
const { stopEntityStore } = useEntityStoreRoutes();
return useMutation<[StopEntityEngineResponse]>(() => Promise.all([stopEntityStore('user')]), {
...options,
mutationKey: STOP_ENTITY_ENGINE_STATUS_KEY,
onSettled: (...args) => {
invalidateEntityEngineStatusQuery();

if (options?.onSettled) {
options.onSettled(...args);
}
},
});
};

export const DELETE_ENTITY_ENGINE_STATUS_KEY = ['POST', 'STOP_ENTITY_ENGINE'];

export const useDeleteEntityEngineMutation = (options?: UseMutationOptions<{}>) => {
const invalidateEntityEngineStatusQuery = useInvalidateEntityEngineStatusQuery();
const { deleteEntityEngine } = useEntityStoreRoutes();
return useMutation<[DeleteEntityEngineResponse]>(
() => Promise.all([deleteEntityEngine('user')]),
{
...options,
mutationKey: DELETE_ENTITY_ENGINE_STATUS_KEY,
onSettled: (...args) => {
invalidateEntityEngineStatusQuery();

if (options?.onSettled) {
options.onSettled(...args);
}
},
}
);
};

This file was deleted.

Loading

0 comments on commit b931655

Please sign in to comment.