Skip to content

Commit

Permalink
rename common/types to common/types_old
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenIdo committed Dec 7, 2023
1 parent f3fbc91 commit cbfab6d
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> => {
const res = await soClient.get<NewPackagePolicy>(
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
packagePolicyId
);
return getBenchmarkFromPackagePolicy(res.attributes.inputs);
};

export const defineFindCspBenchmarkRuleRoute = (router: CspRouter) =>
router.versioned
.get({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> => {
const res = await soClient.get<NewPackagePolicy>(
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
packagePolicyId
);
return getBenchmarkFromPackagePolicy(res.attributes.inputs);
};

export const findRuleHandler = async (
soClient: SavedObjectsClientContract,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cbfab6d

Please sign in to comment.