-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'securitySolution/noteLimitAdvancedSetting' of https://g…
…ithub.com/janmonschke/kibana into securitySolution/noteLimitAdvancedSetting
- Loading branch information
Showing
57 changed files
with
1,494 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
x-pack/packages/kbn-cloud-security-posture/src/hooks/use_vulnerabilities_findings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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 '@tanstack/react-query'; | ||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import { lastValueFrom } from 'rxjs'; | ||
import type { IKibanaSearchResponse, IKibanaSearchRequest } from '@kbn/search-types'; | ||
import { | ||
SearchRequest, | ||
SearchResponse, | ||
AggregationsMultiBucketAggregateBase, | ||
AggregationsStringRareTermsBucketKeys, | ||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import type { CspVulnerabilityFinding } from '@kbn/cloud-security-posture-common/schema/vulnerabilities/latest'; | ||
import type { CoreStart } from '@kbn/core/public'; | ||
import type { CspClientPluginStartDeps, UseCspOptions } from '../../type'; | ||
import { showErrorToast } from '../..'; | ||
import { getVulnerabilitiesAggregationCount, getVulnerabilitiesQuery } from '../utils/hooks_utils'; | ||
|
||
type LatestFindingsRequest = IKibanaSearchRequest<SearchRequest>; | ||
type LatestFindingsResponse = IKibanaSearchResponse< | ||
SearchResponse<CspVulnerabilityFinding, FindingsAggs> | ||
>; | ||
|
||
interface FindingsAggs { | ||
count: AggregationsMultiBucketAggregateBase<AggregationsStringRareTermsBucketKeys>; | ||
} | ||
|
||
export const useVulnerabilitiesFindings = (options: UseCspOptions) => { | ||
const { | ||
data, | ||
notifications: { toasts }, | ||
} = useKibana<CoreStart & CspClientPluginStartDeps>().services; | ||
/** | ||
* We're using useInfiniteQuery in this case to allow the user to fetch more data (if available and up to 10k) | ||
* useInfiniteQuery differs from useQuery because it accumulates and caches a chunk of data from the previous fetches into an array | ||
* it uses the getNextPageParam to know if there are more pages to load and retrieve the position of | ||
* the last loaded record to be used as a from parameter to fetch the next chunk of data. | ||
*/ | ||
return useQuery( | ||
['csp_vulnerabilities_findings', { params: options }], | ||
async ({ pageParam }) => { | ||
const { | ||
rawResponse: { aggregations, hits }, | ||
} = await lastValueFrom( | ||
data.search.search<LatestFindingsRequest, LatestFindingsResponse>({ | ||
params: getVulnerabilitiesQuery(options, pageParam), | ||
}) | ||
); | ||
|
||
return { | ||
count: getVulnerabilitiesAggregationCount(aggregations?.count?.buckets), | ||
rows: hits.hits.map((finding) => ({ | ||
vulnerability: finding._source?.vulnerability, | ||
resource: finding._source?.resource, | ||
})) as Array<Pick<CspVulnerabilityFinding, 'vulnerability' | 'resource'>>, | ||
}; | ||
}, | ||
{ | ||
keepPreviousData: true, | ||
enabled: options.enabled, | ||
onError: (err: Error) => showErrorToast(toasts, err), | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
x-pack/packages/kbn-cloud-security-posture/src/utils/vulnerability_helpers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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 { euiThemeVars } from '@kbn/ui-theme'; | ||
import { getVulnerabilityStats } from './vulnerability_helpers'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
describe('getVulnerabilitiesAggregationCount', () => { | ||
it('should return empty array when all severity count is 0', () => { | ||
const result = getVulnerabilityStats({ critical: 0, high: 0, medium: 0, low: 0, none: 0 }); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should return stats for low, medium, high, and critical vulnerabilities', () => { | ||
const result = getVulnerabilityStats({ critical: 1, high: 2, medium: 3, low: 4, none: 5 }); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
key: i18n.translate( | ||
'xpack.securitySolution.flyout.right.insights.vulnerabilities.noneVulnerabilitiesText', | ||
{ | ||
defaultMessage: 'None', | ||
} | ||
), | ||
count: 5, | ||
color: '#aaa', | ||
}, | ||
{ | ||
key: i18n.translate( | ||
'xpack.securitySolution.flyout.right.insights.vulnerabilities.lowVulnerabilitiesText', | ||
{ | ||
defaultMessage: 'Low', | ||
} | ||
), | ||
count: 4, | ||
color: euiThemeVars.euiColorVis0, | ||
}, | ||
{ | ||
key: i18n.translate( | ||
'xpack.securitySolution.flyout.right.insights.vulnerabilities.mediumVulnerabilitiesText', | ||
{ | ||
defaultMessage: 'Medium', | ||
} | ||
), | ||
count: 3, | ||
color: euiThemeVars.euiColorVis5_behindText, | ||
}, | ||
{ | ||
key: i18n.translate( | ||
'xpack.securitySolution.flyout.right.insights.vulnerabilities.highVulnerabilitiesText', | ||
{ | ||
defaultMessage: 'High', | ||
} | ||
), | ||
count: 2, | ||
color: euiThemeVars.euiColorVis9_behindText, | ||
}, | ||
{ | ||
key: i18n.translate( | ||
'xpack.securitySolution.flyout.right.insights.vulnerabilities.CriticalVulnerabilitiesText', | ||
{ | ||
defaultMessage: 'Critical', | ||
} | ||
), | ||
count: 1, | ||
color: euiThemeVars.euiColorDanger, | ||
}, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.