-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Cloud Security] Azure support for dashboard and flyout and PLG for dashboard #167422
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
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 |
|---|---|---|
|
|
@@ -5,13 +5,43 @@ | |
| * 2.0. | ||
| */ | ||
| import React from 'react'; | ||
| import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; | ||
| import { CIS_AWS, CIS_GCP } from '../../common/constants'; | ||
| import { EuiFlexGroup, EuiFlexItem, useEuiTheme } from '@elastic/eui'; | ||
| import { css } from '@emotion/react'; | ||
| import { CIS_AWS, CIS_GCP, CIS_AZURE, CIS_K8S, CIS_EKS } from '../../common/constants'; | ||
| import { Cluster } from '../../common/types'; | ||
| import { CISBenchmarkIcon } from './cis_benchmark_icon'; | ||
| import { CompactFormattedNumber } from './compact_formatted_number'; | ||
| import { useNavigateFindings } from '../common/hooks/use_navigate_findings'; | ||
|
|
||
| // order in array will determine order of appearance in the dashboard | ||
| const benchmarks = [ | ||
| { | ||
| type: CIS_AWS, | ||
| name: 'Amazon Web Services (AWS)', | ||
| provider: 'aws', | ||
| }, | ||
| { | ||
| type: CIS_GCP, | ||
| name: 'Google Cloud Platform (GCP)', | ||
| provider: 'gcp', | ||
| }, | ||
| { | ||
| type: CIS_AZURE, | ||
| name: 'Azure', | ||
| provider: 'azure', | ||
| }, | ||
| { | ||
| type: CIS_K8S, | ||
| name: 'Kubernetes', | ||
| benchmarkId: 'cis_k8s', | ||
| }, | ||
| { | ||
| type: CIS_EKS, | ||
| name: 'Amazon Elastic Kubernetes Service (EKS)', | ||
| benchmarkId: 'cis_eks', | ||
| }, | ||
| ]; | ||
|
|
||
| export const AccountsEvaluatedWidget = ({ | ||
| clusters, | ||
| benchmarkAbbreviateAbove = 999, | ||
|
|
@@ -20,6 +50,8 @@ export const AccountsEvaluatedWidget = ({ | |
| /** numbers higher than the value of this field will be abbreviated using compact notation and have a tooltip displaying the full value */ | ||
| benchmarkAbbreviateAbove?: number; | ||
| }) => { | ||
| const { euiTheme } = useEuiTheme(); | ||
|
|
||
| const filterClustersById = (benchmarkId: string) => { | ||
| return clusters?.filter((obj) => obj?.meta.benchmark.id === benchmarkId) || []; | ||
| }; | ||
|
|
@@ -30,56 +62,52 @@ export const AccountsEvaluatedWidget = ({ | |
| navToFindings({ 'cloud.provider': provider }); | ||
| }; | ||
|
|
||
| const cisAwsClusterAmount = filterClustersById(CIS_AWS).length; | ||
| const cisGcpClusterAmount = filterClustersById(CIS_GCP).length; | ||
| const navToFindingsByCisBenchmark = (cisBenchmark: string) => { | ||
| navToFindings({ 'rule.benchmark.id': cisBenchmark }); | ||
| }; | ||
|
|
||
| const benchmarkElements = benchmarks.map((benchmark) => { | ||
| const clusterAmount = filterClustersById(benchmark.type).length; | ||
|
|
||
| return ( | ||
| clusterAmount > 0 && ( | ||
| <EuiFlexItem | ||
| key={benchmark.type} | ||
| onClick={() => { | ||
| if (benchmark.provider) { | ||
| navToFindingsByCloudProvider(benchmark.provider); | ||
| } | ||
| if (benchmark.benchmarkId) { | ||
| navToFindingsByCisBenchmark(benchmark.benchmarkId); | ||
| } | ||
| }} | ||
| css={css` | ||
| transition: ${euiTheme.animation.normal} ease-in; | ||
| border-bottom: ${euiTheme.border.thick}; | ||
| border-color: transparent; | ||
|
|
||
| const cisAwsBenchmarkName = 'Amazon Web Services (AWS)'; | ||
| const cisGcpBenchmarkName = 'Google Cloud Platform (GCP)'; | ||
| :hover { | ||
| cursor: pointer; | ||
| border-color: ${euiTheme.colors.darkestShade}; | ||
|
Comment on lines
+89
to
+91
Contributor
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. Nice addition! |
||
| } | ||
| `} | ||
| > | ||
| <EuiFlexGroup gutterSize="xs" alignItems="center"> | ||
| <EuiFlexItem> | ||
| <CISBenchmarkIcon type={benchmark.type} name={benchmark.name} size={'l'} /> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <CompactFormattedNumber | ||
| number={clusterAmount} | ||
| abbreviateAbove={benchmarkAbbreviateAbove} | ||
| /> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiFlexItem> | ||
| ) | ||
| ); | ||
| }); | ||
|
|
||
| return ( | ||
| <> | ||
| <EuiFlexGroup gutterSize="m"> | ||
| {cisAwsClusterAmount > 0 && ( | ||
| <EuiFlexItem grow={false}> | ||
| <EuiFlexGroup gutterSize="xs" alignItems="center"> | ||
| <EuiFlexItem> | ||
| <CISBenchmarkIcon type={CIS_AWS} name={cisAwsBenchmarkName} size={'l'} /> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem | ||
| grow={false} | ||
| onClick={() => { | ||
| navToFindingsByCloudProvider('aws'); | ||
| }} | ||
| > | ||
| <CompactFormattedNumber | ||
| number={cisAwsClusterAmount} | ||
| abbreviateAbove={benchmarkAbbreviateAbove} | ||
| /> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiFlexItem> | ||
| )} | ||
| {cisGcpClusterAmount > 0 && ( | ||
| <EuiFlexItem> | ||
| <EuiFlexGroup gutterSize="xs" alignItems="center"> | ||
| <EuiFlexItem> | ||
| <CISBenchmarkIcon type={CIS_GCP} name={cisGcpBenchmarkName} size={'l'} /> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem | ||
| grow={false} | ||
| onClick={() => { | ||
| navToFindingsByCloudProvider('gcp'); | ||
| }} | ||
| > | ||
| <CompactFormattedNumber | ||
| number={cisGcpClusterAmount} | ||
| abbreviateAbove={benchmarkAbbreviateAbove} | ||
| /> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiFlexItem> | ||
| )} | ||
| </EuiFlexGroup> | ||
| </> | ||
| ); | ||
| // Render the benchmark elements | ||
| return <EuiFlexGroup gutterSize="m">{benchmarkElements}</EuiFlexGroup>; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,10 +6,10 @@ | |
| */ | ||
|
|
||
| import React, { useMemo } from 'react'; | ||
| import { EuiFlexGroup, EuiFlexItem, EuiFlexItemProps } from '@elastic/eui'; | ||
| import { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiFlexItemProps } from '@elastic/eui'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { css } from '@emotion/react'; | ||
| import { statusColors } from '../../../common/constants'; | ||
| import { useCspIntegrationLink } from '../../../common/navigation/use_csp_integration_link'; | ||
| import { DASHBOARD_COUNTER_CARDS, DASHBOARD_SUMMARY_CONTAINER } from '../test_subjects'; | ||
| import { CspCounterCard, CspCounterCardProps } from '../../../components/csp_counter_card'; | ||
| import { CompactFormattedNumber } from '../../../components/compact_formatted_number'; | ||
|
|
@@ -56,6 +56,8 @@ export const SummarySection = ({ | |
| }) => { | ||
| const navToFindings = useNavigateFindings(); | ||
| const navToFindingsByResource = useNavigateFindingsByResource(); | ||
| const cspmIntegrationLink = useCspIntegrationLink(CSPM_POLICY_TEMPLATE); | ||
| const kspmIntegrationLink = useCspIntegrationLink(KSPM_POLICY_TEMPLATE); | ||
|
|
||
| const handleEvalCounterClick = (evaluation: Evaluation) => { | ||
| navToFindings({ 'result.evaluation': evaluation, ...getPolicyTemplateQuery(dashboardType) }); | ||
|
|
@@ -87,12 +89,26 @@ export const SummarySection = ({ | |
| 'xpack.csp.dashboard.summarySection.counterCard.accountsEvaluatedDescription', | ||
| { defaultMessage: 'Accounts Evaluated' } | ||
| ), | ||
| title: | ||
| dashboardType === KSPM_POLICY_TEMPLATE ? ( | ||
| <CompactFormattedNumber number={complianceData.clusters.length} /> | ||
| ) : ( | ||
| <AccountsEvaluatedWidget clusters={complianceData.clusters} /> | ||
| ), | ||
| title: <AccountsEvaluatedWidget clusters={complianceData.clusters} />, | ||
| button: ( | ||
| <EuiButtonEmpty | ||
| iconType="listAdd" | ||
| target="_blank" | ||
| href={ | ||
| dashboardType === KSPM_POLICY_TEMPLATE ? kspmIntegrationLink : cspmIntegrationLink | ||
| } | ||
| > | ||
| {dashboardType === KSPM_POLICY_TEMPLATE | ||
| ? i18n.translate( | ||
| 'xpack.csp.dashboard.summarySection.counterCard.clustersEvaluatedButtonTitle', | ||
| { defaultMessage: 'Enroll more clusters' } | ||
| ) | ||
| : i18n.translate( | ||
| 'xpack.csp.dashboard.summarySection.counterCard.accountsEvaluatedButtonTitle', | ||
| { defaultMessage: 'Enroll more accounts' } | ||
| )} | ||
| </EuiButtonEmpty> | ||
|
Comment on lines
+94
to
+110
Contributor
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. It feels this could be better if splitting into two buttons
Contributor
Author
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. yeah i agree but its pretty small so i prefer to just merge for now |
||
| ), | ||
| }, | ||
| { | ||
| id: DASHBOARD_COUNTER_CARDS.RESOURCES_EVALUATED, | ||
|
|
@@ -101,32 +117,27 @@ export const SummarySection = ({ | |
| { defaultMessage: 'Resources Evaluated' } | ||
| ), | ||
| title: <CompactFormattedNumber number={complianceData.stats.resourcesEvaluated || 0} />, | ||
| onClick: () => { | ||
| navToFindingsByResource(getPolicyTemplateQuery(dashboardType)); | ||
| }, | ||
| }, | ||
| { | ||
| id: DASHBOARD_COUNTER_CARDS.FAILING_FINDINGS, | ||
| description: i18n.translate( | ||
| 'xpack.csp.dashboard.summarySection.counterCard.failingFindingsDescription', | ||
| { defaultMessage: 'Failing Findings' } | ||
| button: ( | ||
| <EuiButtonEmpty | ||
| iconType="search" | ||
| onClick={() => { | ||
| navToFindingsByResource(getPolicyTemplateQuery(dashboardType)); | ||
| }} | ||
| > | ||
| {i18n.translate( | ||
| 'xpack.csp.dashboard.summarySection.counterCard.resourcesEvaluatedButtonTitle', | ||
| { defaultMessage: 'View all resources' } | ||
| )} | ||
| </EuiButtonEmpty> | ||
| ), | ||
| title: <CompactFormattedNumber number={complianceData.stats.totalFailed} />, | ||
| titleColor: complianceData.stats.totalFailed > 0 ? statusColors.failed : 'text', | ||
| onClick: () => { | ||
| navToFindings({ | ||
| 'result.evaluation': RULE_FAILED, | ||
| ...getPolicyTemplateQuery(dashboardType), | ||
| }); | ||
| }, | ||
| }, | ||
| ], | ||
| [ | ||
| complianceData.clusters, | ||
| complianceData.stats.resourcesEvaluated, | ||
| complianceData.stats.totalFailed, | ||
| cspmIntegrationLink, | ||
| dashboardType, | ||
| navToFindings, | ||
| kspmIntegrationLink, | ||
| navToFindingsByResource, | ||
| ] | ||
| ); | ||
|
|
||
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.
think it's a good candidate to wrap with
useMemo()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.
while possible, it also means wrapping all the hooks in usecallbacks and for such small component all those memos are not worth it in my opinion