Skip to content

Commit

Permalink
Merge branch 'master' into fix/kibana-privileges-timing
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Dec 4, 2019
2 parents 88b5222 + a74a129 commit 836803c
Show file tree
Hide file tree
Showing 68 changed files with 1,737 additions and 1,510 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
"minimatch": "^3.0.4",
"moment": "^2.24.0",
"moment-timezone": "^0.5.27",
"monaco-editor": "~0.17.0",
"mustache": "2.3.2",
"ngreact": "0.5.1",
"node-fetch": "1.7.3",
Expand All @@ -222,7 +223,9 @@
"react-grid-layout": "^0.16.2",
"react-input-range": "^1.3.0",
"react-markdown": "^3.4.1",
"react-monaco-editor": "~0.27.0",
"react-redux": "^5.1.2",
"react-resize-detector": "^4.2.0",
"react-router-dom": "^4.3.1",
"react-sizeme": "^2.3.6",
"reactcss": "1.2.3",
Expand Down Expand Up @@ -335,6 +338,7 @@
"@types/react": "^16.9.11",
"@types/react-dom": "^16.9.4",
"@types/react-redux": "^6.0.6",
"@types/react-resize-detector": "^4.0.1",
"@types/react-router-dom": "^4.3.1",
"@types/react-virtualized": "^9.18.7",
"@types/redux": "^3.6.31",
Expand Down
8 changes: 5 additions & 3 deletions src/core/CONVENTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ my_plugin/
└── server
├── routes
│ └── index.ts
├── collectors
│ └── register.ts
   ├── services
   │   ├── my_service
   │   │ └── index.ts
   │   └── index.ts
   ├── index.ts
   └── plugin.ts
```

- Both `server` and `public` should have an `index.ts` and a `plugin.ts` file:
- `index.ts` should only contain:
- The `plugin` export
Expand All @@ -44,8 +45,9 @@ my_plugin/
- If there is only a single application, this directory can be called `application` that exports the `renderApp` function.
- Services provided to other plugins as APIs should live inside the `services` subdirectory.
- Services should model the plugin lifecycle (more details below).
- HTTP routes should be contained inside the `routes` directory.
- HTTP routes should be contained inside the `server/routes` directory.
- More should be fleshed out here...
- Usage collectors for Telemetry should be defined in a separate `server/collectors/` directory.

### The PluginInitializer

Expand Down Expand Up @@ -213,7 +215,7 @@ export class Plugin {

### Usage Collection

For creating and registering a Usage Collector. Collectors would be defined in a separate directory `server/collectors/register.ts`. You can read more about usage collectors on `src/plugins/usage_collection/README.md`.
For creating and registering a Usage Collector. Collectors should be defined in a separate directory `server/collectors/`. You can read more about usage collectors on `src/plugins/usage_collection/README.md`.

```ts
// server/collectors/register.ts
Expand Down
11 changes: 9 additions & 2 deletions src/core/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ src/plugins
"ui": true
}
```
More details about[manifest file format](/docs/development/core/server/kibana-plugin-server.pluginmanifest.md)

Note that `package.json` files are irrelevant to and ignored by the new platform.

Expand Down Expand Up @@ -1140,7 +1141,6 @@ import { npStart: { core } } from 'ui/new_platform';
| `chrome.getUiSettingsClient` | [`core.uiSettings`](/docs/development/core/public/kibana-plugin-public.uisettingsclient.md) | |
| `chrome.helpExtension.set` | [`core.chrome.setHelpExtension`](/docs/development/core/public/kibana-plugin-public.chromestart.sethelpextension.md) | |
| `chrome.setVisible` | [`core.chrome.setIsVisible`](/docs/development/core/public/kibana-plugin-public.chromestart.setisvisible.md) | |
| `chrome.getInjected` | -- | Not implemented yet, see [#41990](https://github.com/elastic/kibana/issues/41990) |
| `chrome.setRootTemplate` / `chrome.setRootController` | -- | Use application mounting via `core.application.register` (not available to legacy plugins at this time). |
| `import { recentlyAccessed } from 'ui/persisted_log'` | [`core.chrome.recentlyAccessed`](/docs/development/core/public/kibana-plugin-public.chromerecentlyaccessed.md) | |
| `ui/capabilities` | [`core.application.capabilities`](/docs/development/core/public/kibana-plugin-public.capabilities.md) | |
Expand All @@ -1150,7 +1150,7 @@ import { npStart: { core } } from 'ui/new_platform';
| `ui/routes` | -- | There is no global routing mechanism. Each app [configures its own routing](/rfcs/text/0004_application_service_mounting.md#complete-example). |
| `ui/saved_objects` | [`core.savedObjects`](/docs/development/core/public/kibana-plugin-public.savedobjectsstart.md) | Client API is the same |
| `ui/doc_title` | [`core.chrome.docTitle`](/docs/development/core/public/kibana-plugin-public.chromedoctitle.md) | |
| `uiExports/injectedVars` | [Configure plugin](#configure-plugin) and [`PluginConfigDescriptor.exposeToBrowser`](/docs/development/core/server/kibana-plugin-server.pluginconfigdescriptor.exposetobrowser.md) | Can only be used to expose configuration properties |
| `uiExports/injectedVars` / `chrome.getInjected` | [Configure plugin](#configure-plugin) and [`PluginConfigDescriptor.exposeToBrowser`](/docs/development/core/server/kibana-plugin-server.pluginconfigdescriptor.exposetobrowser.md) | Can only be used to expose configuration properties |

_See also: [Public's CoreStart API Docs](/docs/development/core/public/kibana-plugin-public.corestart.md)_
Expand Down Expand Up @@ -1352,6 +1352,13 @@ export class Plugin implements Plugin<PluginSetup, PluginStart> {
}
```
All plugins are considered enabled by default. If you want to disable your plugin by default, you could declare the `enabled` flag in plugin config. This is a special Kibana platform key. The platform reads its value and won't create a plugin instance if `enabled: false`.
```js
export const config = {
schema: schema.object({ enabled: schema.boolean({ defaultValue: false }) }),
};
```

### Mock new platform services in tests

#### Writing mocks for your plugin
Expand Down
113 changes: 83 additions & 30 deletions src/core/server/saved_objects/service/lib/filter_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ const mockMappings = {
},
},
},
alert: {
properties: {
actions: {
type: 'nested',
properties: {
group: {
type: 'keyword',
},
actionRef: {
type: 'keyword',
},
actionTypeId: {
type: 'keyword',
},
params: {
enabled: false,
type: 'object',
},
},
},
},
},
hiddenType: {
properties: {
description: {
Expand Down Expand Up @@ -108,6 +130,16 @@ describe('Filter Utils', () => {
);
});

test('Assemble filter with a nested filter', () => {
expect(
validateConvertFilterToKueryNode(
['alert'],
'alert.attributes.actions:{ actionTypeId: ".server-log" }',
mockMappings
)
).toEqual(esKuery.fromKueryExpression('alert.actions:{ actionTypeId: ".server-log" }'));
});

test('Lets make sure that we are throwing an exception if we get an error', () => {
expect(() => {
validateConvertFilterToKueryNode(
Expand All @@ -129,13 +161,13 @@ describe('Filter Utils', () => {

describe('#validateFilterKueryNode', () => {
test('Validate filter query through KueryNode - happy path', () => {
const validationObject = validateFilterKueryNode(
esKuery.fromKueryExpression(
const validationObject = validateFilterKueryNode({
astFilter: esKuery.fromKueryExpression(
'foo.updatedAt: 5678654567 and foo.attributes.bytes > 1000 and foo.attributes.bytes < 8000 and foo.attributes.title: "best" and (foo.attributes.description: t* or foo.attributes.description :*)'
),
['foo'],
mockMappings
);
types: ['foo'],
indexMapping: mockMappings,
});

expect(validationObject).toEqual([
{
Expand Down Expand Up @@ -183,14 +215,34 @@ describe('Filter Utils', () => {
]);
});

test('Validate nested filter query through KueryNode - happy path', () => {
const validationObject = validateFilterKueryNode({
astFilter: esKuery.fromKueryExpression(
'alert.attributes.actions:{ actionTypeId: ".server-log" }'
),
types: ['alert'],
indexMapping: mockMappings,
hasNestedKey: true,
});
expect(validationObject).toEqual([
{
astPath: 'arguments.1',
error: null,
isSavedObjectAttr: false,
key: 'alert.attributes.actions.actionTypeId',
type: 'alert',
},
]);
});

test('Return Error if key is not wrapper by a saved object type', () => {
const validationObject = validateFilterKueryNode(
esKuery.fromKueryExpression(
const validationObject = validateFilterKueryNode({
astFilter: esKuery.fromKueryExpression(
'updatedAt: 5678654567 and foo.attributes.bytes > 1000 and foo.attributes.bytes < 8000 and foo.attributes.title: "best" and (foo.attributes.description: t* or foo.attributes.description :*)'
),
['foo'],
mockMappings
);
types: ['foo'],
indexMapping: mockMappings,
});

expect(validationObject).toEqual([
{
Expand Down Expand Up @@ -239,13 +291,13 @@ describe('Filter Utils', () => {
});

test('Return Error if key of a saved object type is not wrapped with attributes', () => {
const validationObject = validateFilterKueryNode(
esKuery.fromKueryExpression(
const validationObject = validateFilterKueryNode({
astFilter: esKuery.fromKueryExpression(
'foo.updatedAt: 5678654567 and foo.attributes.bytes > 1000 and foo.bytes < 8000 and foo.attributes.title: "best" and (foo.attributes.description: t* or foo.description :*)'
),
['foo'],
mockMappings
);
types: ['foo'],
indexMapping: mockMappings,
});

expect(validationObject).toEqual([
{
Expand Down Expand Up @@ -296,13 +348,13 @@ describe('Filter Utils', () => {
});

test('Return Error if filter is not using an allowed type', () => {
const validationObject = validateFilterKueryNode(
esKuery.fromKueryExpression(
const validationObject = validateFilterKueryNode({
astFilter: esKuery.fromKueryExpression(
'bar.updatedAt: 5678654567 and foo.attributes.bytes > 1000 and foo.attributes.bytes < 8000 and foo.attributes.title: "best" and (foo.attributes.description: t* or foo.attributes.description :*)'
),
['foo'],
mockMappings
);
types: ['foo'],
indexMapping: mockMappings,
});

expect(validationObject).toEqual([
{
Expand Down Expand Up @@ -351,13 +403,13 @@ describe('Filter Utils', () => {
});

test('Return Error if filter is using an non-existing key in the index patterns of the saved object type', () => {
const validationObject = validateFilterKueryNode(
esKuery.fromKueryExpression(
const validationObject = validateFilterKueryNode({
astFilter: esKuery.fromKueryExpression(
'foo.updatedAt33: 5678654567 and foo.attributes.bytes > 1000 and foo.attributes.bytes < 8000 and foo.attributes.header: "best" and (foo.attributes.description: t* or foo.attributes.description :*)'
),
['foo'],
mockMappings
);
types: ['foo'],
indexMapping: mockMappings,
});

expect(validationObject).toEqual([
{
Expand Down Expand Up @@ -407,11 +459,12 @@ describe('Filter Utils', () => {
});

test('Return Error if filter is using an non-existing key null key', () => {
const validationObject = validateFilterKueryNode(
esKuery.fromKueryExpression('foo.attributes.description: hello AND bye'),
['foo'],
mockMappings
);
const validationObject = validateFilterKueryNode({
astFilter: esKuery.fromKueryExpression('foo.attributes.description: hello AND bye'),
types: ['foo'],
indexMapping: mockMappings,
});

expect(validationObject).toEqual([
{
astPath: 'arguments.0',
Expand Down
Loading

0 comments on commit 836803c

Please sign in to comment.