Skip to content

Commit

Permalink
code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenIdo committed Dec 6, 2023
1 parent ac2e27d commit 8cd05f0
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/cloud_security_posture/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/cloud_security_posture/common/types/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const cspRuleSchema = schema.object({

export type CspRule = TypeOf<typeof cspRuleSchema>;

export const findCspRuleRequest = schema.object({
export const findCspRuleRequestSchema = schema.object({
/**
* An Elasticsearch simple_query_string
*/
Expand Down Expand Up @@ -121,7 +121,7 @@ export const findCspRuleRequest = schema.object({
section: schema.maybe(schema.string()),
});

export type FindCspRuleRequest = TypeOf<typeof findCspRuleRequest>;
export type FindCspRuleRequest = TypeOf<typeof findCspRuleRequestSchema>;

export interface FindCspRuleResponse {
items: CspRule[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -61,7 +61,7 @@ export const defineFindCspRuleRoute = (router: CspRouter) =>
version: '1',
validate: {
request: {
query: findCspRuleRequest,
query: findCspRuleRequestSchema,
},
},
},
Expand All @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 8cd05f0

Please sign in to comment.