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] Add nested field inside of data provider #93721

Merged
merged 15 commits into from
Mar 9, 2021
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ const checkIfFieldTypeIsDate = (field: string, browserFields: BrowserFields) =>
return false;
};

const convertNestedFieldToQuery = (
field: string,
value: string | number,
browserFields: BrowserFields
) => {
const pathBrowserField = getBrowserFieldPath(field, browserFields);
const browserField = get(pathBrowserField, browserFields);
const nestedPath = browserField.subType.nested.path;
const key = field.replace(`${nestedPath}.`, '');
return `${nestedPath}: { ${key}: ${value} }`;
};

const convertNestedFieldToExistQuery = (field: string, browserFields: BrowserFields) => {
const pathBrowserField = getBrowserFieldPath(field, browserFields);
const browserField = get(pathBrowserField, browserFields);
const nestedPath = browserField.subType.nested.path;
const key = field.replace(`${nestedPath}.`, '');
return `${nestedPath}: { ${key}: * }`;
};

const checkIfFieldTypeIsNested = (field: string, browserFields: BrowserFields) => {
const pathBrowserField = getBrowserFieldPath(field, browserFields);
const browserField = get(pathBrowserField, browserFields);
if (browserField != null && browserField.subType.nested) {
return true;
}
return false;
};

const buildQueryMatch = (
dataProvider: DataProvider | DataProvidersAnd,
browserFields: BrowserFields
Expand All @@ -73,11 +102,19 @@ const buildQueryMatch = (
dataProvider.type !== DataProviderType.template
? checkIfFieldTypeIsDate(dataProvider.queryMatch.field, browserFields)
? convertDateFieldToQuery(dataProvider.queryMatch.field, dataProvider.queryMatch.value)
: checkIfFieldTypeIsNested(dataProvider.queryMatch.field, browserFields)
? convertNestedFieldToQuery(
dataProvider.queryMatch.field,
dataProvider.queryMatch.value,
browserFields
)
: `${dataProvider.queryMatch.field} : ${
isNumber(dataProvider.queryMatch.value)
? dataProvider.queryMatch.value
: escapeQueryValue(dataProvider.queryMatch.value)
}`
: checkIfFieldTypeIsNested(dataProvider.queryMatch.field, browserFields)
? convertNestedFieldToExistQuery(dataProvider.queryMatch.field, browserFields)
: `${dataProvider.queryMatch.field} ${EXISTS_OPERATOR}`
}`.trim();

Expand Down