Change ContextContainer to lazily initialize providers (#129896)

* Change ContextContainer to lazily initialize providers

* Introduce CustomRequestHandlerContext, start adapting usages

* adapt IContextProvider's return type

* start fixing violations

* fixing violations - 2

* adapt home routes

* fix remaining core violation

* fix violations on core tests

* fixing more violations

* fixing more violations

* update generated doc...

* fix more violations

* adapt remaining RequestHandlerContext

* fix more violations

* fix non-async method

* more fixes

* fix another await in non async method

* add yet another missing async

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* add yet yet another missing async

* update fleet's endpoints

* fix telemetry endpoints

* fix event_log endpoints

* fix some security unit tests

* adapt canvas routes

* adapt alerting routes

* adapt more so_tagging routes

* fix data_enhanced routes

* fix license_management routes

* fix file_upload routes

* fix index_management routes

* fix lists routes

* fix snapshot_restore routes

* fix rule_registry routes

* fix ingest_pipelines routes

* fix remote_clusters routes

* fix index_lifecycle_management routes

* improve and fix the lazy implementation

* fix triggers_actions_ui endpoints

* start fixing unit tests

* fix cases routes

* fix transform routes

* fix upgrade_assistant routes

* fix uptime route wrapper

* fix uptime route wrapper bis

* update osquery routes

* update cross_cluster_replication routes

* fix some ML routes / wrappers

* adapt maps routes

* adapt rollup routes

* fix some canvas unit tests

* fix more canvas unit tests

* fix observability wrapper

* fix (?) infra type hell

* start fixing monitoring

* fix a few test plugins

* woups

* fix yet more violations

* fixing UA  tests

* fix logstash handlers

* fix fleet unit tests

* lint?

* one more batch

* update security_solution endpoints

* start fixing security_solution mocks

* start fixing security_solution tests

* fix more security_solution tests

* fix more security_solution tests

* just one more

* fix last (?) security_solution tests

* fix timelion javascript file

* fix more test plugins

* fix transforms context type

* fix ml context type

* fix context tests

* fix securitySolution withEndpointAuthz tests

* fix features unit tests

* fix actions unit tests

* fix imports

* fix duplicate import

* fix some merge problems

* fix new usage

* fix new test

* introduces context.resolve

* down the rabbit hole again

* start fixing test type failures

* more test type failures fixes

* move import comment back to correct place

* more test type failures fixes, bis

* use context.resolve for security solution rules routes

* fix new violations due to master merge

* remove comment

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Pierre Gayvallet 2022-04-22 13:15:58 +02:00 committed by GitHub
parent 706d9268ef
commit a02c00b8a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
699 changed files with 4508 additions and 3170 deletions

View file

@ -15,10 +15,9 @@ import { RequestHandler } from '@kbn/core/server';
import { FeatureKibanaPrivileges, KibanaFeatureConfig, SubFeatureConfig } from '../../common';
function createContextMock(licenseType: LicenseType = 'platinum') {
return {
core: coreMock.createRequestHandlerContext(),
return coreMock.createCustomRequestHandlerContext({
licensing: licensingMock.createRequestHandlerContext({ license: { type: licenseType } }),
};
});
}
function createPrivilege(partial: Partial<FeatureKibanaPrivileges> = {}): FeatureKibanaPrivileges {
@ -138,7 +137,7 @@ describe('GET /api/features', () => {
it('returns a list of available features, sorted by their configured order', async () => {
const mockResponse = httpServerMock.createResponseFactory();
routeHandler(createContextMock(), { query: {} } as any, mockResponse);
await routeHandler(createContextMock(), { query: {} } as any, mockResponse);
expect(mockResponse.ok).toHaveBeenCalledTimes(1);
const [call] = mockResponse.ok.mock.calls;
@ -173,7 +172,7 @@ describe('GET /api/features', () => {
it(`by default does not return features that arent allowed by current license`, async () => {
const mockResponse = httpServerMock.createResponseFactory();
routeHandler(createContextMock('basic'), { query: {} } as any, mockResponse);
await routeHandler(createContextMock('basic'), { query: {} } as any, mockResponse);
expect(mockResponse.ok).toHaveBeenCalledTimes(1);
const [call] = mockResponse.ok.mock.calls;
@ -204,7 +203,7 @@ describe('GET /api/features', () => {
it(`ignoreValidLicenses=false does not return features that arent allowed by current license`, async () => {
const mockResponse = httpServerMock.createResponseFactory();
routeHandler(
await routeHandler(
createContextMock('basic'),
{ query: { ignoreValidLicenses: false } } as any,
mockResponse
@ -239,7 +238,7 @@ describe('GET /api/features', () => {
it(`ignoreValidLicenses=true returns features that arent allowed by current license`, async () => {
const mockResponse = httpServerMock.createResponseFactory();
routeHandler(
await routeHandler(
createContextMock('basic'),
{ query: { ignoreValidLicenses: true } } as any,
mockResponse

View file

@ -26,8 +26,8 @@ export function defineRoutes({ router, featureRegistry }: RouteDefinitionParams)
query: schema.object({ ignoreValidLicenses: schema.boolean({ defaultValue: false }) }),
},
},
(context, request, response) => {
const currentLicense = context.licensing!.license;
async (context, request, response) => {
const { license: currentLicense } = await context.licensing;
const allFeatures = featureRegistry.getAllKibanaFeatures(
currentLicense,

View file

@ -5,15 +5,15 @@
* 2.0.
*/
import type { RequestHandlerContext, IRouter } from '@kbn/core/server';
import type { CustomRequestHandlerContext, IRouter } from '@kbn/core/server';
import type { LicensingApiRequestHandlerContext } from '@kbn/licensing-plugin/server';
/**
* @internal
*/
export interface FeaturesRequestHandlerContext extends RequestHandlerContext {
export type FeaturesRequestHandlerContext = CustomRequestHandlerContext<{
licensing: LicensingApiRequestHandlerContext;
}
}>;
/**
* @internal