Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/shared_fiel…
Browse files Browse the repository at this point in the history
…d_picker
  • Loading branch information
dej611 committed Jul 6, 2022
2 parents 5016bdc + bce1836 commit e125297
Show file tree
Hide file tree
Showing 318 changed files with 5,911 additions and 2,262 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ x-pack/plugins/security_solution/public/kubernetes @elastic/awp-platform

# Cloud Security Posture
/x-pack/plugins/cloud_security_posture/ @elastic/kibana-cloud-security-posture
/x-pack/plugins/security_solution/public/cloud_security_posture @elastic/kibana-cloud-security-posture

# Design (at the bottom for specificity of SASS files)
**/*.scss @elastic/kibana-design
Expand Down
2 changes: 1 addition & 1 deletion docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ the infrastructure monitoring use-case within Kibana.
|{kib-repo}blob/{branch}/x-pack/plugins/lens/readme.md[lens]
|Visualization editor allowing to quickly and easily configure compelling visualizations to use on dashboards and canvas workpads.
|Lens is a visualization editor allowing to quickly and easily configure compelling visualizations to use on dashboards and canvas workpads.
|{kib-repo}blob/{branch}/x-pack/plugins/license_api_guard/README.md[licenseApiGuard]
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"@hapi/inert": "^6.0.4",
"@hapi/wreck": "^17.1.0",
"@kbn/ace": "link:bazel-bin/packages/kbn-ace",
"@kbn/aiops-components": "link:bazel-bin/x-pack/packages/ml/aiops_components",
"@kbn/aiops-utils": "link:bazel-bin/x-pack/packages/ml/aiops_utils",
"@kbn/alerts": "link:bazel-bin/packages/kbn-alerts",
"@kbn/analytics": "link:bazel-bin/packages/kbn-analytics",
Expand Down Expand Up @@ -299,11 +300,14 @@
"cytoscape-dagre": "^2.2.2",
"d3": "3.5.17",
"d3-array": "1.2.4",
"d3-brush": "^3.0.0",
"d3-cloud": "1.2.5",
"d3-interpolate": "^3.0.1",
"d3-scale": "^2.2.2",
"d3-selection": "^3.0.0",
"d3-shape": "^1.1.0",
"d3-time": "^1.1.0",
"d3-transition": "^3.0.1",
"dedent": "^0.7.0",
"deep-freeze-strict": "^1.1.1",
"deepmerge": "^4.2.2",
Expand Down Expand Up @@ -615,11 +619,14 @@
"@types/cytoscape": "^3.14.0",
"@types/d3": "^3.5.43",
"@types/d3-array": "^1.2.7",
"@types/d3-brush": "^3.0.0",
"@types/d3-interpolate": "^2.0.0",
"@types/d3-scale": "^2.2.6",
"@types/d3-selection": "^3.0.0",
"@types/d3-shape": "^1.3.1",
"@types/d3-time": "^1.0.10",
"@types/d3-time-format": "^2.1.1",
"@types/d3-transition": "^3.0.1",
"@types/dedent": "^0.7.0",
"@types/deep-freeze-strict": "^1.1.0",
"@types/delete-empty": "^2.0.0",
Expand Down Expand Up @@ -664,6 +671,7 @@
"@types/json5": "^0.0.30",
"@types/jsonwebtoken": "^8.5.6",
"@types/kbn__ace": "link:bazel-bin/packages/kbn-ace/npm_module_types",
"@types/kbn__aiops-components": "link:bazel-bin/x-pack/packages/ml/aiops_components/npm_module_types",
"@types/kbn__aiops-utils": "link:bazel-bin/x-pack/packages/ml/aiops_utils/npm_module_types",
"@types/kbn__alerts": "link:bazel-bin/packages/kbn-alerts/npm_module_types",
"@types/kbn__analytics": "link:bazel-bin/packages/kbn-analytics/npm_module_types",
Expand Down
2 changes: 2 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ filegroup(
"//packages/shared-ux/page/kibana_no_data:build",
"//packages/shared-ux/prompt/no_data_views:build",
"//x-pack/packages/ml/agg_utils:build",
"//x-pack/packages/ml/aiops_components:build",
"//x-pack/packages/ml/aiops_utils:build",
"//x-pack/packages/ml/is_populated_object:build",
"//x-pack/packages/ml/string_hash:build",
Expand Down Expand Up @@ -338,6 +339,7 @@ filegroup(
"//packages/shared-ux/page/kibana_no_data:build_types",
"//packages/shared-ux/prompt/no_data_views:build_types",
"//x-pack/packages/ml/agg_utils:build_types",
"//x-pack/packages/ml/aiops_components:build_types",
"//x-pack/packages/ml/aiops_utils:build_types",
"//x-pack/packages/ml/is_populated_object:build_types",
"//x-pack/packages/ml/string_hash:build_types",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const CustomizablePalette = ({
</EuiFormRow>
{showRangeTypeSelector && (
<EuiFormRow
fullWidth
label={
<>
{i18n.translate('coloring.dynamicColoring.rangeType.label', {
Expand All @@ -131,6 +132,7 @@ export const CustomizablePalette = ({
display="rowCompressed"
>
<EuiButtonGroup
isFullWidth
legend={i18n.translate('coloring.dynamicColoring.rangeType.label', {
defaultMessage: 'Value type',
})}
Expand Down Expand Up @@ -169,7 +171,6 @@ export const CustomizablePalette = ({
payload: { rangeType: newRangeType, dataBounds, palettes },
});
}}
isFullWidth
/>
</EuiFormRow>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export function PalettePicker({
}
return (
<EuiColorPalettePicker
fullWidth
data-test-subj="lns-palettePicker"
compressed
palettes={palettesToShow}
Expand Down
10 changes: 5 additions & 5 deletions src/core/server/context/container/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { flatten } from 'lodash';
import { ShallowPromise, MaybePromise } from '@kbn/utility-types';
import type { PluginOpaqueId } from '@kbn/core-base-common';
import type { CoreId } from '@kbn/core-base-common-internal';
import type { RequestHandler, RequestHandlerContext } from '../..';
import type { RequestHandler, RequestHandlerContextBase } from '../..';

/**
* A function that returns a context value for a specific key of given context type.
Expand All @@ -26,7 +26,7 @@ import type { RequestHandler, RequestHandlerContext } from '../..';
* @public
*/
export type IContextProvider<
Context extends RequestHandlerContext,
Context extends RequestHandlerContextBase,
ContextName extends keyof Context
> = (
// context.core will always be available, but plugin contexts are typed as optional
Expand Down Expand Up @@ -148,7 +148,7 @@ export interface IContextContainer {
* @param provider - A {@link IContextProvider} to be called each time a new context is created.
* @returns The {@link IContextContainer} for method chaining.
*/
registerContext<Context extends RequestHandlerContext, ContextName extends keyof Context>(
registerContext<Context extends RequestHandlerContextBase, ContextName extends keyof Context>(
pluginOpaqueId: PluginOpaqueId,
contextName: ContextName,
provider: IContextProvider<Context, ContextName>
Expand Down Expand Up @@ -195,7 +195,7 @@ export class ContextContainer implements IContextContainer {
}

public registerContext = <
Context extends RequestHandlerContext,
Context extends RequestHandlerContextBase,
ContextName extends keyof Context
>(
source: symbol,
Expand Down Expand Up @@ -243,7 +243,7 @@ export class ContextContainer implements IContextContainer {
const builtContextPromises: Record<string, Promise<unknown>> = {};

const builtContext = {} as HandlerContextType<RequestHandler>;
(builtContext as unknown as RequestHandlerContext).resolve = async (keys) => {
(builtContext as unknown as RequestHandlerContextBase).resolve = async (keys) => {
const resolved = await Promise.all(
keys.map(async (key) => {
return [key, await builtContext[key]];
Expand Down
3 changes: 2 additions & 1 deletion src/core/server/core_app/core_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { HttpResources, HttpResourcesServiceToolkit } from '../http_resources';
import { InternalCorePreboot, InternalCoreSetup } from '../internal_types';
import { registerBundleRoutes } from './bundle_routes';
import { UiPlugins } from '../plugins';
import type { InternalCoreAppRequestHandlerContext } from './internal_types';

/** @internal */
interface CommonRoutesParams {
Expand Down Expand Up @@ -85,7 +86,7 @@ export class CoreApp {

private registerDefaultRoutes(coreSetup: InternalCoreSetup, uiPlugins: UiPlugins) {
const httpSetup = coreSetup.http;
const router = httpSetup.createRouter('');
const router = httpSetup.createRouter<InternalCoreAppRequestHandlerContext>('');
const resources = coreSetup.httpResources.createRegistrar(router);

router.get({ path: '/', validate: false }, async (context, req, res) => {
Expand Down
28 changes: 28 additions & 0 deletions src/core/server/core_app/internal_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 { RequestHandlerContextBase } from '..';
import type { IRouter } from '../http';
import type { UiSettingsRequestHandlerContext } from '../ui_settings';

/**
* Request handler context used by core's coreApp routes.
* @internal
*/
export interface InternalCoreAppRequestHandlerContext extends RequestHandlerContextBase {
core: Promise<{
uiSettings: UiSettingsRequestHandlerContext;
}>;
}

/**
* Router bound to the {@link InternalCoreAppRequestHandlerContext}.
* Used by core's coreApp routes.
* @internal
*/
export type InternalCoreAppRouter = IRouter<InternalCoreAppRequestHandlerContext>;
156 changes: 44 additions & 112 deletions src/core/server/core_route_handler_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,131 +6,63 @@
* Side Public License, v 1.
*/

// eslint-disable-next-line max-classes-per-file
import { InternalCoreStart } from './internal_types';
import { KibanaRequest } from './http/router';
import { SavedObjectsClientContract } from './saved_objects/types';
import type { InternalCoreStart } from './internal_types';
import type { KibanaRequest } from './http';
import {
InternalSavedObjectsServiceStart,
ISavedObjectTypeRegistry,
SavedObjectsClientProviderOptions,
CoreSavedObjectsRouteHandlerContext,
SavedObjectsRequestHandlerContext,
} from './saved_objects';
import { InternalElasticsearchServiceStart, IScopedClusterClient } from './elasticsearch';
import { InternalUiSettingsServiceStart, IUiSettingsClient } from './ui_settings';
import { DeprecationsClient, InternalDeprecationsServiceStart } from './deprecations';

class CoreElasticsearchRouteHandlerContext {
#client?: IScopedClusterClient;

constructor(
private readonly elasticsearchStart: InternalElasticsearchServiceStart,
private readonly request: KibanaRequest
) {}

public get client() {
if (this.#client == null) {
this.#client = this.elasticsearchStart.client.asScoped(this.request);
}
return this.#client;
}
}

class CoreSavedObjectsRouteHandlerContext {
constructor(
private readonly savedObjectsStart: InternalSavedObjectsServiceStart,
private readonly request: KibanaRequest
) {}
#scopedSavedObjectsClient?: SavedObjectsClientContract;
#typeRegistry?: ISavedObjectTypeRegistry;

public get client() {
if (this.#scopedSavedObjectsClient == null) {
this.#scopedSavedObjectsClient = this.savedObjectsStart.getScopedClient(this.request);
}
return this.#scopedSavedObjectsClient;
}

public get typeRegistry() {
if (this.#typeRegistry == null) {
this.#typeRegistry = this.savedObjectsStart.getTypeRegistry();
}
return this.#typeRegistry;
}

public getClient = (options?: SavedObjectsClientProviderOptions) => {
if (!options) return this.client;
return this.savedObjectsStart.getScopedClient(this.request, options);
};

public getExporter = (client: SavedObjectsClientContract) => {
return this.savedObjectsStart.createExporter(client);
};

public getImporter = (client: SavedObjectsClientContract) => {
return this.savedObjectsStart.createImporter(client);
};
}

class CoreUiSettingsRouteHandlerContext {
#client?: IUiSettingsClient;
constructor(
private readonly uiSettingsStart: InternalUiSettingsServiceStart,
private readonly savedObjectsRouterHandlerContext: CoreSavedObjectsRouteHandlerContext
) {}

public get client() {
if (this.#client == null) {
this.#client = this.uiSettingsStart.asScopedToClient(
this.savedObjectsRouterHandlerContext.client
);
}
return this.#client;
}
}

class CoreDeprecationsRouteHandlerContext {
#client?: DeprecationsClient;
constructor(
private readonly deprecationsStart: InternalDeprecationsServiceStart,
private readonly elasticsearchRouterHandlerContext: CoreElasticsearchRouteHandlerContext,
private readonly savedObjectsRouterHandlerContext: CoreSavedObjectsRouteHandlerContext
) {}

public get client() {
if (this.#client == null) {
this.#client = this.deprecationsStart.asScopedToClient(
this.elasticsearchRouterHandlerContext.client,
this.savedObjectsRouterHandlerContext.client
);
}
return this.#client;
}
import {
CoreElasticsearchRouteHandlerContext,
ElasticsearchRequestHandlerContext,
} from './elasticsearch';
import { CoreUiSettingsRouteHandlerContext, UiSettingsRequestHandlerContext } from './ui_settings';
import {
CoreDeprecationsRouteHandlerContext,
DeprecationsRequestHandlerContext,
} from './deprecations';

/**
* The `core` context provided to route handler.
*
* Provides the following clients and services:
* - {@link SavedObjectsClient | savedObjects.client} - Saved Objects client
* which uses the credentials of the incoming request
* - {@link ISavedObjectTypeRegistry | savedObjects.typeRegistry} - Type registry containing
* all the registered types.
* - {@link IScopedClusterClient | elasticsearch.client} - Elasticsearch
* data client which uses the credentials of the incoming request
* - {@link IUiSettingsClient | uiSettings.client} - uiSettings client
* which uses the credentials of the incoming request
* @public
*/
export interface CoreRequestHandlerContext {
savedObjects: SavedObjectsRequestHandlerContext;
elasticsearch: ElasticsearchRequestHandlerContext;
uiSettings: UiSettingsRequestHandlerContext;
deprecations: DeprecationsRequestHandlerContext;
}

export class CoreRouteHandlerContext {
/**
* The concrete implementation for Core's route handler context.
*
* @internal
*/
export class CoreRouteHandlerContext implements CoreRequestHandlerContext {
readonly elasticsearch: CoreElasticsearchRouteHandlerContext;
readonly savedObjects: CoreSavedObjectsRouteHandlerContext;
readonly uiSettings: CoreUiSettingsRouteHandlerContext;
readonly deprecations: CoreDeprecationsRouteHandlerContext;

constructor(
private readonly coreStart: InternalCoreStart,
private readonly request: KibanaRequest
) {
this.elasticsearch = new CoreElasticsearchRouteHandlerContext(
this.coreStart.elasticsearch,
this.request
);
this.savedObjects = new CoreSavedObjectsRouteHandlerContext(
this.coreStart.savedObjects,
this.request
);
constructor(coreStart: InternalCoreStart, request: KibanaRequest) {
this.elasticsearch = new CoreElasticsearchRouteHandlerContext(coreStart.elasticsearch, request);
this.savedObjects = new CoreSavedObjectsRouteHandlerContext(coreStart.savedObjects, request);
this.uiSettings = new CoreUiSettingsRouteHandlerContext(
this.coreStart.uiSettings,
coreStart.uiSettings,
this.savedObjects
);
this.deprecations = new CoreDeprecationsRouteHandlerContext(
this.coreStart.deprecations,
coreStart.deprecations,
this.elasticsearch,
this.savedObjects
);
Expand Down
Loading

0 comments on commit e125297

Please sign in to comment.