"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.NoFindingsStates = void 0; var _react = _interopRequireDefault(require("react")); var _eui = require("@elastic/eui"); var _i18nReact = require("@kbn/i18n-react"); var _i18n = require("@kbn/i18n"); var _react2 = require("@emotion/react"); var _constants = require("../../common/constants"); var _full_size_centered_page = require("./full_size_centered_page"); var _use_csp_benchmark_integrations = require("../pages/benchmarks/use_csp_benchmark_integrations"); var _use_navigate_to_cis_integration_policies = require("../common/navigation/use_navigate_to_cis_integration_policies"); var _test_subjects = require("./test_subjects"); var _cloud_posture_page = require("./cloud_posture_page"); var _use_setup_status_api = require("../common/api/use_setup_status_api"); var _constants2 = require("../common/navigation/constants"); var _no_data_illustration = _interopRequireDefault(require("../assets/illustrations/no_data_illustration.svg")); var _use_csp_integration_link = require("../common/navigation/use_csp_integration_link"); var _constants3 = require("../common/constants"); /* * 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. */ const NotDeployed = () => { var _benchmarks$data, _benchmarks$data$item; // using an existing hook to get agent id and package policy id const benchmarks = (0, _use_csp_benchmark_integrations.useCspBenchmarkIntegrations)({ name: '', page: 1, perPage: 1, sortField: 'package_policy.name', sortOrder: 'asc' }); // the ids are not a must, but as long as we have them we can open the add agent flyout const firstBenchmark = (_benchmarks$data = benchmarks.data) === null || _benchmarks$data === void 0 ? void 0 : (_benchmarks$data$item = _benchmarks$data.items) === null || _benchmarks$data$item === void 0 ? void 0 : _benchmarks$data$item[0]; const integrationPoliciesLink = (0, _use_navigate_to_cis_integration_policies.useCISIntegrationPoliciesLink)({ addAgentToPolicyId: (firstBenchmark === null || firstBenchmark === void 0 ? void 0 : firstBenchmark.agent_policy.id) || '', integration: (firstBenchmark === null || firstBenchmark === void 0 ? void 0 : firstBenchmark.package_policy.id) || '' }); return /*#__PURE__*/_react.default.createElement(_eui.EuiEmptyPrompt, { "data-test-subj": _test_subjects.NO_FINDINGS_STATUS_TEST_SUBJ.NO_AGENTS_DEPLOYED, color: "plain", iconType: "fleetApp", title: /*#__PURE__*/_react.default.createElement("h2", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.noFindingsStates.noAgentsDeployed.noAgentsDeployedTitle", defaultMessage: "No Agents Installed" })), body: /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.noFindingsStates.noAgentsDeployed.noAgentsDeployedDescription", defaultMessage: "In order to begin detecting security misconfigurations, you'll need to deploy elastic-agent into the cloud account or Kubernetes cluster you want to monitor." })), actions: [/*#__PURE__*/_react.default.createElement(_eui.EuiButton, { fill: true, href: integrationPoliciesLink, isDisabled: !integrationPoliciesLink }, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.noFindingsStates.noAgentsDeployed.noAgentsDeployedButtonTitle", defaultMessage: "Install Agent" }))] }); }; const Indexing = () => /*#__PURE__*/_react.default.createElement(_eui.EuiEmptyPrompt, { "data-test-subj": _test_subjects.NO_FINDINGS_STATUS_TEST_SUBJ.INDEXING, color: "plain", icon: /*#__PURE__*/_react.default.createElement(_eui.EuiLoadingLogo, { logo: "logoSecurity", size: "xl" }), title: /*#__PURE__*/_react.default.createElement("h2", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.noFindingsStates.indexing.indexingButtonTitle", defaultMessage: "Posture evaluation underway" })), body: /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.noFindingsStates.indexing.indexingDescription", defaultMessage: "Waiting for data to be collected and indexed. Check back later to see your findings" })) }); const IndexTimeout = () => /*#__PURE__*/_react.default.createElement(_eui.EuiEmptyPrompt, { "data-test-subj": _test_subjects.NO_FINDINGS_STATUS_TEST_SUBJ.INDEX_TIMEOUT, color: "plain", icon: /*#__PURE__*/_react.default.createElement(_eui.EuiLoadingLogo, { logo: "logoSecurity", size: "xl" }), title: /*#__PURE__*/_react.default.createElement("h2", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.noFindingsStates.indexTimeout.indexTimeoutTitle", defaultMessage: "Waiting for Findings data" })), body: /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.noFindingsStates.indexTimeout.indexTimeoutDescription", defaultMessage: "Collecting findings is taking longer than expected. {docs}.", values: { docs: /*#__PURE__*/_react.default.createElement(_eui.EuiLink, { href: "https://ela.st/findings", target: "_blank" }, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.noFindingsStates.indexTimeout.indexTimeoutDocLink", defaultMessage: "Learn more" })) } })) }); const Unprivileged = ({ unprivilegedIndices }) => /*#__PURE__*/_react.default.createElement(_eui.EuiEmptyPrompt, { "data-test-subj": _test_subjects.NO_FINDINGS_STATUS_TEST_SUBJ.UNPRIVILEGED, color: "plain", icon: /*#__PURE__*/_react.default.createElement(_eui.EuiIcon, { type: "logoSecurity", size: "xl" }), title: /*#__PURE__*/_react.default.createElement("h2", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.noFindingsStates.unprivileged.unprivilegedTitle", defaultMessage: "Privileges required" })), body: /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.noFindingsStates.unprivileged.unprivilegedDescription", defaultMessage: "To view cloud posture data, you must update privileges. For more information, contact your Kibana administrator." })), footer: /*#__PURE__*/_react.default.createElement(_eui.EuiMarkdownFormat, { css: (0, _react2.css)` text-align: initial; `, children: _i18n.i18n.translate('xpack.csp.noFindingsStates.unprivileged.unprivilegedFooterMarkdown', { defaultMessage: 'Required Elasticsearch index privilege `read` for the following indices:' }) + unprivilegedIndices.map(idx => `\n- \`${idx}\``) }) }); const ConfigurationFindingsInstalledEmptyPrompt = ({ kspmIntegrationLink, cspmIntegrationLink }) => { return /*#__PURE__*/_react.default.createElement(_eui.EuiEmptyPrompt, { "data-test-subj": _cloud_posture_page.PACKAGE_NOT_INSTALLED_TEST_SUBJECT, icon: /*#__PURE__*/_react.default.createElement(_eui.EuiImage, { size: "fullWidth", src: _no_data_illustration.default, alt: "no-data-illustration" }), title: /*#__PURE__*/_react.default.createElement("h2", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.cloudPosturePage.packageNotInstalledRenderer.promptTitle", defaultMessage: "Detect security misconfigurations in your cloud infrastructure!" })), layout: "horizontal", color: "plain", body: /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.cloudPosturePage.packageNotInstalledRenderer.promptDescription", defaultMessage: "Detect and remediate potential configuration risks in your cloud infrastructure, like publicly accessible S3 buckets, with our Cloud and Kubernetes Security Posture Management solutions. {learnMore}", values: { learnMore: /*#__PURE__*/_react.default.createElement(_eui.EuiLink, { href: _constants2.cspIntegrationDocsNavigation.cspm.overviewPath, target: "_blank" }, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.cloudPosturePage.packageNotInstalledRenderer.learnMoreTitle", defaultMessage: "Learn more about Cloud Security Posture" })) } })), actions: /*#__PURE__*/_react.default.createElement(_eui.EuiFlexGroup, null, /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, { grow: false }, /*#__PURE__*/_react.default.createElement(_eui.EuiButton, { color: "primary", fill: true, href: cspmIntegrationLink, "data-test-subj": _test_subjects.CSPM_NOT_INSTALLED_ACTION_SUBJ }, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.cloudPosturePage.packageNotInstalledRenderer.addCspmIntegrationButtonTitle", defaultMessage: "Add CSPM Integration" }))), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, { grow: false }, /*#__PURE__*/_react.default.createElement(_eui.EuiButton, { color: "primary", fill: true, href: kspmIntegrationLink, "data-test-subj": _test_subjects.KSPM_NOT_INSTALLED_ACTION_SUBJ }, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.csp.cloudPosturePage.packageNotInstalledRenderer.addKspmIntegrationButtonTitle", defaultMessage: "Add KSPM Integration" })))) }); }; /** * This component will return the render states based on cloud posture setup status API * since 'not-installed' is being checked globally by CloudPosturePage and 'indexed' is the pass condition, those states won't be handled here * */ const NoFindingsStates = ({ posturetype }) => { var _getSetupStatus$data, _getSetupStatus$data$, _getSetupStatus$data2, _getSetupStatus$data3, _getSetupStatus$data4, _getSetupStatus$data5, _getSetupStatus$data6, _getSetupStatus$data7, _getSetupStatus$data8; const getSetupStatus = (0, _use_setup_status_api.useCspSetupStatusApi)({ refetchInterval: _constants3.NO_FINDINGS_STATUS_REFRESH_INTERVAL_MS }); const statusKspm = (_getSetupStatus$data = getSetupStatus.data) === null || _getSetupStatus$data === void 0 ? void 0 : (_getSetupStatus$data$ = _getSetupStatus$data.kspm) === null || _getSetupStatus$data$ === void 0 ? void 0 : _getSetupStatus$data$.status; const statusCspm = (_getSetupStatus$data2 = getSetupStatus.data) === null || _getSetupStatus$data2 === void 0 ? void 0 : (_getSetupStatus$data3 = _getSetupStatus$data2.cspm) === null || _getSetupStatus$data3 === void 0 ? void 0 : _getSetupStatus$data3.status; const indicesStatus = (_getSetupStatus$data4 = getSetupStatus.data) === null || _getSetupStatus$data4 === void 0 ? void 0 : _getSetupStatus$data4.indicesDetails; const status = posturetype === 'cspm' ? statusCspm : statusKspm; const showConfigurationInstallPrompt = ((_getSetupStatus$data5 = getSetupStatus.data) === null || _getSetupStatus$data5 === void 0 ? void 0 : (_getSetupStatus$data6 = _getSetupStatus$data5.kspm) === null || _getSetupStatus$data6 === void 0 ? void 0 : _getSetupStatus$data6.status) === 'not-installed' && ((_getSetupStatus$data7 = getSetupStatus.data) === null || _getSetupStatus$data7 === void 0 ? void 0 : (_getSetupStatus$data8 = _getSetupStatus$data7.cspm) === null || _getSetupStatus$data8 === void 0 ? void 0 : _getSetupStatus$data8.status) === 'not-installed'; const kspmIntegrationLink = (0, _use_csp_integration_link.useCspIntegrationLink)(_constants.KSPM_POLICY_TEMPLATE); const cspmIntegrationLink = (0, _use_csp_integration_link.useCspIntegrationLink)(_constants.CSPM_POLICY_TEMPLATE); const unprivilegedIndices = indicesStatus && indicesStatus.filter(idxDetails => idxDetails.status === 'unprivileged').map(idxDetails => idxDetails.index).sort((a, b) => a.localeCompare(b)); const render = () => { if (status === 'not-deployed') return /*#__PURE__*/_react.default.createElement(NotDeployed, null); // integration installed, but no agents added if (status === 'indexing' || status === 'waiting_for_results') return /*#__PURE__*/_react.default.createElement(Indexing, null); // agent added, index timeout hasn't passed since installation if (status === 'index-timeout') return /*#__PURE__*/_react.default.createElement(IndexTimeout, null); // agent added, index timeout has passed if (status === 'unprivileged') return /*#__PURE__*/_react.default.createElement(Unprivileged, { unprivilegedIndices: unprivilegedIndices || [] }); // user has no privileges for our indices if (showConfigurationInstallPrompt) return /*#__PURE__*/_react.default.createElement(ConfigurationFindingsInstalledEmptyPrompt, { kspmIntegrationLink: kspmIntegrationLink, cspmIntegrationLink: cspmIntegrationLink }); }; return /*#__PURE__*/_react.default.createElement(_cloud_posture_page.CloudPosturePage, { query: getSetupStatus }, /*#__PURE__*/_react.default.createElement(_full_size_centered_page.FullSizeCenteredPage, null, render())); }; exports.NoFindingsStates = NoFindingsStates;