-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add KQL functionality in the find function of the saved objects (#41136…
…) (#47182) * Add KQL functionality in the find function of the saved objects wip rename variable from KQL to filter, fix unit test + add new ones miss security pluggins review I fix api changes refactor after reviewing with Rudolf fix type review III review IV for security put back allowed logic back to return empty results remove StaticIndexPattern review V fix core_api_changes fix type * validate filter to match requirement type.attributes.key or type.savedObjectKey * Fix types * fix a bug + add more api integration test * fix types in test until we create package @kbn/types * fix type issue * fix api integration test * export nodeTypes from packages @kbn/es-query instead of the function buildNodeKuery * throw 400- bad request when validation error in find * fix type issue * accept api change * renove _ to represent private * fix unit test + add doc * add comment to explain why we removed the private
- Loading branch information
Showing
42 changed files
with
2,459 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
.../development/core/public/kibana-plugin-public.savedobjectsfindoptions.filter.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) > [filter](./kibana-plugin-public.savedobjectsfindoptions.filter.md) | ||
|
||
## SavedObjectsFindOptions.filter property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
filter?: string; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
.../development/core/server/kibana-plugin-server.savedobjectsfindoptions.filter.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SavedObjectsFindOptions](./kibana-plugin-server.savedobjectsfindoptions.md) > [filter](./kibana-plugin-server.savedobjectsfindoptions.filter.md) | ||
|
||
## SavedObjectsFindOptions.filter property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
filter?: string; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/** | ||
* WARNING: these typings are incomplete | ||
*/ | ||
|
||
import { JsonObject, JsonValue } from '..'; | ||
|
||
type FunctionName = | ||
| 'is' | ||
| 'and' | ||
| 'or' | ||
| 'not' | ||
| 'range' | ||
| 'exists' | ||
| 'geoBoundingBox' | ||
| 'geoPolygon'; | ||
|
||
interface FunctionTypeBuildNode { | ||
type: 'function'; | ||
function: FunctionName; | ||
// TODO -> Need to define a better type for DSL query | ||
arguments: any[]; | ||
} | ||
|
||
interface FunctionType { | ||
buildNode: (functionName: FunctionName, ...args: any[]) => FunctionTypeBuildNode; | ||
buildNodeWithArgumentNodes: (functionName: FunctionName, ...args: any[]) => FunctionTypeBuildNode; | ||
toElasticsearchQuery: (node: any, indexPattern: any, config: JsonObject) => JsonValue; | ||
} | ||
|
||
interface LiteralType { | ||
buildNode: ( | ||
value: null | boolean | number | string | ||
) => { type: 'literal'; value: null | boolean | number | string }; | ||
toElasticsearchQuery: (node: any) => null | boolean | number | string; | ||
} | ||
|
||
interface NamedArgType { | ||
buildNode: (name: string, value: any) => { type: 'namedArg'; name: string; value: any }; | ||
toElasticsearchQuery: (node: any) => string; | ||
} | ||
|
||
interface WildcardType { | ||
buildNode: (value: string) => { type: 'wildcard'; value: string }; | ||
test: (node: any, string: string) => boolean; | ||
toElasticsearchQuery: (node: any) => string; | ||
toQueryStringQuery: (node: any) => string; | ||
hasLeadingWildcard: (node: any) => boolean; | ||
} | ||
|
||
interface NodeTypes { | ||
function: FunctionType; | ||
literal: LiteralType; | ||
namedArg: NamedArgType; | ||
wildcard: WildcardType; | ||
} | ||
|
||
export const nodeTypes: NodeTypes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/core/server/saved_objects/service/lib/cache_index_patterns.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { SavedObjectsCacheIndexPatterns } from './cache_index_patterns'; | ||
|
||
const mockGetFieldsForWildcard = jest.fn(); | ||
const mockIndexPatternsService: jest.Mock = jest.fn().mockImplementation(() => ({ | ||
getFieldsForWildcard: mockGetFieldsForWildcard, | ||
getFieldsForTimePattern: jest.fn(), | ||
})); | ||
|
||
describe('SavedObjectsRepository', () => { | ||
let cacheIndexPatterns: SavedObjectsCacheIndexPatterns; | ||
|
||
const fields = [ | ||
{ | ||
aggregatable: true, | ||
name: 'config.type', | ||
searchable: true, | ||
type: 'string', | ||
}, | ||
{ | ||
aggregatable: true, | ||
name: 'foo.type', | ||
searchable: true, | ||
type: 'string', | ||
}, | ||
{ | ||
aggregatable: true, | ||
name: 'bar.type', | ||
searchable: true, | ||
type: 'string', | ||
}, | ||
{ | ||
aggregatable: true, | ||
name: 'baz.type', | ||
searchable: true, | ||
type: 'string', | ||
}, | ||
{ | ||
aggregatable: true, | ||
name: 'dashboard.otherField', | ||
searchable: true, | ||
type: 'string', | ||
}, | ||
{ | ||
aggregatable: true, | ||
name: 'hiddenType.someField', | ||
searchable: true, | ||
type: 'string', | ||
}, | ||
]; | ||
|
||
beforeEach(() => { | ||
cacheIndexPatterns = new SavedObjectsCacheIndexPatterns(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('setIndexPatterns should return an error object when indexPatternsService is undefined', async () => { | ||
try { | ||
await cacheIndexPatterns.setIndexPatterns('test-index'); | ||
} catch (error) { | ||
expect(error.message).toMatch('indexPatternsService is not defined'); | ||
} | ||
}); | ||
|
||
it('setIndexPatterns should return an error object if getFieldsForWildcard is not defined', async () => { | ||
mockGetFieldsForWildcard.mockImplementation(() => { | ||
throw new Error('something happen'); | ||
}); | ||
try { | ||
cacheIndexPatterns.setIndexPatternsService(new mockIndexPatternsService()); | ||
await cacheIndexPatterns.setIndexPatterns('test-index'); | ||
} catch (error) { | ||
expect(error.message).toMatch('Index Pattern Error - something happen'); | ||
} | ||
}); | ||
|
||
it('setIndexPatterns should return empty array when getFieldsForWildcard is returning null or undefined', async () => { | ||
mockGetFieldsForWildcard.mockImplementation(() => null); | ||
cacheIndexPatterns.setIndexPatternsService(new mockIndexPatternsService()); | ||
await cacheIndexPatterns.setIndexPatterns('test-index'); | ||
expect(cacheIndexPatterns.getIndexPatterns()).toEqual(undefined); | ||
}); | ||
|
||
it('setIndexPatterns should return index pattern when getFieldsForWildcard is returning fields', async () => { | ||
mockGetFieldsForWildcard.mockImplementation(() => fields); | ||
cacheIndexPatterns.setIndexPatternsService(new mockIndexPatternsService()); | ||
await cacheIndexPatterns.setIndexPatterns('test-index'); | ||
expect(cacheIndexPatterns.getIndexPatterns()).toEqual({ fields, title: 'test-index' }); | ||
}); | ||
}); |
Oops, something went wrong.