From 8cd05f0fa837f20a34c9e3331f05238cddeff6ba Mon Sep 17 00:00:00 2001 From: Ido Cohen <90558359+CohenIdo@users.noreply.github.com> Date: Wed, 6 Dec 2023 19:46:38 +0200 Subject: [PATCH] code review comments --- x-pack/plugins/cloud_security_posture/common/types.ts | 2 +- .../cloud_security_posture/common/types/index.ts | 3 +-- .../cloud_security_posture/common/types/rules/v2.ts | 2 +- .../cloud_security_posture/common/types/rules/v3.ts | 4 ++-- .../public/pages/rules/rules_container.test.tsx | 2 +- .../server/routes/rules/find/find_csp_rule.ts | 8 ++++---- .../server/routes/rules/find/v1.ts | 10 +++++----- .../apis/cloud_security_posture/find_csp_rule.ts | 7 ++++--- .../security/cloud_security_posture/find_csp_rule.ts | 7 ++++--- 9 files changed, 23 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/cloud_security_posture/common/types.ts b/x-pack/plugins/cloud_security_posture/common/types.ts index a2186b51b384d..0d923eb3f5aa6 100644 --- a/x-pack/plugins/cloud_security_posture/common/types.ts +++ b/x-pack/plugins/cloud_security_posture/common/types.ts @@ -10,7 +10,7 @@ import { CspFinding } from './schemas/csp_finding'; import { SUPPORTED_CLOUDBEAT_INPUTS, SUPPORTED_POLICY_TEMPLATES } from './constants'; import { getComplianceDashboardSchema } from './schemas/stats'; -import { CspRuleMetadata } from './types/latest'; +import type { CspRuleMetadata } from './types/latest'; export type AwsCredentialsType = | 'assume_role' diff --git a/x-pack/plugins/cloud_security_posture/common/types/index.ts b/x-pack/plugins/cloud_security_posture/common/types/index.ts index 840ae6ad76e43..717b0a7ef734d 100644 --- a/x-pack/plugins/cloud_security_posture/common/types/index.ts +++ b/x-pack/plugins/cloud_security_posture/common/types/index.ts @@ -1,5 +1,3 @@ -// index.ts -// Explicit export of everything from latest /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License @@ -11,6 +9,7 @@ export * as rulesV1 from './rules/v1'; export * as rulesV2 from './rules/v2'; export * as rulesV3 from './rules/v3'; +// Explicit export of everything from latest export type { cspRuleMetadataSchema, CspRuleMetadata, diff --git a/x-pack/plugins/cloud_security_posture/common/types/rules/v2.ts b/x-pack/plugins/cloud_security_posture/common/types/rules/v2.ts index 78f3e09a26219..6ed9504423543 100644 --- a/x-pack/plugins/cloud_security_posture/common/types/rules/v2.ts +++ b/x-pack/plugins/cloud_security_posture/common/types/rules/v2.ts @@ -6,7 +6,7 @@ */ import { schema, TypeOf } from '@kbn/config-schema'; -// Since version 8.4.0 //TODO: rename V840 +// Since version 8.4.0 export const cspRuleMetadataSchema = schema.object({ audit: schema.string(), benchmark: schema.object({ diff --git a/x-pack/plugins/cloud_security_posture/common/types/rules/v3.ts b/x-pack/plugins/cloud_security_posture/common/types/rules/v3.ts index 3cba40fc96757..2a12ebe092233 100644 --- a/x-pack/plugins/cloud_security_posture/common/types/rules/v3.ts +++ b/x-pack/plugins/cloud_security_posture/common/types/rules/v3.ts @@ -46,7 +46,7 @@ export const cspRuleSchema = schema.object({ export type CspRule = TypeOf; -export const findCspRuleRequest = schema.object({ +export const findCspRuleRequestSchema = schema.object({ /** * An Elasticsearch simple_query_string */ @@ -121,7 +121,7 @@ export const findCspRuleRequest = schema.object({ section: schema.maybe(schema.string()), }); -export type FindCspRuleRequest = TypeOf; +export type FindCspRuleRequest = TypeOf; export interface FindCspRuleResponse { items: CspRule[]; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_container.test.tsx b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_container.test.tsx index 3711a967aab61..6025f61975fa0 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_container.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/rules/rules_container.test.tsx @@ -15,7 +15,7 @@ import { Chance } from 'chance'; import { TestProvider } from '../../test/test_provider'; import { useParams } from 'react-router-dom'; import { coreMock } from '@kbn/core/public/mocks'; -import { CspRule } from '@kbn/cloud-security-posture-plugin/common/types/latest'; +import type { CspRule } from '@kbn/cloud-security-posture-plugin/common/types/latest'; const chance = new Chance(); diff --git a/x-pack/plugins/cloud_security_posture/server/routes/rules/find/find_csp_rule.ts b/x-pack/plugins/cloud_security_posture/server/routes/rules/find/find_csp_rule.ts index e8e3d2ec2a1c9..3281f8cb1a0f0 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/rules/find/find_csp_rule.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/rules/find/find_csp_rule.ts @@ -14,14 +14,14 @@ import { CspRule, FindCspRuleRequest, FindCspRuleResponse, - findCspRuleRequest, + findCspRuleRequestSchema, } from '@kbn/cloud-security-posture-plugin/common/types/latest'; import { getBenchmarkFromPackagePolicy } from '../../../../common/utils/helpers'; import { FIND_CSP_RULE_ROUTE_PATH } from '../../../../common/constants'; import { CspRouter } from '../../../types'; import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../benchmarks/benchmarks'; -import { findRuleHandler } from './v1'; +import { findRuleHandler as findRuleHandlerV1 } from './v1'; export const getSortedCspRulesTemplates = (cspRulesTemplates: CspRule[]) => { return cspRulesTemplates.slice().sort((a, b) => { @@ -61,7 +61,7 @@ export const defineFindCspRuleRoute = (router: CspRouter) => version: '1', validate: { request: { - query: findCspRuleRequest, + query: findCspRuleRequestSchema, }, }, }, @@ -74,7 +74,7 @@ export const defineFindCspRuleRoute = (router: CspRouter) => const cspContext = await context.csp; try { - const cspRulesTemplates: FindCspRuleResponse = await findRuleHandler( + const cspRulesTemplates: FindCspRuleResponse = await findRuleHandlerV1( cspContext.soClient, requestBody ); diff --git a/x-pack/plugins/cloud_security_posture/server/routes/rules/find/v1.ts b/x-pack/plugins/cloud_security_posture/server/routes/rules/find/v1.ts index 0d305072b1946..743bb67a6c99b 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/rules/find/v1.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/rules/find/v1.ts @@ -6,15 +6,15 @@ */ import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; -import { +import { getBenchmarkFilter } from '../../../../common/utils/helpers'; +import { CSP_RULE_SAVED_OBJECT_TYPE } from '../../../../common/constants'; +import { getBenchmarkIdFromPackagePolicyId, getSortedCspRulesTemplates } from './find_csp_rule'; + +import type { CspRule, FindCspRuleRequest, FindCspRuleResponse, } from '@kbn/cloud-security-posture-plugin/common/types/latest'; -import { getBenchmarkFilter } from '../../../../common/utils/helpers'; - -import { CSP_RULE_SAVED_OBJECT_TYPE } from '../../../../common/constants'; -import { getBenchmarkIdFromPackagePolicyId, getSortedCspRulesTemplates } from './find_csp_rule'; export const findRuleHandler = async ( soClient: SavedObjectsClientContract, diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/find_csp_rule.ts b/x-pack/test/api_integration/apis/cloud_security_posture/find_csp_rule.ts index f84b81573321a..561f1597766aa 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/find_csp_rule.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/find_csp_rule.ts @@ -6,12 +6,13 @@ */ import expect from '@kbn/expect'; import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; -import { +import { FtrProviderContext } from '../../ftr_provider_context'; +import { createPackagePolicy } from './helper'; + +import type { CspRule, FindCspRuleResponse, } from '@kbn/cloud-security-posture-plugin/common/types/latest'; -import { FtrProviderContext } from '../../ftr_provider_context'; -import { createPackagePolicy } from './helper'; export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); diff --git a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/find_csp_rule.ts b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/find_csp_rule.ts index 050b1c6b1dadc..d1ab684546fa8 100644 --- a/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/find_csp_rule.ts +++ b/x-pack/test_serverless/api_integration/test_suites/security/cloud_security_posture/find_csp_rule.ts @@ -9,12 +9,13 @@ import { ELASTIC_HTTP_VERSION_HEADER, X_ELASTIC_INTERNAL_ORIGIN_REQUEST, } from '@kbn/core-http-common'; -import { +import { FtrProviderContext } from '../../../ftr_provider_context'; +import { createPackagePolicy } from '../../../apis/cloud_security_posture/helper'; // eslint-disable-line @kbn/imports/no_boundary_crossing + +import type { CspRule, FindCspRuleResponse, } from '@kbn/cloud-security-posture-plugin/common/types/latest'; -import { FtrProviderContext } from '../../../ftr_provider_context'; -import { createPackagePolicy } from '../../../apis/cloud_security_posture/helper'; // eslint-disable-line @kbn/imports/no_boundary_crossing export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest');