From 4000d4eb3aae33af5fcf2f9d43fa4ef5779a75c6 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Fri, 6 Mar 2020 14:25:06 +0100 Subject: [PATCH] stop magical tricks about the config type, register it as any other so type. --- .../build_active_mappings.test.ts.snap | 18 -------- .../migrations/core/build_active_mappings.ts | 8 ---- .../migrations/core/index_migrator.test.ts | 10 ---- .../kibana_migrator.test.ts.snap | 9 ---- .../saved_objects_service.test.ts | 16 +++++-- .../saved_objects/saved_objects_service.ts | 3 ++ .../lib/repository_create_repository.test.ts | 2 - .../server/saved_objects/so_types/config.ts | 46 +++++++++++++++++++ .../server/saved_objects/so_types/index.ts | 20 ++++++++ src/legacy/core_plugins/kibana/index.js | 12 ----- 10 files changed, 82 insertions(+), 62 deletions(-) create mode 100644 src/core/server/saved_objects/so_types/config.ts create mode 100644 src/core/server/saved_objects/so_types/index.ts diff --git a/src/core/server/saved_objects/migrations/core/__snapshots__/build_active_mappings.test.ts.snap b/src/core/server/saved_objects/migrations/core/__snapshots__/build_active_mappings.test.ts.snap index 68f90ea70a0c6..fc26d7e9cf6e9 100644 --- a/src/core/server/saved_objects/migrations/core/__snapshots__/build_active_mappings.test.ts.snap +++ b/src/core/server/saved_objects/migrations/core/__snapshots__/build_active_mappings.test.ts.snap @@ -6,7 +6,6 @@ Object { "migrationMappingPropertyHashes": Object { "aaa": "625b32086eb1d1203564cf85062dd22e", "bbb": "18c78c995965207ed3f6e7fc5c6e55fe", - "config": "87aca8fdb053154f11383fce3dbf3edf", "migrationVersion": "4a1746014a75ade3a714e1db5763276f", "namespace": "2f4316de49999235636386fe51dc06c1", "references": "7997cf5a56cc02bdc9c93361bde732b0", @@ -22,14 +21,6 @@ Object { "bbb": Object { "type": "long", }, - "config": Object { - "dynamic": "true", - "properties": Object { - "buildNum": Object { - "type": "keyword", - }, - }, - }, "migrationVersion": Object { "dynamic": "true", "type": "object", @@ -65,7 +56,6 @@ exports[`buildActiveMappings handles the \`dynamic\` property of types 1`] = ` Object { "_meta": Object { "migrationMappingPropertyHashes": Object { - "config": "87aca8fdb053154f11383fce3dbf3edf", "firstType": "635418ab953d81d93f1190b70a8d3f57", "migrationVersion": "4a1746014a75ade3a714e1db5763276f", "namespace": "2f4316de49999235636386fe51dc06c1", @@ -78,14 +68,6 @@ Object { }, "dynamic": "strict", "properties": Object { - "config": Object { - "dynamic": "true", - "properties": Object { - "buildNum": Object { - "type": "keyword", - }, - }, - }, "firstType": Object { "dynamic": "strict", "properties": Object { diff --git a/src/core/server/saved_objects/migrations/core/build_active_mappings.ts b/src/core/server/saved_objects/migrations/core/build_active_mappings.ts index 3afe8aae119d9..4d1a607414ca6 100644 --- a/src/core/server/saved_objects/migrations/core/build_active_mappings.ts +++ b/src/core/server/saved_objects/migrations/core/build_active_mappings.ts @@ -132,14 +132,6 @@ function defaultMapping(): IndexMapping { return { dynamic: 'strict', properties: { - config: { - dynamic: 'true', - properties: { - buildNum: { - type: 'keyword', - }, - }, - }, migrationVersion: { dynamic: 'true', type: 'object', diff --git a/src/core/server/saved_objects/migrations/core/index_migrator.test.ts b/src/core/server/saved_objects/migrations/core/index_migrator.test.ts index a9d0a339c229f..1c2d3f501ff80 100644 --- a/src/core/server/saved_objects/migrations/core/index_migrator.test.ts +++ b/src/core/server/saved_objects/migrations/core/index_migrator.test.ts @@ -58,7 +58,6 @@ describe('IndexMigrator', () => { dynamic: 'strict', _meta: { migrationMappingPropertyHashes: { - config: '87aca8fdb053154f11383fce3dbf3edf', foo: '18c78c995965207ed3f6e7fc5c6e55fe', migrationVersion: '4a1746014a75ade3a714e1db5763276f', namespace: '2f4316de49999235636386fe51dc06c1', @@ -68,10 +67,6 @@ describe('IndexMigrator', () => { }, }, properties: { - config: { - dynamic: 'true', - properties: { buildNum: { type: 'keyword' } }, - }, foo: { type: 'long' }, migrationVersion: { dynamic: 'true', type: 'object' }, namespace: { type: 'keyword' }, @@ -180,7 +175,6 @@ describe('IndexMigrator', () => { dynamic: 'strict', _meta: { migrationMappingPropertyHashes: { - config: '87aca8fdb053154f11383fce3dbf3edf', foo: '625b32086eb1d1203564cf85062dd22e', migrationVersion: '4a1746014a75ade3a714e1db5763276f', namespace: '2f4316de49999235636386fe51dc06c1', @@ -191,10 +185,6 @@ describe('IndexMigrator', () => { }, properties: { author: { type: 'text' }, - config: { - dynamic: 'true', - properties: { buildNum: { type: 'keyword' } }, - }, foo: { type: 'text' }, migrationVersion: { dynamic: 'true', type: 'object' }, namespace: { type: 'keyword' }, diff --git a/src/core/server/saved_objects/migrations/kibana/__snapshots__/kibana_migrator.test.ts.snap b/src/core/server/saved_objects/migrations/kibana/__snapshots__/kibana_migrator.test.ts.snap index 37a73b11bbc48..507c0b0d9339f 100644 --- a/src/core/server/saved_objects/migrations/kibana/__snapshots__/kibana_migrator.test.ts.snap +++ b/src/core/server/saved_objects/migrations/kibana/__snapshots__/kibana_migrator.test.ts.snap @@ -6,7 +6,6 @@ Object { "migrationMappingPropertyHashes": Object { "amap": "510f1f0adb69830cf8a1c5ce2923ed82", "bmap": "510f1f0adb69830cf8a1c5ce2923ed82", - "config": "87aca8fdb053154f11383fce3dbf3edf", "migrationVersion": "4a1746014a75ade3a714e1db5763276f", "namespace": "2f4316de49999235636386fe51dc06c1", "references": "7997cf5a56cc02bdc9c93361bde732b0", @@ -30,14 +29,6 @@ Object { }, }, }, - "config": Object { - "dynamic": "true", - "properties": Object { - "buildNum": Object { - "type": "keyword", - }, - }, - }, "migrationVersion": Object { "dynamic": "true", "type": "object", diff --git a/src/core/server/saved_objects/saved_objects_service.test.ts b/src/core/server/saved_objects/saved_objects_service.test.ts index 554acf8d43dcb..bc3cd154524b0 100644 --- a/src/core/server/saved_objects/saved_objects_service.test.ts +++ b/src/core/server/saved_objects/saved_objects_service.test.ts @@ -23,7 +23,7 @@ import { clientProviderInstanceMock, typeRegistryInstanceMock, } from './saved_objects_service.test.mocks'; - +import { BehaviorSubject } from 'rxjs'; import { ByteSizeValue } from '@kbn/config-schema'; import { SavedObjectsService } from './saved_objects_service'; import { mockCoreContext } from '../core_context.mock'; @@ -34,8 +34,10 @@ import { elasticsearchServiceMock } from '../elasticsearch/elasticsearch_service import { legacyServiceMock } from '../legacy/legacy_service.mock'; import { httpServiceMock } from '../http/http_service.mock'; import { SavedObjectsClientFactoryProvider } from './service/lib'; -import { BehaviorSubject } from 'rxjs'; import { NodesVersionCompatibility } from '../elasticsearch/version_check/ensure_es_version'; +import { config as configSavedObjectType } from './so_types'; + +const internalTypesCount = 1; describe('SavedObjectsService', () => { const createCoreContext = ({ @@ -69,6 +71,13 @@ describe('SavedObjectsService', () => { }); describe('#setup()', () => { + it('registers the `config` type', async () => { + const coreContext = createCoreContext(); + const soService = new SavedObjectsService(coreContext); + await soService.setup(createSetupDeps()); + expect(typeRegistryInstanceMock.registerType).toHaveBeenCalledWith(configSavedObjectType); + }); + describe('#setClientFactoryProvider', () => { it('registers the factory to the clientProvider', async () => { const coreContext = createCoreContext(); @@ -144,7 +153,8 @@ describe('SavedObjectsService', () => { }; setup.registerType(type); - expect(typeRegistryInstanceMock.registerType).toHaveBeenCalledTimes(1); + // the config type is also registered during setup + expect(typeRegistryInstanceMock.registerType).toHaveBeenCalledTimes(internalTypesCount + 1); expect(typeRegistryInstanceMock.registerType).toHaveBeenCalledWith(type); }); }); diff --git a/src/core/server/saved_objects/saved_objects_service.ts b/src/core/server/saved_objects/saved_objects_service.ts index 175eac3c1bd95..ed31563ba82c3 100644 --- a/src/core/server/saved_objects/saved_objects_service.ts +++ b/src/core/server/saved_objects/saved_objects_service.ts @@ -50,6 +50,7 @@ import { SavedObjectTypeRegistry, ISavedObjectTypeRegistry } from './saved_objec import { PropertyValidators } from './validation'; import { SavedObjectsSerializer } from './serialization'; import { registerRoutes } from './routes'; +import { config as configSavedObjectType } from './so_types'; /** * Saved Objects is Kibana's data persistence mechanism allowing plugins to @@ -294,6 +295,8 @@ export class SavedObjectsService this.setupDeps = setupDeps; + this.typeRegistry.registerType(configSavedObjectType); + const legacyTypes = convertLegacyTypes( setupDeps.legacyPlugins.uiExports, setupDeps.legacyPlugins.pluginExtendedConfig diff --git a/src/core/server/saved_objects/service/lib/repository_create_repository.test.ts b/src/core/server/saved_objects/service/lib/repository_create_repository.test.ts index 4a87bb1043ca2..a6b580e9b3461 100644 --- a/src/core/server/saved_objects/service/lib/repository_create_repository.test.ts +++ b/src/core/server/saved_objects/service/lib/repository_create_repository.test.ts @@ -102,7 +102,6 @@ describe('SavedObjectsRepository#createRepository', () => { expect(repository).toBeDefined(); expect(RepositoryConstructor.mock.calls[0][0].allowedTypes).toMatchInlineSnapshot(` Array [ - "config", "nsAgnosticType", "nsType", ] @@ -121,7 +120,6 @@ describe('SavedObjectsRepository#createRepository', () => { expect(repository).toBeDefined(); expect(RepositoryConstructor.mock.calls[0][0].allowedTypes).toMatchInlineSnapshot(` Array [ - "config", "nsAgnosticType", "nsType", "hiddenType", diff --git a/src/core/server/saved_objects/so_types/config.ts b/src/core/server/saved_objects/so_types/config.ts new file mode 100644 index 0000000000000..c02d76a162df3 --- /dev/null +++ b/src/core/server/saved_objects/so_types/config.ts @@ -0,0 +1,46 @@ +/* + * 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 { SavedObjectsType } from '../types'; + +export const config: SavedObjectsType = { + name: 'config', + hidden: false, + namespaceAgnostic: false, + mappings: { + dynamic: true as any, // TODO: check if can be switched to false, else adapt the type to allow true + properties: { + buildNum: { + type: 'keyword', + }, + }, + }, + management: { + importableAndExportable: true, + getInAppUrl() { + return { + path: `/app/kibana#/management/kibana/settings`, + uiCapabilitiesPath: 'advancedSettings.show', + }; + }, + getTitle(obj) { + return `Advanced Settings [${obj.id}]`; + }, + }, +}; diff --git a/src/core/server/saved_objects/so_types/index.ts b/src/core/server/saved_objects/so_types/index.ts new file mode 100644 index 0000000000000..610f168f75b10 --- /dev/null +++ b/src/core/server/saved_objects/so_types/index.ts @@ -0,0 +1,20 @@ +/* + * 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 { config } from './config'; diff --git a/src/legacy/core_plugins/kibana/index.js b/src/legacy/core_plugins/kibana/index.js index 221133a17d59a..092eed924f330 100644 --- a/src/legacy/core_plugins/kibana/index.js +++ b/src/legacy/core_plugins/kibana/index.js @@ -201,18 +201,6 @@ export default function(kibana) { return `/goto/${encodeURIComponent(obj.id)}`; }, }, - config: { - isImportableAndExportable: true, - getInAppUrl() { - return { - path: `/app/kibana#/management/kibana/settings`, - uiCapabilitiesPath: 'advancedSettings.show', - }; - }, - getTitle(obj) { - return `Advanced Settings [${obj.id}]`; - }, - }, }, savedObjectSchemas: {