-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Deprecations service] add
deprecationType
and use it in configs de…
…precations (#100983)
- Loading branch information
Showing
14 changed files
with
204 additions
and
10 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...nt/core/server/kibana-plugin-core-server.deprecationsdetails.deprecationtype.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,15 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [DeprecationsDetails](./kibana-plugin-core-server.deprecationsdetails.md) > [deprecationType](./kibana-plugin-core-server.deprecationsdetails.deprecationtype.md) | ||
|
||
## DeprecationsDetails.deprecationType property | ||
|
||
(optional) Used to identify between different deprecation types. Example use case: in Upgrade Assistant, we may want to allow the user to sort by deprecation type or show each type in a separate tab. | ||
|
||
Feel free to add new types if necessary. Predefined types are necessary to reduce having similar definitions with different keywords across kibana deprecations. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
deprecationType?: 'config' | 'feature'; | ||
``` |
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,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { PublicMethodsOf } from '@kbn/utility-types'; | ||
import type { DeprecationsFactory } from './deprecations_factory'; | ||
type DeprecationsFactoryContract = PublicMethodsOf<DeprecationsFactory>; | ||
|
||
const createDeprecationsFactoryMock = () => { | ||
const mocked: jest.Mocked<DeprecationsFactoryContract> = { | ||
getRegistry: jest.fn(), | ||
getDeprecations: jest.fn(), | ||
getAllDeprecations: jest.fn(), | ||
}; | ||
|
||
mocked.getDeprecations.mockResolvedValue([]); | ||
mocked.getAllDeprecations.mockResolvedValue([]); | ||
return mocked as jest.Mocked<DeprecationsFactory>; | ||
}; | ||
|
||
export const mockDeprecationsFactory = { | ||
create: createDeprecationsFactoryMock, | ||
}; |
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
37 changes: 37 additions & 0 deletions
37
src/core/server/deprecations/deprecations_registry.mock.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,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { PublicMethodsOf } from '@kbn/utility-types'; | ||
import type { DeprecationsRegistry } from './deprecations_registry'; | ||
import type { GetDeprecationsContext } from './types'; | ||
import { elasticsearchClientMock } from '../elasticsearch/client/mocks'; | ||
import { savedObjectsClientMock } from '../saved_objects/service/saved_objects_client.mock'; | ||
type DeprecationsRegistryContract = PublicMethodsOf<DeprecationsRegistry>; | ||
|
||
const createDeprecationsRegistryMock = () => { | ||
const mocked: jest.Mocked<DeprecationsRegistryContract> = { | ||
registerDeprecations: jest.fn(), | ||
getDeprecations: jest.fn(), | ||
}; | ||
|
||
return mocked as jest.Mocked<DeprecationsRegistry>; | ||
}; | ||
|
||
const createGetDeprecationsContextMock = () => { | ||
const mocked: jest.Mocked<GetDeprecationsContext> = { | ||
esClient: elasticsearchClientMock.createScopedClusterClient(), | ||
savedObjectsClient: savedObjectsClientMock.create(), | ||
}; | ||
|
||
return mocked; | ||
}; | ||
|
||
export const mockDeprecationsRegistry = { | ||
create: createDeprecationsRegistryMock, | ||
createGetDeprecationsContext: createGetDeprecationsContextMock, | ||
}; |
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,99 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/* eslint-disable dot-notation */ | ||
import { DeprecationsService } from './deprecations_service'; | ||
import { httpServiceMock } from '../http/http_service.mock'; | ||
import { mockRouter } from '../http/router/router.mock'; | ||
import { mockCoreContext } from '../core_context.mock'; | ||
import { mockDeprecationsFactory } from './deprecations_factory.mock'; | ||
import { mockDeprecationsRegistry } from './deprecations_registry.mock'; | ||
|
||
describe('DeprecationsService', () => { | ||
const coreContext = mockCoreContext.create(); | ||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
describe('#setup', () => { | ||
const http = httpServiceMock.createInternalSetupContract(); | ||
const router = mockRouter.create(); | ||
http.createRouter.mockReturnValue(router); | ||
const deprecationsCoreSetupDeps = { http }; | ||
|
||
it('registers routes', () => { | ||
const deprecationsService = new DeprecationsService(coreContext); | ||
deprecationsService.setup(deprecationsCoreSetupDeps); | ||
// Registers correct base api path | ||
expect(http.createRouter).toBeCalledWith('/api/deprecations'); | ||
// registers get route '/' | ||
expect(router.get).toHaveBeenCalledTimes(1); | ||
expect(router.get).toHaveBeenCalledWith({ path: '/', validate: false }, expect.any(Function)); | ||
}); | ||
|
||
it('calls registerConfigDeprecationsInfo', () => { | ||
const deprecationsService = new DeprecationsService(coreContext); | ||
const mockRegisterConfigDeprecationsInfo = jest.fn(); | ||
deprecationsService['registerConfigDeprecationsInfo'] = mockRegisterConfigDeprecationsInfo; | ||
deprecationsService.setup(deprecationsCoreSetupDeps); | ||
expect(mockRegisterConfigDeprecationsInfo).toBeCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('#registerConfigDeprecationsInfo', () => { | ||
const deprecationsFactory = mockDeprecationsFactory.create(); | ||
const deprecationsRegistry = mockDeprecationsRegistry.create(); | ||
const getDeprecationsContext = mockDeprecationsRegistry.createGetDeprecationsContext(); | ||
|
||
it('registers config deprecations', () => { | ||
const deprecationsService = new DeprecationsService(coreContext); | ||
coreContext.configService.getHandledDeprecatedConfigs.mockReturnValue([ | ||
[ | ||
'testDomain', | ||
[ | ||
{ | ||
message: 'testMessage', | ||
documentationUrl: 'testDocUrl', | ||
correctiveActions: { | ||
manualSteps: [ | ||
'Using Kibana user management, change all users using the kibana_user role to the kibana_admin role.', | ||
'Using Kibana role-mapping management, change all role-mappings which assing the kibana_user role to the kibana_admin role.', | ||
], | ||
}, | ||
}, | ||
], | ||
], | ||
]); | ||
|
||
deprecationsFactory.getRegistry.mockReturnValue(deprecationsRegistry); | ||
deprecationsService['registerConfigDeprecationsInfo'](deprecationsFactory); | ||
|
||
expect(coreContext.configService.getHandledDeprecatedConfigs).toBeCalledTimes(1); | ||
expect(deprecationsFactory.getRegistry).toBeCalledTimes(1); | ||
expect(deprecationsFactory.getRegistry).toBeCalledWith('testDomain'); | ||
expect(deprecationsRegistry.registerDeprecations).toBeCalledTimes(1); | ||
const configDeprecations = deprecationsRegistry.registerDeprecations.mock.calls[0][0].getDeprecations( | ||
getDeprecationsContext | ||
); | ||
expect(configDeprecations).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"correctiveActions": Object { | ||
"manualSteps": Array [ | ||
"Using Kibana user management, change all users using the kibana_user role to the kibana_admin role.", | ||
"Using Kibana role-mapping management, change all role-mappings which assing the kibana_user role to the kibana_admin role.", | ||
], | ||
}, | ||
"deprecationType": "config", | ||
"documentationUrl": "testDocUrl", | ||
"level": "critical", | ||
"message": "testMessage", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); | ||
}); |
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