-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cloud Security] Rules Combo Box filters Custom component #175175
Changes from 12 commits
03fdd91
4a03581
11a0180
e220abc
4a144ef
390dfe9
f0aab5c
fad1882
7563a50
05284d1
f704d7b
a41599d
5aaeffe
28fa96d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ | |
* 2.0. | ||
*/ | ||
|
||
export * from './rules/v4'; | ||
export * from './rules/v5'; | ||
export * from './benchmarks/v2'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { schema, TypeOf } from '@kbn/config-schema'; | ||
import { DEFAULT_BENCHMARK_RULES_PER_PAGE } from './v3'; | ||
|
||
export type { | ||
cspBenchmarkRuleMetadataSchema, | ||
CspBenchmarkRuleMetadata, | ||
cspBenchmarkRuleSchema, | ||
CspBenchmarkRule, | ||
FindCspBenchmarkRuleResponse, | ||
} from './v3'; | ||
export type { | ||
PageUrlParams, | ||
rulesToUpdate, | ||
CspBenchmarkRulesBulkActionRequestSchema, | ||
CspBenchmarkRulesBulkActionResponse, | ||
RuleStateAttributes, | ||
CspBenchmarkRulesStates, | ||
cspSettingsSchema, | ||
CspSettings, | ||
BulkActionBenchmarkRulesResponse, | ||
} from './v4'; | ||
|
||
export type FindCspBenchmarkRuleRequest = TypeOf<typeof findCspBenchmarkRuleRequestSchema>; | ||
|
||
export const findCspBenchmarkRuleRequestSchema = schema.object({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you highlight what is new here that requires a new version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just ruleNumber and section, previously its only string because we can only filter using 1 rule number and 1 cis section. now its an array because can filter using multiple rule number and cis section |
||
/** | ||
* An Elasticsearch simple_query_string | ||
*/ | ||
search: schema.maybe(schema.string()), | ||
|
||
/** | ||
* The page of objects to return | ||
*/ | ||
page: schema.number({ defaultValue: 1, min: 1 }), | ||
|
||
/** | ||
* The number of objects to include in each page | ||
*/ | ||
perPage: schema.number({ defaultValue: DEFAULT_BENCHMARK_RULES_PER_PAGE, min: 0 }), | ||
|
||
/** | ||
* Fields to retrieve from CspBenchmarkRule saved object | ||
*/ | ||
fields: schema.maybe(schema.arrayOf(schema.string())), | ||
|
||
/** | ||
* The fields to perform the parsed query against. | ||
* Valid fields are fields which mapped to 'text' in cspBenchmarkRuleSavedObjectMapping | ||
*/ | ||
searchFields: schema.arrayOf( | ||
schema.oneOf([schema.literal('metadata.name.text'), schema.literal('metadata.section.text')]), | ||
{ defaultValue: ['metadata.name.text'] } | ||
), | ||
|
||
/** | ||
* Sort Field | ||
*/ | ||
sortField: schema.oneOf( | ||
[ | ||
schema.literal('metadata.name'), | ||
schema.literal('metadata.section'), | ||
schema.literal('metadata.id'), | ||
schema.literal('metadata.version'), | ||
schema.literal('metadata.benchmark.id'), | ||
schema.literal('metadata.benchmark.name'), | ||
schema.literal('metadata.benchmark.posture_type'), | ||
schema.literal('metadata.benchmark.version'), | ||
schema.literal('metadata.benchmark.rule_number'), | ||
], | ||
{ | ||
defaultValue: 'metadata.benchmark.rule_number', | ||
} | ||
), | ||
|
||
/** | ||
* The order to sort by | ||
*/ | ||
sortOrder: schema.oneOf([schema.literal('asc'), schema.literal('desc')], { | ||
defaultValue: 'asc', | ||
}), | ||
|
||
/** | ||
* benchmark id | ||
*/ | ||
benchmarkId: schema.maybe( | ||
schema.oneOf([ | ||
schema.literal('cis_k8s'), | ||
schema.literal('cis_eks'), | ||
schema.literal('cis_aws'), | ||
schema.literal('cis_azure'), | ||
schema.literal('cis_gcp'), | ||
]) | ||
), | ||
|
||
/** | ||
* benchmark version | ||
*/ | ||
benchmarkVersion: schema.maybe(schema.string()), | ||
|
||
/** | ||
* rule section | ||
*/ | ||
section: schema.maybe( | ||
schema.oneOf([schema.string(), schema.arrayOf(schema.string(), { minSize: 1 })]) | ||
), | ||
ruleNumber: schema.maybe( | ||
schema.oneOf([schema.string(), schema.arrayOf(schema.string(), { minSize: 1 })]) | ||
), | ||
}); | ||
|
||
export interface BenchmarkRuleSelectParams { | ||
section?: string[]; | ||
ruleNumber?: string[]; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -218,3 +218,29 @@ export const getBenchmarkFilterQuery = ( | |||||
: ''; | ||||||
return baseQuery + sectionQuery + ruleNumberQuery; | ||||||
}; | ||||||
|
||||||
export const getBenchmarkFilterQueryV2 = ( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like we get the same params and return a string, why do we need a new version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously we only accept string for the rule number and section filter, but now since we add ability to filter based on multiple rule number and/or section we use array instead of string |
||||||
id: BenchmarkId, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
version?: string, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
selectParams?: BenchmarkRuleSelectParams | ||||||
): string => { | ||||||
const baseQuery = `${CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE}.attributes.metadata.benchmark.id:${id} AND ${CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE}.attributes.metadata.benchmark.version:"v${version}"`; | ||||||
|
||||||
let sectionQuery = ''; | ||||||
let ruleNumberQuery = ''; | ||||||
if (selectParams?.section) { | ||||||
const sectionParamsArr = selectParams.section?.map( | ||||||
(params) => `${CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE}.attributes.metadata.section: "${params}"` | ||||||
); | ||||||
sectionQuery = ' AND (' + sectionParamsArr.join(' OR ') + ')'; | ||||||
} | ||||||
if (selectParams?.ruleNumber) { | ||||||
const ruleNumbersParamsArr = selectParams.ruleNumber?.map( | ||||||
(params) => | ||||||
`${CSP_BENCHMARK_RULE_SAVED_OBJECT_TYPE}.attributes.metadata.benchmark.rule_number: "${params}"` | ||||||
); | ||||||
ruleNumberQuery = ' AND (' + ruleNumbersParamsArr.join(' OR ') + ')'; | ||||||
} | ||||||
|
||||||
return baseQuery + sectionQuery + ruleNumberQuery; | ||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason to modify the pervious version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh good catch this wasnt supposed to be modified