Skip to content

Commit

Permalink
FE general polish (elastic#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
orouz authored Jan 3, 2022
1 parent c3c4588 commit 31ac3d2
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 69 deletions.
7 changes: 0 additions & 7 deletions x-pack/plugins/cloud_security_posture/.i18nrc.json

This file was deleted.

5 changes: 2 additions & 3 deletions x-pack/plugins/cloud_security_posture/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const CSP_KUBEBEAT_INDEX_PATTERN = 'kubebeat*';
export const CSP_KUBEBEAT_INDEX_NAME = 'findings';
export const CSP_KUBEBEAT_INDEX_NAME = 'kubebeat*';
export const CSP_FINDINGS_INDEX_NAME = 'findings';
export const STATS_ROUTH_PATH = '/api/csp/stats';
export const FINDINGS_ROUTH_PATH = '/api/csp/finding';
export const AGENT_LOGS_INDEX = 'kubebeat*';
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/cloud_security_posture/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +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 const PLUGIN_ID = 'csp';
export const PLUGIN_NAME = 'csp';
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import { useQuery } from 'react-query';
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
import { CloudPostureStats } from '../../../common/types';
import { STATS_ROUTH_PATH } from '../../../common/constants';

export const useCloudPostureStatsApi = () => {
const { http } = useKibana().services;
return useQuery(['csp_dashboard_stats'], () => http!.get<CloudPostureStats>('/api/csp/stats'));
return useQuery(['csp_dashboard_stats'], () => http!.get<CloudPostureStats>(STATS_ROUTH_PATH));
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const navItems: NonNullable<KibanaPageTemplateProps['solutionNav']>['items'] = n
id: route.name,
...route,
renderItem: () => (
<NavLink to={route.path as string} activeStyle={activeItemStyle}>
<NavLink to={route.path} activeStyle={activeItemStyle}>
{route.name}
</NavLink>
),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks'
import { coreMock } from '../../../../../../src/core/public/mocks';
import { createStubDataView } from '../../../../../../src/plugins/data_views/public/data_views/data_view.stub';
import * as utils from './utils';
import { CSP_KUBEBEAT_INDEX_PATTERN } from '../../../common/constants';
import { CSP_KUBEBEAT_INDEX_NAME } from '../../../common/constants';
import { TEST_SUBJECTS } from './constants';
import type { UseQueryResult } from 'react-query';
import type { DataView } from '../../../../../../src/plugins/data/common';
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('<Findings />', () => {
status: 'success',
data: createStubDataView({
spec: {
id: CSP_KUBEBEAT_INDEX_PATTERN,
id: CSP_KUBEBEAT_INDEX_NAME,
},
}),
} as UseQueryResult<DataView>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
TimeRange,
} from '../../../../../../src/plugins/data/common';
import type { CspPluginSetup } from '../../types';
import { CSP_KUBEBEAT_INDEX_PATTERN } from '../../../common/constants';
import { CSP_KUBEBEAT_INDEX_NAME } from '../../../common/constants';
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';

export const extractErrorMessage = (e: unknown): string =>
Expand All @@ -37,15 +37,15 @@ export const useKubebeatDataView = () => {

const createDataView = () =>
dataViews.createAndSave({
title: CSP_KUBEBEAT_INDEX_PATTERN,
title: CSP_KUBEBEAT_INDEX_NAME,
allowNoIndex: false,
});

// TODO: check if index exists
// if not, no point in creating a data view
// const check = () => http?.get(`/kubebeat`);

const findDataView = async () => (await dataViews.find(CSP_KUBEBEAT_INDEX_PATTERN))?.[0];
const findDataView = async () => (await dataViews.find(CSP_KUBEBEAT_INDEX_NAME))?.[0];

const getKubebeatDataView = () => findDataView().then((v) => (v ? v : createDataView()));

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cloud_security_posture/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class CspPlugin implements Plugin<CspSetup, CspStart, CspPluginSetup, Csp
// Register an application into the side navigation menu

core.application.register({
id: 'csp_root',
id: 'csp',
title: PLUGIN_NAME,
status: AppStatus.accessible,
navLinkStatus: AppNavLinkStatus.hidden,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { MappingProperty } from '@elastic/elasticsearch/lib/api/types';
import type { ElasticsearchClient } from 'src/core/server';
import { CSP_KUBEBEAT_INDEX_PATTERN, CSP_KUBEBEAT_INDEX_NAME } from '../..//common/constants';
import { CSP_KUBEBEAT_INDEX_NAME, CSP_FINDINGS_INDEX_NAME } from '../..//common/constants';
import findingsIndexMapping from './findings_mapping.json';

export type Status = boolean;
Expand Down Expand Up @@ -51,12 +51,12 @@ export const createFindingsIndexTemplate = async (
esClient: ElasticsearchClient
): Promise<Status> => {
try {
const isExisting = await doesIndexTemplateExist(esClient, CSP_KUBEBEAT_INDEX_NAME);
const isExisting = await doesIndexTemplateExist(esClient, CSP_FINDINGS_INDEX_NAME);
if (isExisting) return true;
return await createIndexTemplate(
esClient,
CSP_FINDINGS_INDEX_NAME,
CSP_KUBEBEAT_INDEX_NAME,
CSP_KUBEBEAT_INDEX_PATTERN,
// TODO: check why this cast is required
findingsIndexMapping as Record<string, MappingProperty>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { schema as rt, TypeOf } from '@kbn/config-schema';
import type { ElasticsearchClient } from 'src/core/server';
import type { IRouter } from 'src/core/server';
import { getLatestCycleIds } from './get_latest_cycle_ids';
import { CSP_KUBEBEAT_INDEX_PATTERN, FINDINGS_ROUTH_PATH } from '../../../common/constants';
import { CSP_KUBEBEAT_INDEX_NAME, FINDINGS_ROUTH_PATH } from '../../../common/constants';
export const DEFAULT_FINDINGS_PER_PAGE = 20;
type FindingsQuerySchema = TypeOf<typeof schema>;

Expand Down Expand Up @@ -42,7 +42,7 @@ const getFindingsEsQuery = async (
): Promise<SearchRequest> => {
const query = await buildQueryFilter(esClient, queryParams);
return {
index: CSP_KUBEBEAT_INDEX_PATTERN,
index: CSP_KUBEBEAT_INDEX_NAME,
query,
size: queryParams.per_page,
from:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
QueryDslQueryContainer,
} from '@elastic/elasticsearch/lib/api/types';

import { CSP_KUBEBEAT_INDEX_PATTERN } from '../../../common/constants';
import { CSP_KUBEBEAT_INDEX_NAME } from '../../../common/constants';

export const getFindingsEsQuery = (
cycleId: string,
Expand All @@ -28,7 +28,7 @@ export const getFindingsEsQuery = (
}

return {
index: CSP_KUBEBEAT_INDEX_PATTERN,
index: CSP_KUBEBEAT_INDEX_NAME,
query: {
bool: { filter },
},
Expand All @@ -53,7 +53,7 @@ export const getResourcesEvaluationEsQuery = (
query.bool!.must = { terms: { 'resource.filename.keyword': resources } };
}
return {
index: CSP_KUBEBEAT_INDEX_PATTERN,
index: CSP_KUBEBEAT_INDEX_NAME,
size,
query,
aggs: {
Expand All @@ -66,7 +66,7 @@ export const getResourcesEvaluationEsQuery = (
};

export const getBenchmarksQuery = (): SearchRequest => ({
index: CSP_KUBEBEAT_INDEX_PATTERN,
index: CSP_KUBEBEAT_INDEX_NAME,
size: 0,
aggs: {
benchmarks: {
Expand All @@ -76,7 +76,7 @@ export const getBenchmarksQuery = (): SearchRequest => ({
});

export const getLatestFindingQuery = (): SearchRequest => ({
index: CSP_KUBEBEAT_INDEX_PATTERN,
index: CSP_KUBEBEAT_INDEX_NAME,
size: 1,
/* @ts-expect-error TS2322 - missing SearchSortContainer */
sort: { '@timestamp': 'desc' },
Expand Down

0 comments on commit 31ac3d2

Please sign in to comment.