mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Cloud Posture] refactoring - renaming types (#135328)
This commit is contained in:
parent
f8c1c71ff2
commit
d44189578b
17 changed files with 75 additions and 75 deletions
|
@ -8,7 +8,7 @@ import { type TypeOf, schema } from '@kbn/config-schema';
|
|||
|
||||
export const DEFAULT_BENCHMARKS_PER_PAGE = 20;
|
||||
export const BENCHMARK_PACKAGE_POLICY_PREFIX = 'package_policy.';
|
||||
export const benchmarksInputSchema = schema.object({
|
||||
export const benchmarksQueryParamsSchema = schema.object({
|
||||
/**
|
||||
* The page of objects to return
|
||||
*/
|
||||
|
@ -59,4 +59,4 @@ export const benchmarksInputSchema = schema.object({
|
|||
benchmark_name: schema.maybe(schema.string()),
|
||||
});
|
||||
|
||||
export type BenchmarksQuerySchema = TypeOf<typeof benchmarksInputSchema>;
|
||||
export type BenchmarksQueryParams = TypeOf<typeof benchmarksQueryParamsSchema>;
|
||||
|
|
|
@ -37,6 +37,6 @@ export const cspRuleSchemaV840 = rt.object({
|
|||
policy_id: rt.string(),
|
||||
});
|
||||
|
||||
export type CspRuleTypeV830 = TypeOf<typeof cspRuleSchemaV830>;
|
||||
export type CspRuleTypeV840 = TypeOf<typeof cspRuleSchemaV840>;
|
||||
export type CspRuleType = CspRuleTypeV840;
|
||||
export type CspRuleV830 = TypeOf<typeof cspRuleSchemaV830>;
|
||||
export type CspRuleV840 = TypeOf<typeof cspRuleSchemaV840>;
|
||||
export type CspRule = CspRuleV840;
|
||||
|
|
|
@ -24,4 +24,4 @@ export const cspRuleMetadataSchema = rt.object({
|
|||
version: rt.string(),
|
||||
});
|
||||
|
||||
export type CspRuleMetadataType = TypeOf<typeof cspRuleMetadataSchema>;
|
||||
export type CspRuleMetadata = TypeOf<typeof cspRuleMetadataSchema>;
|
||||
|
|
|
@ -33,6 +33,6 @@ export const cspRuleTemplateSchemaV840 = rt.object({
|
|||
muted: rt.boolean(),
|
||||
});
|
||||
|
||||
export type CspRuleTemplateTypeV830 = TypeOf<typeof cspRuleTemplateSchemaV830>;
|
||||
export type CspRuleTemplateTypeV840 = TypeOf<typeof cspRuleTemplateSchemaV840>;
|
||||
export type CspRuleTemplateType = CspRuleTemplateTypeV840;
|
||||
export type CspRuleTemplateV830 = TypeOf<typeof cspRuleTemplateSchemaV830>;
|
||||
export type CspRuleTemplateV840 = TypeOf<typeof cspRuleTemplateSchemaV840>;
|
||||
export type CspRuleTemplate = CspRuleTemplateV840;
|
||||
|
|
|
@ -15,4 +15,4 @@ export const cspRulesConfigSchema = rt.object({
|
|||
}),
|
||||
});
|
||||
|
||||
export type CspRulesConfigSchema = TypeOf<typeof cspRulesConfigSchema>;
|
||||
export type CspRulesConfiguration = TypeOf<typeof cspRulesConfigSchema>;
|
|
@ -8,4 +8,4 @@
|
|||
export * from './csp_rule';
|
||||
export * from './csp_rule_metadata';
|
||||
export * from './csp_rule_template';
|
||||
export * from './csp_configuration';
|
||||
export * from './csp_rules_configuration';
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { useQuery } from 'react-query';
|
||||
import type { ListResult } from '@kbn/fleet-plugin/common';
|
||||
import { BENCHMARKS_ROUTE_PATH } from '../../../common/constants';
|
||||
import type { BenchmarksQuerySchema } from '../../../common/schemas/benchmark';
|
||||
import type { BenchmarksQueryParams } from '../../../common/schemas/benchmark';
|
||||
import { useKibana } from '../../common/hooks/use_kibana';
|
||||
import type { Benchmark } from '../../../common/types';
|
||||
|
||||
|
@ -18,8 +18,8 @@ export interface UseCspBenchmarkIntegrationsProps {
|
|||
name: string;
|
||||
page: number;
|
||||
perPage: number;
|
||||
sortField: BenchmarksQuerySchema['sort_field'];
|
||||
sortOrder: BenchmarksQuerySchema['sort_order'];
|
||||
sortField: BenchmarksQueryParams['sort_field'];
|
||||
sortOrder: BenchmarksQueryParams['sort_order'];
|
||||
}
|
||||
|
||||
export const useCspBenchmarkIntegrations = ({
|
||||
|
@ -30,7 +30,7 @@ export const useCspBenchmarkIntegrations = ({
|
|||
sortOrder,
|
||||
}: UseCspBenchmarkIntegrationsProps) => {
|
||||
const { http } = useKibana().services;
|
||||
const query: BenchmarksQuerySchema = {
|
||||
const query: BenchmarksQueryParams = {
|
||||
benchmark_name: name,
|
||||
per_page: perPage,
|
||||
page,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
import type { DataView } from '@kbn/data-views-plugin/common';
|
||||
import type { BoolQuery, Filter, Query } from '@kbn/es-query';
|
||||
import type { CspRuleMetadataType } from '../../../common/schemas';
|
||||
import type { CspRuleMetadata } from '../../../common/schemas';
|
||||
|
||||
export type FindingsGroupByKind = 'default' | 'resource';
|
||||
|
||||
|
@ -31,7 +31,7 @@ export interface CspFinding {
|
|||
cycle_id: string;
|
||||
result: CspFindingResult;
|
||||
resource: CspFindingResource;
|
||||
rule: CspRuleMetadataType;
|
||||
rule: CspRuleMetadata;
|
||||
host: CspFindingHost;
|
||||
agent: CspFindingAgent;
|
||||
ecs: {
|
||||
|
|
|
@ -12,10 +12,10 @@ import {
|
|||
UPDATE_RULES_CONFIG_ROUTE_PATH,
|
||||
CSP_RULE_SAVED_OBJECT_TYPE,
|
||||
} from '../../../common/constants';
|
||||
import type { CspRuleType } from '../../../common/schemas';
|
||||
import type { CspRule } from '../../../common/schemas';
|
||||
import { useKibana } from '../../common/hooks/use_kibana';
|
||||
|
||||
export type RuleSavedObject = Omit<SimpleSavedObject<CspRuleType>, FunctionKeys<SimpleSavedObject>>;
|
||||
export type RuleSavedObject = Omit<SimpleSavedObject<CspRule>, FunctionKeys<SimpleSavedObject>>;
|
||||
|
||||
export type RulesQuery = Required<
|
||||
Pick<SavedObjectsFindOptions, 'search' | 'page' | 'perPage' | 'filter'>
|
||||
|
@ -26,7 +26,7 @@ export const useFindCspRules = ({ search, page, perPage, filter }: RulesQuery) =
|
|||
const { savedObjects } = useKibana().services;
|
||||
|
||||
return useQuery([CSP_RULE_SAVED_OBJECT_TYPE, { search, page, perPage }], () =>
|
||||
savedObjects.client.find<CspRuleType>({
|
||||
savedObjects.client.find<CspRule>({
|
||||
type: CSP_RULE_SAVED_OBJECT_TYPE,
|
||||
search: search ? `"${search}"*` : '',
|
||||
searchFields: ['metadata.name.text'],
|
||||
|
@ -52,7 +52,7 @@ export const useBulkUpdateCspRules = () => {
|
|||
packagePolicyId,
|
||||
}: {
|
||||
savedObjectRules: RuleSavedObject[];
|
||||
packagePolicyId: CspRuleType['package_policy_id'];
|
||||
packagePolicyId: CspRule['package_policy_id'];
|
||||
}) => {
|
||||
await savedObjects.client.bulkUpdate<RuleSavedObject>(
|
||||
savedObjectRules.map((savedObjectRule) => ({
|
||||
|
|
|
@ -18,7 +18,7 @@ import {
|
|||
CSP_RULE_SAVED_OBJECT_TYPE,
|
||||
CSP_RULE_TEMPLATE_SAVED_OBJECT_TYPE,
|
||||
} from '../../common/constants';
|
||||
import type { CspRuleType, CspRuleTemplateType } from '../../common/schemas';
|
||||
import type { CspRule, CspRuleTemplate } from '../../common/schemas';
|
||||
|
||||
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends ReadonlyArray<
|
||||
infer ElementType
|
||||
|
@ -35,7 +35,7 @@ export const onPackagePolicyPostCreateCallback = async (
|
|||
savedObjectsClient: SavedObjectsClientContract
|
||||
): Promise<void> => {
|
||||
// Create csp-rules from the generic asset
|
||||
const existingRuleTemplates: SavedObjectsFindResponse<CspRuleTemplateType> =
|
||||
const existingRuleTemplates: SavedObjectsFindResponse<CspRuleTemplate> =
|
||||
await savedObjectsClient.find({
|
||||
type: CSP_RULE_TEMPLATE_SAVED_OBJECT_TYPE,
|
||||
perPage: 10000,
|
||||
|
@ -69,7 +69,7 @@ export const removeCspRulesInstancesCallback = async (
|
|||
logger: Logger
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { saved_objects: cspRules }: SavedObjectsFindResponse<CspRuleType> = await soClient.find({
|
||||
const { saved_objects: cspRules }: SavedObjectsFindResponse<CspRule> = await soClient.find({
|
||||
type: CSP_RULE_SAVED_OBJECT_TYPE,
|
||||
filter: createCspRuleSearchFilterByPackagePolicy({
|
||||
packagePolicyId: deletedPackagePolicy.id,
|
||||
|
@ -90,7 +90,7 @@ export const isCspPackageInstalled = async (
|
|||
): Promise<boolean> => {
|
||||
// TODO: check if CSP package installed via the Fleet API
|
||||
try {
|
||||
const { saved_objects: postDeleteRules }: SavedObjectsFindResponse<CspRuleType> =
|
||||
const { saved_objects: postDeleteRules }: SavedObjectsFindResponse<CspRule> =
|
||||
await soClient.find({
|
||||
type: CSP_RULE_SAVED_OBJECT_TYPE,
|
||||
});
|
||||
|
@ -108,8 +108,8 @@ export const isCspPackageInstalled = async (
|
|||
const generateRulesFromTemplates = (
|
||||
packagePolicyId: string,
|
||||
policyId: string,
|
||||
cspRuleTemplates: Array<SavedObjectsFindResult<CspRuleTemplateType>>
|
||||
): Array<SavedObjectsBulkCreateObject<CspRuleType>> =>
|
||||
cspRuleTemplates: Array<SavedObjectsFindResult<CspRuleTemplate>>
|
||||
): Array<SavedObjectsBulkCreateObject<CspRule>> =>
|
||||
cspRuleTemplates.map((template) => ({
|
||||
type: CSP_RULE_SAVED_OBJECT_TYPE,
|
||||
attributes: {
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { KibanaRequest } from '@kbn/core/server/http/router/request';
|
||||
import {
|
||||
benchmarksInputSchema,
|
||||
benchmarksQueryParamsSchema,
|
||||
DEFAULT_BENCHMARKS_PER_PAGE,
|
||||
} from '../../../common/schemas/benchmark';
|
||||
import {
|
||||
|
@ -146,7 +146,7 @@ describe('benchmarks API', () => {
|
|||
|
||||
describe('test input schema', () => {
|
||||
it('expect to find default values', async () => {
|
||||
const validatedQuery = benchmarksInputSchema.validate({});
|
||||
const validatedQuery = benchmarksQueryParamsSchema.validate({});
|
||||
|
||||
expect(validatedQuery).toMatchObject({
|
||||
page: 1,
|
||||
|
@ -155,7 +155,7 @@ describe('benchmarks API', () => {
|
|||
});
|
||||
|
||||
it('expect to find benchmark_name', async () => {
|
||||
const validatedQuery = benchmarksInputSchema.validate({
|
||||
const validatedQuery = benchmarksQueryParamsSchema.validate({
|
||||
benchmark_name: 'my_cis_benchmark',
|
||||
});
|
||||
|
||||
|
@ -168,50 +168,50 @@ describe('benchmarks API', () => {
|
|||
|
||||
it('should throw when page field is not a positive integer', async () => {
|
||||
expect(() => {
|
||||
benchmarksInputSchema.validate({ page: -2 });
|
||||
benchmarksQueryParamsSchema.validate({ page: -2 });
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('should throw when per_page field is not a positive integer', async () => {
|
||||
expect(() => {
|
||||
benchmarksInputSchema.validate({ per_page: -2 });
|
||||
benchmarksQueryParamsSchema.validate({ per_page: -2 });
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw when sort_field is not string', async () => {
|
||||
expect(() => {
|
||||
benchmarksInputSchema.validate({ sort_field: true });
|
||||
benchmarksQueryParamsSchema.validate({ sort_field: true });
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('should not throw when sort_field is a string', async () => {
|
||||
expect(() => {
|
||||
benchmarksInputSchema.validate({ sort_field: 'package_policy.name' });
|
||||
benchmarksQueryParamsSchema.validate({ sort_field: 'package_policy.name' });
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('should throw when sort_order is not `asc` or `desc`', async () => {
|
||||
expect(() => {
|
||||
benchmarksInputSchema.validate({ sort_order: 'Other Direction' });
|
||||
benchmarksQueryParamsSchema.validate({ sort_order: 'Other Direction' });
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('should not throw when `asc` is input for sort_order field', async () => {
|
||||
expect(() => {
|
||||
benchmarksInputSchema.validate({ sort_order: 'asc' });
|
||||
benchmarksQueryParamsSchema.validate({ sort_order: 'asc' });
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('should not throw when `desc` is input for sort_order field', async () => {
|
||||
expect(() => {
|
||||
benchmarksInputSchema.validate({ sort_order: 'desc' });
|
||||
benchmarksQueryParamsSchema.validate({ sort_order: 'desc' });
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('should not throw when fields is a known string literal', async () => {
|
||||
expect(() => {
|
||||
benchmarksInputSchema.validate({ sort_field: 'package_policy.name' });
|
||||
benchmarksQueryParamsSchema.validate({ sort_field: 'package_policy.name' });
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
|
|
|
@ -26,12 +26,12 @@ import {
|
|||
} from '../../../common/constants';
|
||||
import {
|
||||
BENCHMARK_PACKAGE_POLICY_PREFIX,
|
||||
benchmarksInputSchema,
|
||||
BenchmarksQuerySchema,
|
||||
benchmarksQueryParamsSchema,
|
||||
BenchmarksQueryParams,
|
||||
} from '../../../common/schemas/benchmark';
|
||||
import { CspAppContext } from '../../plugin';
|
||||
import type { Benchmark, CspRulesStatus } from '../../../common/types';
|
||||
import type { CspRuleType } from '../../../common/schemas';
|
||||
import type { CspRule } from '../../../common/schemas';
|
||||
import {
|
||||
createCspRuleSearchFilterByPackagePolicy,
|
||||
isNonNullable,
|
||||
|
@ -53,7 +53,7 @@ export const getCspPackagePolicies = (
|
|||
soClient: SavedObjectsClientContract,
|
||||
packagePolicyService: PackagePolicyServiceInterface,
|
||||
packageName: string,
|
||||
queryParams: Partial<BenchmarksQuerySchema>
|
||||
queryParams: Partial<BenchmarksQueryParams>
|
||||
): Promise<ListResult<PackagePolicy>> => {
|
||||
if (!packagePolicyService) {
|
||||
throw new Error('packagePolicyService is undefined');
|
||||
|
@ -107,8 +107,8 @@ export interface RulesStatusAggregation {
|
|||
export const getCspRulesStatus = (
|
||||
soClient: SavedObjectsClientContract,
|
||||
packagePolicy: PackagePolicy
|
||||
): Promise<SavedObjectsFindResponse<CspRuleType, RulesStatusAggregation>> => {
|
||||
const cspRules = soClient.find<CspRuleType, RulesStatusAggregation>({
|
||||
): Promise<SavedObjectsFindResponse<CspRule, RulesStatusAggregation>> => {
|
||||
const cspRules = soClient.find<CspRule, RulesStatusAggregation>({
|
||||
type: CSP_RULE_SAVED_OBJECT_TYPE,
|
||||
filter: createCspRuleSearchFilterByPackagePolicy({
|
||||
packagePolicyId: packagePolicy.id,
|
||||
|
@ -200,7 +200,7 @@ export const defineGetBenchmarksRoute = (router: CspRouter, cspContext: CspAppCo
|
|||
router.get(
|
||||
{
|
||||
path: BENCHMARKS_ROUTE_PATH,
|
||||
validate: { query: benchmarksInputSchema },
|
||||
validate: { query: benchmarksQueryParamsSchema },
|
||||
options: {
|
||||
tags: ['access:cloud-security-posture-read'],
|
||||
},
|
||||
|
|
|
@ -26,7 +26,7 @@ import { createPackagePolicyMock } from '@kbn/fleet-plugin/common/mocks';
|
|||
import { createPackagePolicyServiceMock } from '@kbn/fleet-plugin/server/mocks';
|
||||
|
||||
import { CSP_RULE_SAVED_OBJECT_TYPE } from '../../../common/constants';
|
||||
import type { CspRuleType } from '../../../common/schemas';
|
||||
import type { CspRule } from '../../../common/schemas';
|
||||
|
||||
import {
|
||||
ElasticsearchClient,
|
||||
|
@ -129,7 +129,7 @@ describe('Update rules configuration API', () => {
|
|||
});
|
||||
|
||||
it('create csp rules config based on activated csp rules', async () => {
|
||||
const cspRules: DeepPartial<SavedObjectsFindResponse<CspRuleType>> = {
|
||||
const cspRules: DeepPartial<SavedObjectsFindResponse<CspRule>> = {
|
||||
page: 1,
|
||||
per_page: 1000,
|
||||
total: 2,
|
||||
|
@ -163,14 +163,14 @@ describe('Update rules configuration API', () => {
|
|||
},
|
||||
],
|
||||
};
|
||||
const cspConfig = await createRulesConfig(cspRules as SavedObjectsFindResponse<CspRuleType>);
|
||||
const cspConfig = await createRulesConfig(cspRules as SavedObjectsFindResponse<CspRule>);
|
||||
expect(cspConfig).toMatchObject({
|
||||
data_yaml: { activated_rules: { cis_k8s: ['cis_1_1_1', 'cis_1_1_3'] } },
|
||||
});
|
||||
});
|
||||
|
||||
it('create empty csp rules config when all rules are disabled', async () => {
|
||||
const cspRules: DeepPartial<SavedObjectsFindResponse<CspRuleType>> = {
|
||||
const cspRules: DeepPartial<SavedObjectsFindResponse<CspRule>> = {
|
||||
page: 1,
|
||||
per_page: 1000,
|
||||
total: 2,
|
||||
|
@ -204,7 +204,7 @@ describe('Update rules configuration API', () => {
|
|||
},
|
||||
],
|
||||
};
|
||||
const cspConfig = await createRulesConfig(cspRules as SavedObjectsFindResponse<CspRuleType>);
|
||||
const cspConfig = await createRulesConfig(cspRules as SavedObjectsFindResponse<CspRule>);
|
||||
expect(cspConfig).toMatchObject({ data_yaml: { activated_rules: { cis_k8s: [] } } });
|
||||
});
|
||||
|
||||
|
@ -242,7 +242,7 @@ describe('Update rules configuration API', () => {
|
|||
}
|
||||
);
|
||||
|
||||
const cspRules: DeepPartial<SavedObjectsFindResponse<CspRuleType>> = {
|
||||
const cspRules: DeepPartial<SavedObjectsFindResponse<CspRule>> = {
|
||||
page: 1,
|
||||
per_page: 1000,
|
||||
total: 2,
|
||||
|
@ -276,7 +276,7 @@ describe('Update rules configuration API', () => {
|
|||
},
|
||||
],
|
||||
};
|
||||
mockSoClient.find.mockResolvedValueOnce(cspRules as SavedObjectsFindResponse<CspRuleType>);
|
||||
mockSoClient.find.mockResolvedValueOnce(cspRules as SavedObjectsFindResponse<CspRule>);
|
||||
|
||||
const mockPackagePolicy = createPackagePolicyMock();
|
||||
mockPackagePolicy.vars = { dataYaml: { type: 'foo' } };
|
||||
|
@ -304,7 +304,7 @@ describe('Update rules configuration API', () => {
|
|||
mockSoClient = savedObjectsClientMock.create();
|
||||
const mockPackagePolicyService = createPackagePolicyServiceMock();
|
||||
|
||||
const cspRules: DeepPartial<SavedObjectsFindResponse<CspRuleType>> = {
|
||||
const cspRules: DeepPartial<SavedObjectsFindResponse<CspRule>> = {
|
||||
page: 1,
|
||||
per_page: 1000,
|
||||
total: 2,
|
||||
|
@ -338,7 +338,7 @@ describe('Update rules configuration API', () => {
|
|||
},
|
||||
],
|
||||
};
|
||||
mockSoClient.find.mockResolvedValueOnce(cspRules as SavedObjectsFindResponse<CspRuleType>);
|
||||
mockSoClient.find.mockResolvedValueOnce(cspRules as SavedObjectsFindResponse<CspRule>);
|
||||
|
||||
const mockPackagePolicy = createPackagePolicyMock();
|
||||
const packagePolicyId1 = chance.guid();
|
||||
|
@ -378,7 +378,7 @@ describe('Update rules configuration API', () => {
|
|||
const mockPackagePolicy = createPackagePolicyMock();
|
||||
const user = mockAuthenticatedUser();
|
||||
|
||||
const cspRules: DeepPartial<SavedObjectsFindResponse<CspRuleType>> = {
|
||||
const cspRules: DeepPartial<SavedObjectsFindResponse<CspRule>> = {
|
||||
page: 1,
|
||||
per_page: 1000,
|
||||
total: 2,
|
||||
|
@ -394,7 +394,7 @@ describe('Update rules configuration API', () => {
|
|||
},
|
||||
],
|
||||
};
|
||||
mockSoClient.find.mockResolvedValueOnce(cspRules as SavedObjectsFindResponse<CspRuleType>);
|
||||
mockSoClient.find.mockResolvedValueOnce(cspRules as SavedObjectsFindResponse<CspRule>);
|
||||
|
||||
mockPackagePolicy.vars = { dataYaml: { type: 'yaml' } };
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import { PackagePolicyServiceInterface } from '@kbn/fleet-plugin/server';
|
|||
import { AuthenticatedUser } from '@kbn/security-plugin/common';
|
||||
import { createCspRuleSearchFilterByPackagePolicy } from '../../../common/utils/helpers';
|
||||
import { CspAppContext } from '../../plugin';
|
||||
import type { CspRuleType, CspRulesConfigSchema } from '../../../common/schemas';
|
||||
import type { CspRule, CspRulesConfiguration } from '../../../common/schemas';
|
||||
import {
|
||||
CLOUD_SECURITY_POSTURE_PACKAGE_NAME,
|
||||
UPDATE_RULES_CONFIG_ROUTE_PATH,
|
||||
|
@ -52,8 +52,8 @@ export const getPackagePolicy = async (
|
|||
export const getCspRules = (
|
||||
soClient: SavedObjectsClientContract,
|
||||
packagePolicy: PackagePolicy
|
||||
): Promise<SavedObjectsFindResponse<CspRuleType, unknown>> => {
|
||||
return soClient.find<CspRuleType>({
|
||||
): Promise<SavedObjectsFindResponse<CspRule, unknown>> => {
|
||||
return soClient.find<CspRule>({
|
||||
type: CSP_RULE_SAVED_OBJECT_TYPE,
|
||||
filter: createCspRuleSearchFilterByPackagePolicy({
|
||||
packagePolicyId: packagePolicy.id,
|
||||
|
@ -66,8 +66,8 @@ export const getCspRules = (
|
|||
};
|
||||
|
||||
export const createRulesConfig = (
|
||||
cspRules: SavedObjectsFindResponse<CspRuleType>
|
||||
): CspRulesConfigSchema => {
|
||||
cspRules: SavedObjectsFindResponse<CspRule>
|
||||
): CspRulesConfiguration => {
|
||||
const activatedRules = cspRules.saved_objects.filter((cspRule) => cspRule.attributes.enabled);
|
||||
const config = {
|
||||
data_yaml: {
|
||||
|
@ -81,7 +81,7 @@ export const createRulesConfig = (
|
|||
return config;
|
||||
};
|
||||
|
||||
export const convertRulesConfigToYaml = (config: CspRulesConfigSchema): string => {
|
||||
export const convertRulesConfigToYaml = (config: CspRulesConfiguration): string => {
|
||||
return yaml.safeDump(config);
|
||||
};
|
||||
|
||||
|
@ -128,7 +128,7 @@ export const defineUpdateRulesConfigRoute = (router: CspRouter, cspContext: CspA
|
|||
router.post(
|
||||
{
|
||||
path: UPDATE_RULES_CONFIG_ROUTE_PATH,
|
||||
validate: { body: configurationUpdateInputSchema },
|
||||
validate: { body: updateRulesConfigurationBodySchema },
|
||||
options: {
|
||||
tags: ['access:cloud-security-posture-all'],
|
||||
},
|
||||
|
@ -177,7 +177,7 @@ export const defineUpdateRulesConfigRoute = (router: CspRouter, cspContext: CspA
|
|||
}
|
||||
);
|
||||
|
||||
export const configurationUpdateInputSchema = rt.object({
|
||||
export const updateRulesConfigurationBodySchema = rt.object({
|
||||
/**
|
||||
* CSP integration instance ID
|
||||
*/
|
||||
|
|
|
@ -10,12 +10,12 @@ import {
|
|||
SavedObjectUnsanitizedDoc,
|
||||
SavedObjectMigrationContext,
|
||||
} from '@kbn/core/server';
|
||||
import { CspRuleTypeV830, CspRuleTypeV840 } from '../../../common/schemas/csp_rule';
|
||||
import { CspRuleV830, CspRuleV840 } from '../../../common/schemas/csp_rule';
|
||||
|
||||
function migrateCspRuleMetadata(
|
||||
doc: SavedObjectUnsanitizedDoc<CspRuleTypeV830>,
|
||||
doc: SavedObjectUnsanitizedDoc<CspRuleV830>,
|
||||
context: SavedObjectMigrationContext
|
||||
): SavedObjectUnsanitizedDoc<CspRuleTypeV840> {
|
||||
): SavedObjectUnsanitizedDoc<CspRuleV840> {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const { enabled, muted, package_policy_id, policy_id, ...metadata } = doc.attributes;
|
||||
|
||||
|
|
|
@ -11,14 +11,14 @@ import {
|
|||
SavedObjectMigrationContext,
|
||||
} from '@kbn/core/server';
|
||||
import {
|
||||
CspRuleTemplateTypeV830,
|
||||
CspRuleTemplateTypeV840,
|
||||
CspRuleTemplateV830,
|
||||
CspRuleTemplateV840,
|
||||
} from '../../../common/schemas/csp_rule_template';
|
||||
|
||||
function migrateCspRuleMetadata(
|
||||
doc: SavedObjectUnsanitizedDoc<CspRuleTemplateTypeV830>,
|
||||
doc: SavedObjectUnsanitizedDoc<CspRuleTemplateV830>,
|
||||
context: SavedObjectMigrationContext
|
||||
): SavedObjectUnsanitizedDoc<CspRuleTemplateTypeV840> {
|
||||
): SavedObjectUnsanitizedDoc<CspRuleTemplateV840> {
|
||||
const { enabled, muted, ...metadata } = doc.attributes;
|
||||
return {
|
||||
...doc,
|
||||
|
|
|
@ -14,8 +14,8 @@ import {
|
|||
cspRuleSchemaV840,
|
||||
cspRuleTemplateSchemaV830,
|
||||
cspRuleTemplateSchemaV840,
|
||||
CspRuleTemplateType,
|
||||
CspRuleType,
|
||||
CspRuleTemplate,
|
||||
CspRule,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import {
|
||||
|
@ -24,7 +24,7 @@ import {
|
|||
} from '../../common/constants';
|
||||
|
||||
export function setupSavedObjects(savedObjects: SavedObjectsServiceSetup) {
|
||||
savedObjects.registerType<CspRuleType>({
|
||||
savedObjects.registerType<CspRule>({
|
||||
name: CSP_RULE_SAVED_OBJECT_TYPE,
|
||||
hidden: false,
|
||||
namespaceType: 'agnostic',
|
||||
|
@ -45,7 +45,7 @@ export function setupSavedObjects(savedObjects: SavedObjectsServiceSetup) {
|
|||
migrations: cspRuleMigrations,
|
||||
mappings: cspRuleSavedObjectMapping,
|
||||
});
|
||||
savedObjects.registerType<CspRuleTemplateType>({
|
||||
savedObjects.registerType<CspRuleTemplate>({
|
||||
name: CSP_RULE_TEMPLATE_SAVED_OBJECT_TYPE,
|
||||
hidden: false,
|
||||
namespaceType: 'agnostic',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue