-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cloud Posture] add resource findings table #131334
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { EuiEmptyPrompt, EuiBasicTable } from '@elastic/eui'; | ||
import { extractErrorMessage } from '../../../../../common/utils/helpers'; | ||
import * as TEXT from '../../translations'; | ||
import type { ResourceFindingsResult } from './use_resource_findings'; | ||
import { getFindingsColumns } from '../../layout/findings_layout'; | ||
|
||
type FindingsGroupByResourceProps = ResourceFindingsResult; | ||
|
||
const columns = getFindingsColumns(); | ||
|
||
const ResourceFindingsTableComponent = ({ error, data, loading }: FindingsGroupByResourceProps) => { | ||
if (!loading && !data?.page.length) | ||
return <EuiEmptyPrompt iconType="logoKibana" title={<h2>{TEXT.NO_FINDINGS}</h2>} />; | ||
|
||
return ( | ||
<EuiBasicTable | ||
loading={loading} | ||
error={error ? extractErrorMessage(error) : undefined} | ||
items={data?.page || []} | ||
columns={columns} | ||
/> | ||
); | ||
}; | ||
|
||
export const ResourceFindingsTable = React.memo(ResourceFindingsTableComponent); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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 { useQuery } from 'react-query'; | ||
import { lastValueFrom } from 'rxjs'; | ||
import { IEsSearchResponse } from '@kbn/data-plugin/common'; | ||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import { useKibana } from '../../../../common/hooks/use_kibana'; | ||
import { showErrorToast } from '../../latest_findings/use_latest_findings'; | ||
import type { CspFinding, FindingsBaseEsQuery, FindingsQueryResult } from '../../types'; | ||
|
||
interface UseResourceFindingsOptions extends FindingsBaseEsQuery { | ||
resourceId: string; | ||
} | ||
|
||
export type ResourceFindingsResult = FindingsQueryResult< | ||
ReturnType<typeof useResourceFindings>['data'] | undefined, | ||
unknown | ||
>; | ||
|
||
export const getResourceFindingsQuery = ({ | ||
index, | ||
query, | ||
resourceId, | ||
}: UseResourceFindingsOptions): estypes.SearchRequest => ({ | ||
index, | ||
body: { | ||
query: { | ||
...query, | ||
bool: { | ||
...query?.bool, | ||
filter: [...(query?.bool?.filter || []), { term: { 'resource_id.keyword': resourceId } }], | ||
}, | ||
}, | ||
}, | ||
Comment on lines
+31
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is where we say this query is limited to a might change this later to just be |
||
}); | ||
|
||
export const useResourceFindings = ({ index, query, resourceId }: UseResourceFindingsOptions) => { | ||
const { | ||
data, | ||
notifications: { toasts }, | ||
} = useKibana().services; | ||
|
||
return useQuery( | ||
['csp_resource_findings', { index, query, resourceId }], | ||
() => | ||
lastValueFrom<IEsSearchResponse<CspFinding>>( | ||
data.search.search({ | ||
params: getResourceFindingsQuery({ index, query, resourceId }), | ||
}) | ||
), | ||
{ | ||
select: ({ rawResponse: { hits } }) => ({ | ||
page: hits.hits.map((hit) => hit._source!), | ||
total: hits.total as number, | ||
}), | ||
onError: (err) => showErrorToast(toasts, err), | ||
} | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,20 @@ | |
* 2.0. | ||
*/ | ||
import React from 'react'; | ||
import { EuiSpacer, EuiTitle, useEuiTheme } from '@elastic/eui'; | ||
import { | ||
EuiBasicTableColumn, | ||
EuiSpacer, | ||
EuiTableActionsColumnType, | ||
EuiTitle, | ||
EuiToolTip, | ||
PropsOf, | ||
useEuiTheme, | ||
} from '@elastic/eui'; | ||
import { css } from '@emotion/react'; | ||
import moment from 'moment'; | ||
import { CspEvaluationBadge } from '../../../components/csp_evaluation_badge'; | ||
import * as TEXT from '../translations'; | ||
import { CspFinding } from '../types'; | ||
|
||
export const PageWrapper: React.FC = ({ children }) => { | ||
const { euiTheme } = useEuiTheme(); | ||
|
@@ -31,3 +43,72 @@ export const PageTitle: React.FC = ({ children }) => ( | |
); | ||
|
||
export const PageTitleText = ({ title }: { title: React.ReactNode }) => <h2>{title}</h2>; | ||
|
||
export const getExpandColumn = <T extends unknown>({ | ||
onClick, | ||
}: { | ||
onClick(item: T): void; | ||
}): EuiTableActionsColumnType<T> => ({ | ||
width: '40px', | ||
actions: [ | ||
{ | ||
name: 'Expand', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be localized (both name and description) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think it's OK to merge as is and fix this in the next PR which is rebased on this one, and i'd like to rebase it on upstream There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
description: 'Expand', | ||
type: 'icon', | ||
icon: 'expand', | ||
onClick, | ||
}, | ||
], | ||
}); | ||
|
||
export const getFindingsColumns = (): Array<EuiBasicTableColumn<CspFinding>> => [ | ||
{ | ||
field: 'resource_id', | ||
name: TEXT.RESOURCE_ID, | ||
truncateText: true, | ||
width: '15%', | ||
sortable: true, | ||
render: (filename: string) => ( | ||
<EuiToolTip position="top" content={filename}> | ||
<span>{filename}</span> | ||
</EuiToolTip> | ||
), | ||
}, | ||
{ | ||
field: 'result.evaluation', | ||
name: TEXT.RESULT, | ||
width: '100px', | ||
sortable: true, | ||
render: (type: PropsOf<typeof CspEvaluationBadge>['type']) => ( | ||
<CspEvaluationBadge type={type} /> | ||
), | ||
}, | ||
{ | ||
field: 'rule.name', | ||
name: TEXT.RULE, | ||
sortable: true, | ||
}, | ||
{ | ||
field: 'cluster_id', | ||
name: TEXT.CLUSTER_ID, | ||
truncateText: true, | ||
sortable: true, | ||
}, | ||
{ | ||
field: 'rule.section', | ||
name: TEXT.CIS_SECTION, | ||
sortable: true, | ||
truncateText: true, | ||
}, | ||
{ | ||
field: '@timestamp', | ||
name: TEXT.LAST_CHECKED, | ||
truncateText: true, | ||
sortable: true, | ||
render: (timestamp: number) => ( | ||
<EuiToolTip position="top" content={timestamp}> | ||
<span>{moment(timestamp).fromNow()}</span> | ||
</EuiToolTip> | ||
), | ||
}, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed because columns are partially shared (for now) between
group-by-none
andresource-findings