From cbfab6dc979afa2e38266c8396fd72fa034ab6da Mon Sep 17 00:00:00 2001 From: Ido Cohen <90558359+CohenIdo@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:17:59 +0200 Subject: [PATCH] rename common/types to common/types_old --- .../public/pages/rules/rules_container.tsx | 3 +- .../find/find.test.ts} | 2 +- .../find/find.ts} | 35 ---------------- .../{rules => benchmark_rules}/find/v1.ts | 42 +++++++++++++++---- .../server/routes/setup_routes.ts | 2 +- .../apis/cloud_security_posture/benchmark.ts | 2 +- .../apis/cloud_security_posture/helper.ts | 2 +- .../status/status_index_timeout.ts | 2 +- .../status/status_indexed.ts | 2 +- .../status/status_indexing.ts | 2 +- .../status_not_deployed_not_installed.ts | 2 +- .../status/status_unprivileged.ts | 2 +- .../status/status_waiting_for_results.ts | 2 +- .../cloud_security_posture/benchmark.ts | 2 +- .../find_csp_benchmark_rule.ts | 3 +- .../status/status_indexed.ts | 2 +- .../status/status_indexing.ts | 2 +- .../status_not_deployed_not_installed.ts | 2 +- 18 files changed, 52 insertions(+), 59 deletions(-) rename x-pack/plugins/cloud_security_posture/server/routes/{rules/find/find_csp_benchmark_rule.test.ts => benchmark_rules/find/find.test.ts} (97%) rename x-pack/plugins/cloud_security_posture/server/routes/{rules/find/find_csp_benchmark_rule.ts => benchmark_rules/find/find.ts} (58%) rename x-pack/plugins/cloud_security_posture/server/routes/{rules => benchmark_rules}/find/v1.ts (62%) diff --git a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_container.tsx b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_container.tsx index 3998b5ff51958..5ec1971b1f0ac 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_container.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_container.tsx @@ -7,7 +7,6 @@ import React, { useState, useMemo } from 'react'; import { EuiPanel, EuiSpacer } from '@elastic/eui'; import { useParams } from 'react-router-dom'; -import { CspBenchmarkRule } from '../../../common/types/latest'; import { extractErrorMessage } from '../../../common/utils/helpers'; import { RulesTable } from './rules_table'; import { RulesTableHeader } from './rules_table_header'; @@ -20,7 +19,7 @@ import * as TEST_SUBJECTS from './test_subjects'; import { RuleFlyout } from './rules_flyout'; import { LOCAL_STORAGE_PAGE_SIZE_RULES_KEY } from '../../common/constants'; import { usePageSize } from '../../common/hooks/use_page_size'; - +import type { CspBenchmarkRule } from '../../../common/types/latest'; interface RulesPageData { rules_page: CspBenchmarkRule[]; all_rules: CspBenchmarkRule[]; diff --git a/x-pack/plugins/cloud_security_posture/server/routes/rules/find/find_csp_benchmark_rule.test.ts b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/find/find.test.ts similarity index 97% rename from x-pack/plugins/cloud_security_posture/server/routes/rules/find/find_csp_benchmark_rule.test.ts rename to x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/find/find.test.ts index 3c836c48c6910..ffec7d5b9b261 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/rules/find/find_csp_benchmark_rule.test.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/find/find.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { getSortedCspBenchmarkRulesTemplates } from './find_csp_benchmark_rule'; +import { getSortedCspBenchmarkRulesTemplates } from './v1'; import { CspBenchmarkRule } from '../../../../common/types/latest'; describe('getSortedCspBenchmarkRules', () => { diff --git a/x-pack/plugins/cloud_security_posture/server/routes/rules/find/find_csp_benchmark_rule.ts b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/find/find.ts similarity index 58% rename from x-pack/plugins/cloud_security_posture/server/routes/rules/find/find_csp_benchmark_rule.ts rename to x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/find/find.ts index 75e0ced19693d..aa4856fd9bada 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/rules/find/find_csp_benchmark_rule.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/find/find.ts @@ -4,52 +4,17 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - -import { NewPackagePolicy } from '@kbn/fleet-plugin/common'; -import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import { transformError } from '@kbn/securitysolution-es-utils'; -import semverCompare from 'semver/functions/compare'; -import semverValid from 'semver/functions/valid'; import { - CspBenchmarkRule, FindCspBenchmarkRuleRequest, FindCspBenchmarkRuleResponse, findCspBenchmarkRuleRequestSchema, } from '../../../../common/types/latest'; -import { getBenchmarkFromPackagePolicy } from '../../../../common/utils/helpers'; import { FIND_CSP_BENCHMARK_RULE_ROUTE_PATH } from '../../../../common/constants'; import { CspRouter } from '../../../types'; -import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../benchmarks/benchmarks'; import { findRuleHandler as findRuleHandlerV1 } from './v1'; -export const getSortedCspBenchmarkRulesTemplates = (cspBenchmarkRules: CspBenchmarkRule[]) => { - return cspBenchmarkRules.slice().sort((a, b) => { - const ruleNumberA = a?.metadata?.benchmark?.rule_number; - const ruleNumberB = b?.metadata?.benchmark?.rule_number; - - const versionA = semverValid(ruleNumberA); - const versionB = semverValid(ruleNumberB); - - if (versionA !== null && versionB !== null) { - return semverCompare(versionA, versionB); - } else { - return String(ruleNumberA).localeCompare(String(ruleNumberB)); - } - }); -}; - -export const getBenchmarkIdFromPackagePolicyId = async ( - soClient: SavedObjectsClientContract, - packagePolicyId: string -): Promise => { - const res = await soClient.get( - PACKAGE_POLICY_SAVED_OBJECT_TYPE, - packagePolicyId - ); - return getBenchmarkFromPackagePolicy(res.attributes.inputs); -}; - export const defineFindCspBenchmarkRuleRoute = (router: CspRouter) => router.versioned .get({ diff --git a/x-pack/plugins/cloud_security_posture/server/routes/rules/find/v1.ts b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/find/v1.ts similarity index 62% rename from x-pack/plugins/cloud_security_posture/server/routes/rules/find/v1.ts rename to x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/find/v1.ts index c4527f14a88e1..6bd0d14a2f540 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/rules/find/v1.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/benchmark_rules/find/v1.ts @@ -4,19 +4,47 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - +import semverValid from 'semver/functions/valid'; +import semverCompare from 'semver/functions/compare'; +import { NewPackagePolicy } from '@kbn/fleet-plugin/common'; import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; +import { getBenchmarkFilter } from '../../../../common/utils/helpers'; +import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '../../../../common/constants'; +import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../benchmarks/benchmarks'; +import { getBenchmarkFromPackagePolicy } from '../../../../common/utils/helpers'; + import type { CspBenchmarkRule, FindCspBenchmarkRuleRequest, FindCspBenchmarkRuleResponse, } from '../../../../common/types/latest'; -import { - getBenchmarkIdFromPackagePolicyId, - getSortedCspBenchmarkRulesTemplates, -} from './find_csp_benchmark_rule'; -import { getBenchmarkFilter } from '../../../../common/utils/helpers'; -import { CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE } from '../../../../common/constants'; + +export const getSortedCspBenchmarkRulesTemplates = (cspBenchmarkRules: CspBenchmarkRule[]) => { + return cspBenchmarkRules.slice().sort((a, b) => { + const ruleNumberA = a?.metadata?.benchmark?.rule_number; + const ruleNumberB = b?.metadata?.benchmark?.rule_number; + + const versionA = semverValid(ruleNumberA); + const versionB = semverValid(ruleNumberB); + + if (versionA !== null && versionB !== null) { + return semverCompare(versionA, versionB); + } else { + return String(ruleNumberA).localeCompare(String(ruleNumberB)); + } + }); +}; + +export const getBenchmarkIdFromPackagePolicyId = async ( + soClient: SavedObjectsClientContract, + packagePolicyId: string +): Promise => { + const res = await soClient.get( + PACKAGE_POLICY_SAVED_OBJECT_TYPE, + packagePolicyId + ); + return getBenchmarkFromPackagePolicy(res.attributes.inputs); +}; export const findRuleHandler = async ( soClient: SavedObjectsClientContract, diff --git a/x-pack/plugins/cloud_security_posture/server/routes/setup_routes.ts b/x-pack/plugins/cloud_security_posture/server/routes/setup_routes.ts index 04ec884c81b17..49022dd1f5fe6 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/setup_routes.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/setup_routes.ts @@ -17,7 +17,7 @@ import { defineGetComplianceDashboardRoute } from './compliance_dashboard/compli import { defineGetVulnerabilitiesDashboardRoute } from './vulnerabilities_dashboard/vulnerabilities_dashboard'; import { defineGetBenchmarksRoute } from './benchmarks/benchmarks'; import { defineGetCspStatusRoute } from './status/status'; -import { defineFindCspBenchmarkRuleRoute } from './rules/find/find_csp_benchmark_rule'; +import { defineFindCspBenchmarkRuleRoute } from './benchmark_rules/find/find'; import { defineGetDetectionEngineAlertsStatus } from './detection_engine/get_detection_engine_alerts_count_by_rule_tags'; /** diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/benchmark.ts b/x-pack/test/api_integration/apis/cloud_security_posture/benchmark.ts index f8735da12c9e4..ccaa3940258ec 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/benchmark.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/benchmark.ts @@ -5,7 +5,7 @@ * 2.0. */ import expect from '@kbn/expect'; -import type { GetBenchmarkResponse } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { GetBenchmarkResponse } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { FtrProviderContext } from '../../ftr_provider_context'; import { createPackagePolicy } from './helper'; diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts b/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts index 434d3fd308974..de9fdfe9952ea 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts @@ -9,7 +9,7 @@ import type { SuperTest, Test } from 'supertest'; import { Client } from '@elastic/elasticsearch'; import expect from '@kbn/expect'; import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; -import type { IndexDetails } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { IndexDetails } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { SecurityService } from '../../../../../test/common/services/security/security'; export const deleteIndex = (es: Client, indexToBeDeleted: string[]) => { diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts index 46cd700c7964c..3eda0f6a7b01a 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts @@ -5,7 +5,7 @@ * 2.0. */ import expect from '@kbn/expect'; -import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { FINDINGS_INDEX_DEFAULT_NS, diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts index 0ba63bd6d436e..6ba3fbe5c31ef 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; -import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { FINDINGS_INDEX_DEFAULT_NS, LATEST_FINDINGS_INDEX_DEFAULT_NS, diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts index 216f5aee17627..f55f5533718ed 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; -import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { FINDINGS_INDEX_DEFAULT_NS, LATEST_FINDINGS_INDEX_DEFAULT_NS, diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts index c991311922758..f67e2d5a0814b 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts @@ -5,7 +5,7 @@ * 2.0. */ import expect from '@kbn/expect'; -import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { FtrProviderContext } from '../../../ftr_provider_context'; import { createPackagePolicy } from '../helper'; diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts index 06f80adf46034..e80e80c322568 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; -import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { BENCHMARK_SCORE_INDEX_DEFAULT_NS, LATEST_FINDINGS_INDEX_DEFAULT_NS, diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts index dce7e655c0e67..a148f160bfd81 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; -import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { setupFleetAndAgents } from '../../../../fleet_api_integration/apis/agents/services'; import { generateAgent } from '../../../../fleet_api_integration/helpers'; import { FtrProviderContext } from '../../../ftr_provider_context'; diff --git a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/benchmark.ts b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/benchmark.ts index 53802db8caf3d..f67febd8e4a13 100644 --- a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/benchmark.ts +++ b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/benchmark.ts @@ -5,7 +5,7 @@ * 2.0. */ import expect from '@kbn/expect'; -import type { GetBenchmarkResponse } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { GetBenchmarkResponse } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { ELASTIC_HTTP_VERSION_HEADER, X_ELASTIC_INTERNAL_ORIGIN_REQUEST, diff --git a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/find_csp_benchmark_rule.ts b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/find_csp_benchmark_rule.ts index 72edcefc3853f..8209e9965a9a2 100644 --- a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/find_csp_benchmark_rule.ts +++ b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/find_csp_benchmark_rule.ts @@ -15,13 +15,14 @@ import type { } from '@kbn/cloud-security-posture-plugin/common/types/latest'; import { FtrProviderContext } from '../../../ftr_provider_context'; -import { createPackagePolicy } from '../../../apis/cloud_security_posture/helper'; +import { createPackagePolicy } from '../../../../../test/api_integration/apis/cloud_security_posture/helper'; // eslint-disable-line @kbn/imports/no_boundary_crossing export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const esArchiver = getService('esArchiver'); const kibanaServer = getService('kibanaServer'); + // find csp benchmark rule tests describe('GET internal/cloud_security_posture/rules/_find', function () { // security_exception: action [indices:admin/create] is unauthorized for user [elastic] with effective roles [superuser] on restricted indices [.fleet-actions-7], this action is granted by the index privileges [create_index,manage,all] this.tags(['failsOnMKI']); diff --git a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_indexed.ts b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_indexed.ts index ace5eef6a5499..ec3216971ec35 100644 --- a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_indexed.ts +++ b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_indexed.ts @@ -9,7 +9,7 @@ import { ELASTIC_HTTP_VERSION_HEADER, X_ELASTIC_INTERNAL_ORIGIN_REQUEST, } from '@kbn/core-http-common'; -import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { FINDINGS_INDEX_DEFAULT_NS, LATEST_FINDINGS_INDEX_DEFAULT_NS, diff --git a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_indexing.ts b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_indexing.ts index 316fb54f829c6..17e1e6458edaa 100644 --- a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_indexing.ts +++ b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_indexing.ts @@ -9,7 +9,7 @@ import { ELASTIC_HTTP_VERSION_HEADER, X_ELASTIC_INTERNAL_ORIGIN_REQUEST, } from '@kbn/core-http-common'; -import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { FINDINGS_INDEX_DEFAULT_NS, LATEST_FINDINGS_INDEX_DEFAULT_NS, diff --git a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_not_deployed_not_installed.ts b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_not_deployed_not_installed.ts index ac516bc68434c..9dc25ca4a1133 100644 --- a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_not_deployed_not_installed.ts +++ b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/status/status_not_deployed_not_installed.ts @@ -5,7 +5,7 @@ * 2.0. */ import expect from '@kbn/expect'; -import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types'; +import type { CspSetupStatus } from '@kbn/cloud-security-posture-plugin/common/types_old'; import { ELASTIC_HTTP_VERSION_HEADER, X_ELASTIC_INTERNAL_ORIGIN_REQUEST,