Skip to content

Commit

Permalink
Merge branch 'master' into adding-kibana-setting-for-max-file-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Apr 27, 2020
2 parents 93d24d6 + dfb6a30 commit bafad91
Show file tree
Hide file tree
Showing 83 changed files with 1,646 additions and 293 deletions.
3 changes: 2 additions & 1 deletion docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,14 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [SavedObjectAttribute](./kibana-plugin-core-server.savedobjectattribute.md) | Type definition for a Saved Object attribute value |
| [SavedObjectAttributeSingle](./kibana-plugin-core-server.savedobjectattributesingle.md) | Don't use this type, it's simply a helper type for [SavedObjectAttribute](./kibana-plugin-core-server.savedobjectattribute.md) |
| [SavedObjectMigrationFn](./kibana-plugin-core-server.savedobjectmigrationfn.md) | A migration function for a [saved object type](./kibana-plugin-core-server.savedobjectstype.md) used to migrate it to a given version |
| [SavedObjectSanitizedDoc](./kibana-plugin-core-server.savedobjectsanitizeddoc.md) | |
| [SavedObjectSanitizedDoc](./kibana-plugin-core-server.savedobjectsanitizeddoc.md) | Describes Saved Object documents that have passed through the migration framework and are guaranteed to have a <code>references</code> root property. |
| [SavedObjectsClientContract](./kibana-plugin-core-server.savedobjectsclientcontract.md) | Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state.<!-- -->\#\# SavedObjectsClient errors<!-- -->Since the SavedObjectsClient has its hands in everything we are a little paranoid about the way we present errors back to to application code. Ideally, all errors will be either:<!-- -->1. Caused by bad implementation (ie. undefined is not a function) and as such unpredictable 2. An error that has been classified and decorated appropriately by the decorators in [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md)<!-- -->Type 1 errors are inevitable, but since all expected/handle-able errors should be Type 2 the <code>isXYZError()</code> helpers exposed at <code>SavedObjectsErrorHelpers</code> should be used to understand and manage error responses from the <code>SavedObjectsClient</code>.<!-- -->Type 2 errors are decorated versions of the source error, so if the elasticsearch client threw an error it will be decorated based on its type. That means that rather than looking for <code>error.body.error.type</code> or doing substring checks on <code>error.body.error.reason</code>, just use the helpers to understand the meaning of the error:<!-- -->\`\`\`<!-- -->js if (SavedObjectsErrorHelpers.isNotFoundError(error)) { // handle 404 }<!-- -->if (SavedObjectsErrorHelpers.isNotAuthorizedError(error)) { // 401 handling should be automatic, but in case you wanted to know }<!-- -->// always rethrow the error unless you handle it throw error; \`\`\`<!-- -->\#\#\# 404s from missing index<!-- -->From the perspective of application code and APIs the SavedObjectsClient is a black box that persists objects. One of the internal details that users have no control over is that we use an elasticsearch index for persistance and that index might be missing.<!-- -->At the time of writing we are in the process of transitioning away from the operating assumption that the SavedObjects index is always available. Part of this transition is handling errors resulting from an index missing. These used to trigger a 500 error in most cases, and in others cause 404s with different error messages.<!-- -->From my (Spencer) perspective, a 404 from the SavedObjectsApi is a 404; The object the request/call was targeting could not be found. This is why \#14141 takes special care to ensure that 404 errors are generic and don't distinguish between index missing or document missing.<!-- -->See [SavedObjectsClient](./kibana-plugin-core-server.savedobjectsclient.md) See [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md) |
| [SavedObjectsClientFactory](./kibana-plugin-core-server.savedobjectsclientfactory.md) | Describes the factory used to create instances of the Saved Objects Client. |
| [SavedObjectsClientFactoryProvider](./kibana-plugin-core-server.savedobjectsclientfactoryprovider.md) | Provider to invoke to retrieve a [SavedObjectsClientFactory](./kibana-plugin-core-server.savedobjectsclientfactory.md)<!-- -->. |
| [SavedObjectsClientWrapperFactory](./kibana-plugin-core-server.savedobjectsclientwrapperfactory.md) | Describes the factory used to create instances of Saved Objects Client Wrappers. |
| [SavedObjectsFieldMapping](./kibana-plugin-core-server.savedobjectsfieldmapping.md) | Describe a [saved object type mapping](./kibana-plugin-core-server.savedobjectstypemappingdefinition.md) field.<!-- -->Please refer to [elasticsearch documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html) For the mapping documentation |
| [SavedObjectsNamespaceType](./kibana-plugin-core-server.savedobjectsnamespacetype.md) | The namespace type dictates how a saved object can be interacted in relation to namespaces. Each type is mutually exclusive: \* single (default): this type of saved object is namespace-isolated, e.g., it exists in only one namespace. \* multiple: this type of saved object is shareable, e.g., it can exist in one or more namespaces. \* agnostic: this type of saved object is global.<!-- -->Note: do not write logic that uses this value directly; instead, use the appropriate accessors in the [type registry](./kibana-plugin-core-server.savedobjecttyperegistry.md)<!-- -->. |
| [SavedObjectUnsanitizedDoc](./kibana-plugin-core-server.savedobjectunsanitizeddoc.md) | Describes Saved Object documents from Kibana &lt; 7.0.0 which don't have a <code>references</code> root property defined. This type should only be used in migrations. |
| [ScopeableRequest](./kibana-plugin-core-server.scopeablerequest.md) | A user credentials container. It accommodates the necessary auth credentials to impersonate the current user.<!-- -->See [KibanaRequest](./kibana-plugin-core-server.kibanarequest.md)<!-- -->. |
| [ServiceStatusLevel](./kibana-plugin-core-server.servicestatuslevel.md) | A convenience type that represents the union of each value in [ServiceStatusLevels](./kibana-plugin-core-server.servicestatuslevels.md)<!-- -->. |
| [SharedGlobalConfig](./kibana-plugin-core-server.sharedglobalconfig.md) | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## SavedObjectSanitizedDoc type

Describes Saved Object documents that have passed through the migration framework and are guaranteed to have a `references` root property.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectUnsanitizedDoc](./kibana-plugin-core-server.savedobjectunsanitizeddoc.md)

## SavedObjectUnsanitizedDoc type

Describes Saved Object documents from Kibana &lt; 7.0.0 which don't have a `references` root property defined. This type should only be used in migrations.

<b>Signature:</b>

```typescript
export declare type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial<Referencable>;
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"**/@types/hapi": "^17.0.18",
"**/@types/angular": "^1.6.56",
"**/@types/hoist-non-react-statics": "^3.3.1",
"**/@types/chai": "^4.2.11",
"**/typescript": "3.7.2",
"**/graphql-toolkit/lodash": "^4.17.13",
"**/hoist-non-react-statics": "^3.3.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ describe('DocumentMigrator', () => {
expect(_.get(migratedDoc, 'attributes.name')).toBe('Mike');
});

it('migrates meta properties', () => {
it('migrates root properties', () => {
const migrator = new DocumentMigrator({
...testOpts(),
typeRegistry: createRegistry({
name: 'acl',
migrations: {
'2.3.5': setAttr('acl', 'admins-only,sucka!'),
'2.3.5': setAttr('acl', 'admins-only, sucka!'),
},
}),
});
Expand All @@ -165,13 +165,13 @@ describe('DocumentMigrator', () => {
attributes: { name: 'Tyler' },
acl: 'anyone',
migrationVersion: {},
});
} as SavedObjectUnsanitizedDoc);
expect(actual).toEqual({
id: 'me',
type: 'user',
attributes: { name: 'Tyler' },
migrationVersion: { acl: '2.3.5' },
acl: 'admins-only,sucka!',
acl: 'admins-only, sucka!',
});
});

Expand Down Expand Up @@ -241,7 +241,7 @@ describe('DocumentMigrator', () => {
type: 'user',
attributes: { name: 'Tyler' },
bbb: 'Shazm',
});
} as SavedObjectUnsanitizedDoc);
expect(actual).toEqual({
id: 'me',
type: 'user',
Expand Down Expand Up @@ -405,7 +405,7 @@ describe('DocumentMigrator', () => {
attributes: { name: 'Callie' },
dawg: 'Yo',
migrationVersion: {},
});
} as SavedObjectUnsanitizedDoc);
expect(actual).toEqual({
id: 'smelly',
type: 'foo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function props(doc: SavedObjectUnsanitizedDoc) {
*/
function propVersion(doc: SavedObjectUnsanitizedDoc | ActiveMigrations, prop: string) {
return (
(doc[prop] && doc[prop].latestVersion) ||
((doc as any)[prop] && (doc as any)[prop].latestVersion) ||
(doc.migrationVersion && (doc as any).migrationVersion[prop])
);
}
Expand Down
21 changes: 10 additions & 11 deletions src/core/server/saved_objects/serialization/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ export interface SavedObjectsRawDocSource {
}

/**
* A saved object type definition that allows for miscellaneous, unknown
* properties, as current discussions around security, ACLs, etc indicate
* that future props are likely to be added. Migrations support this
* scenario out of the box.
* Saved Object base document
*/
interface SavedObjectDoc {
attributes: any;
Expand All @@ -59,23 +56,25 @@ interface SavedObjectDoc {
migrationVersion?: SavedObjectsMigrationVersion;
version?: string;
updated_at?: string;

[rootProp: string]: any;
}

interface Referencable {
references: SavedObjectReference[];
}

/**
* We want to have two types, one that guarantees a "references" attribute
* will exist and one that allows it to be null. Since we're not migrating
* all the saved objects to have a "references" array, we need to support
* the scenarios where it may be missing (ex migrations).
* Describes Saved Object documents from Kibana < 7.0.0 which don't have a
* `references` root property defined. This type should only be used in
* migrations.
*
* @public
*/
export type SavedObjectUnsanitizedDoc = SavedObjectDoc & Partial<Referencable>;

/** @public */
/**
* Describes Saved Object documents that have passed through the migration
* framework and are guaranteed to have a `references` root property.
*
* @public
*/
export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;
2 changes: 1 addition & 1 deletion src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ export interface SavedObjectsAddToNamespacesOptions extends SavedObjectsBaseOpti
// Warning: (ae-forgotten-export) The symbol "SavedObjectDoc" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Referencable" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
// @public
export type SavedObjectSanitizedDoc = SavedObjectDoc & Referencable;

// @public (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion src/dev/run_check_published_api_changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async function run(
Options:
--accept {dim Accepts all changes by updating the API Review files and documentation}
--docs {dim Updates the Core API documentation}
--only {dim RegExp that folder names must match, folders: [${folders.join(', ')}]}
--filter {dim RegExp that folder names must match, folders: [${folders.join(', ')}]}
--help {dim Show this message}
`)
);
Expand Down
4 changes: 2 additions & 2 deletions src/es_archiver/actions/rebuild_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { resolve, dirname, relative } from 'path';
import { stat, rename, createReadStream, createWriteStream } from 'fs';
import { stat, Stats, rename, createReadStream, createWriteStream } from 'fs';
import { Readable, Writable } from 'stream';
import { fromNode } from 'bluebird';
import { ToolingLog } from '@kbn/dev-utils';
Expand All @@ -33,7 +33,7 @@ import {
} from '../lib';

async function isDirectory(path: string): Promise<boolean> {
const stats = await fromNode(cb => stat(path, cb));
const stats: Stats = await fromNode(cb => stat(path, cb));
return stats.isDirectory();
}

Expand Down
65 changes: 0 additions & 65 deletions src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,6 @@ export default function(kibana) {
},
],

savedObjectsManagement: {
url: {
defaultSearchField: 'url',
isImportableAndExportable: true,
getTitle(obj) {
return `/goto/${encodeURIComponent(obj.id)}`;
},
},
},

injectDefaultVars(server, options) {
const mapConfig = server.config().get('map');
const tilemap = mapConfig.tilemap;
Expand All @@ -152,61 +142,6 @@ export default function(kibana) {
uiSettingDefaults: getUiSettingDefaults(),
},

uiCapabilities: async function() {
return {
discover: {
show: true,
createShortUrl: true,
save: true,
saveQuery: true,
},
visualize: {
show: true,
createShortUrl: true,
delete: true,
save: true,
saveQuery: true,
},
dashboard: {
createNew: true,
show: true,
showWriteControls: true,
saveQuery: true,
},
catalogue: {
discover: true,
dashboard: true,
visualize: true,
console: true,
advanced_settings: true,
index_patterns: true,
},
advancedSettings: {
show: true,
save: true,
},
indexPatterns: {
save: true,
},
savedObjectsManagement: {
delete: true,
edit: true,
read: true,
},
management: {
/*
* Management settings correspond to management section/link ids, and should not be changed
* without also updating those definitions.
*/
kibana: {
settings: true,
index_patterns: true,
objects: true,
},
},
};
},

preInit: async function(server) {
try {
// Create the data directory (recursively, if the a parent dir doesn't exist).
Expand Down
22 changes: 0 additions & 22 deletions src/legacy/core_plugins/kibana/mappings.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
{
"url": {
"properties": {
"accessCount": {
"type": "long"
},
"accessDate": {
"type": "date"
},
"createDate": {
"type": "date"
},
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 2048
}
}
}
}
},
"server": {
"properties": {
"uuid": {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/advanced_settings/kibana.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "advancedSettings",
"version": "kibana",
"server": false,
"server": true,
"ui": true,
"requiredPlugins": ["management"]
}
25 changes: 25 additions & 0 deletions src/plugins/advanced_settings/server/capabilities_provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

export const capabilitiesProvider = () => ({
advancedSettings: {
show: true,
save: true,
},
});
24 changes: 24 additions & 0 deletions src/plugins/advanced_settings/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { PluginInitializerContext } from 'kibana/server';
import { AdvancedSettingsServerPlugin } from './plugin';

export const plugin = (initContext: PluginInitializerContext) =>
new AdvancedSettingsServerPlugin(initContext);
44 changes: 44 additions & 0 deletions src/plugins/advanced_settings/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 { PluginInitializerContext, CoreSetup, CoreStart, Plugin, Logger } from 'kibana/server';
import { capabilitiesProvider } from './capabilities_provider';

export class AdvancedSettingsServerPlugin implements Plugin<object, object> {
private readonly logger: Logger;

constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
}

public setup(core: CoreSetup) {
this.logger.debug('advancedSettings: Setup');

core.capabilities.registerProvider(capabilitiesProvider);

return {};
}

public start(core: CoreStart) {
this.logger.debug('advancedSettings: Started');
return {};
}

public stop() {}
}
Loading

0 comments on commit bafad91

Please sign in to comment.