Skip to content

Commit

Permalink
stop magical tricks about the config type, register it as any other s…
Browse files Browse the repository at this point in the history
…o type.
  • Loading branch information
pgayvallet committed Mar 6, 2020
1 parent 579c3ca commit 4000d4e
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 62 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,6 @@ function defaultMapping(): IndexMapping {
return {
dynamic: 'strict',
properties: {
config: {
dynamic: 'true',
properties: {
buildNum: {
type: 'keyword',
},
},
},
migrationVersion: {
dynamic: 'true',
type: 'object',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ describe('IndexMigrator', () => {
dynamic: 'strict',
_meta: {
migrationMappingPropertyHashes: {
config: '87aca8fdb053154f11383fce3dbf3edf',
foo: '18c78c995965207ed3f6e7fc5c6e55fe',
migrationVersion: '4a1746014a75ade3a714e1db5763276f',
namespace: '2f4316de49999235636386fe51dc06c1',
Expand All @@ -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' },
Expand Down Expand Up @@ -180,7 +175,6 @@ describe('IndexMigrator', () => {
dynamic: 'strict',
_meta: {
migrationMappingPropertyHashes: {
config: '87aca8fdb053154f11383fce3dbf3edf',
foo: '625b32086eb1d1203564cf85062dd22e',
migrationVersion: '4a1746014a75ade3a714e1db5763276f',
namespace: '2f4316de49999235636386fe51dc06c1',
Expand All @@ -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' },
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions src/core/server/saved_objects/saved_objects_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = ({
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
});
Expand Down
3 changes: 3 additions & 0 deletions src/core/server/saved_objects/saved_objects_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -294,6 +295,8 @@ export class SavedObjectsService

this.setupDeps = setupDeps;

this.typeRegistry.registerType(configSavedObjectType);

const legacyTypes = convertLegacyTypes(
setupDeps.legacyPlugins.uiExports,
setupDeps.legacyPlugins.pluginExtendedConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ describe('SavedObjectsRepository#createRepository', () => {
expect(repository).toBeDefined();
expect(RepositoryConstructor.mock.calls[0][0].allowedTypes).toMatchInlineSnapshot(`
Array [
"config",
"nsAgnosticType",
"nsType",
]
Expand All @@ -121,7 +120,6 @@ describe('SavedObjectsRepository#createRepository', () => {
expect(repository).toBeDefined();
expect(RepositoryConstructor.mock.calls[0][0].allowedTypes).toMatchInlineSnapshot(`
Array [
"config",
"nsAgnosticType",
"nsType",
"hiddenType",
Expand Down
46 changes: 46 additions & 0 deletions src/core/server/saved_objects/so_types/config.ts
Original file line number Diff line number Diff line change
@@ -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}]`;
},
},
};
20 changes: 20 additions & 0 deletions src/core/server/saved_objects/so_types/index.ts
Original file line number Diff line number Diff line change
@@ -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';
12 changes: 0 additions & 12 deletions src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 4000d4e

Please sign in to comment.