Skip to content
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

[Security Solution] Replaced the incorrect runtime type used for ruleSource #184004

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
IndexPatternArray,
InvestigationFields,
InvestigationGuide,
IsExternalRuleCustomized,
IsRuleImmutable,
ItemsPerSearch,
KqlQueryLanguage,
Expand All @@ -63,7 +64,6 @@ import {
RuleQuery,
RuleReferenceArray,
RuleSignatureId,
RuleSource,
RuleVersion,
SavedQueryId,
SetupGuide,
Expand All @@ -84,7 +84,6 @@ import {
TimestampOverrideFallbackDisabled,
} from '../../../../../common/api/detection_engine/model/rule_schema';
import type { SERVER_APP_ID } from '../../../../../common/constants';
import { convertObjectKeysToCamelCase } from '../../../../utils/object_case_converters';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also do something with this utility? For example:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function works as expected. It accepts any object and converts its keys to camel case. It has nothing to do with Zod and can be used (and is used) in other places, so I believe we can leave it as is.


// 8.10.x is mapped as an array of strings
export type LegacyInvestigationFields = z.infer<typeof LegacyInvestigationFields>;
Expand All @@ -104,8 +103,20 @@ export const InvestigationFieldsCombined = z.union([
LegacyInvestigationFields,
]);

/**
* This is the same type as RuleSource, but with the keys in camelCase. Intended
* for internal use only (not for API responses).
*/
export type RuleSourceCamelCased = z.infer<typeof RuleSourceCamelCased>;
export const RuleSourceCamelCased = RuleSource.transform(convertObjectKeysToCamelCase);
export const RuleSourceCamelCased = z.discriminatedUnion('type', [
z.object({
type: z.literal('external'),
isCustomized: IsExternalRuleCustomized,
}),
z.object({
type: z.literal('internal'),
}),
]);

// Conversion to an interface has to be disabled for the entire file; otherwise,
// the resulting union would not be assignable to Alerting's RuleParams due to a
Expand Down