mirror of
https://github.com/elastic/kibana.git
synced 2025-04-18 23:21:39 -04:00
## Summary Start relocating Kibana modules (packages and plugins) to the new folder structure, according to the _Kibana Sustainable Architecture_ initiative. #### 16 plugin(s) are going to be relocated: | Id | Target folder | | -- | ------------- | | `@kbn/cloud-chat-plugin` | `x-pack/platform/plugins/private/cloud_integrations/cloud_chat` | | `@kbn/cloud-experiments-plugin` | `x-pack/platform/plugins/shared/cloud_integrations/cloud_experiments` | | `@kbn/cloud-full-story-plugin` | `x-pack/platform/plugins/private/cloud_integrations/cloud_full_story` | | `@kbn/cloud-links-plugin` | `x-pack/platform/plugins/private/cloud_integrations/cloud_links` | | `@kbn/cloud-plugin` | `x-pack/platform/plugins/shared/cloud` | | `@kbn/features-plugin` | `x-pack/platform/plugins/shared/features` | | `@kbn/ftr-apis-plugin` | `src/platform/plugins/private/ftr_apis` | | `@kbn/kibana-usage-collection-plugin` | `src/platform/plugins/private/kibana_usage_collection` | | `@kbn/licensing-plugin` | `x-pack/platform/plugins/shared/licensing` | | `@kbn/newsfeed-plugin` | `src/platform/plugins/shared/newsfeed` | | `@kbn/saved-objects-management-plugin` | `src/platform/plugins/shared/saved_objects_management` | | `@kbn/telemetry-collection-manager-plugin` | `src/platform/plugins/shared/telemetry_collection_manager` | | `@kbn/telemetry-collection-xpack-plugin` | `x-pack/platform/plugins/private/telemetry_collection_xpack` | | `@kbn/telemetry-management-section-plugin` | `src/platform/plugins/shared/telemetry_management_section` | | `@kbn/telemetry-plugin` | `src/platform/plugins/shared/telemetry` | | `@kbn/usage-collection-plugin` | `src/platform/plugins/shared/usage_collection` | #### 22 package(s) are going to be relocated: | Id | Target folder | | -- | ------------- | | `@kbn/analytics` | `src/platform/packages/shared/kbn-analytics` | | `@kbn/analytics-collection-utils` | `src/platform/packages/private/analytics/utils/analytics_collection_utils` | | `@kbn/apm-config-loader` | `src/platform/packages/private/kbn-apm-config-loader` | | `@kbn/cloud` | `src/platform/packages/shared/cloud` | | `@kbn/config` | `src/platform/packages/shared/kbn-config` | | `@kbn/config-mocks` | `src/platform/packages/private/kbn-config-mocks` | | `@kbn/config-schema` | `src/platform/packages/shared/kbn-config-schema` | | `@kbn/crypto-browser` | `src/platform/packages/shared/kbn-crypto-browser` | | `@kbn/ebt-tools` | `src/platform/packages/shared/kbn-ebt-tools` | | `@kbn/es-errors` | `src/platform/packages/shared/kbn-es-errors` | | `@kbn/es-types` | `src/platform/packages/shared/kbn-es-types` | | `@kbn/hapi-mocks` | `src/platform/packages/private/kbn-hapi-mocks` | | `@kbn/health-gateway-server` | `src/platform/packages/private/kbn-health-gateway-server` | | `@kbn/i18n` | `src/platform/packages/shared/kbn-i18n` | | `@kbn/i18n-react` | `src/platform/packages/shared/kbn-i18n-react` | | `@kbn/logging` | `src/platform/packages/shared/kbn-logging` | | `@kbn/logging-mocks` | `src/platform/packages/shared/kbn-logging-mocks` | | `@kbn/router-to-openapispec` | `src/platform/packages/shared/kbn-router-to-openapispec` | | `@kbn/server-http-tools` | `src/platform/packages/shared/kbn-server-http-tools` | | `@kbn/std` | `src/platform/packages/shared/kbn-std` | | `@kbn/utility-types` | `src/platform/packages/shared/kbn-utility-types` | | `@kbn/zod` | `src/platform/packages/shared/kbn-zod` | --------- Co-authored-by: Alejandro Fernández Haro <alejandro.haro@elastic.co> Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
57 lines
2.3 KiB
Text
57 lines
2.3 KiB
Text
[[patterns]]
|
|
== Patterns
|
|
[[scoped-services]]
|
|
=== Scoped services
|
|
Whenever Kibana needs to get access to data saved in Elasticsearch, it
|
|
should perform a check whether an end-user has access to the data.
|
|
The Kibana Platform introduced a handler interface on the server-side to perform that association
|
|
internally. Core services, that require impersonation with an incoming
|
|
request, are exposed via `context` argument of
|
|
{kib-repo}/blob/8.9/src/core/packages/http/server/src/router/request_handler.ts[the request handler interface].
|
|
|
|
[source,js]
|
|
----
|
|
async function handler(context, req, res) {
|
|
const data = await context.core.elasticsearch.client.asCurrentUser('ping');
|
|
}
|
|
----
|
|
|
|
The {kib-repo}/blob/8.9/src/core/packages/http/server/src/router/request_handler.ts[request handler context] exposes the following scoped *core* services:
|
|
|
|
* {kib-repo}/blob/8.9/src/core/packages/saved-objects/api-server/src/saved_objects_client.ts[`context.savedObjects.client`]
|
|
* {kib-repo}/blob/8.9/src/core/packages/elasticsearch/server/src/client/scoped_cluster_client.ts[`context.elasticsearch.client`]
|
|
* {kib-repo}/blob/8.9/packages/core/ui-settings/core-ui-settings-server/src/ui_settings_client.ts[`context.uiSettings.client`]
|
|
|
|
==== Declare a custom scoped service
|
|
|
|
Plugins can extend the handler context with a custom API that will be
|
|
available to the plugin itself and all dependent plugins. For example,
|
|
the plugin creates a custom Elasticsearch client and wants to use it via
|
|
the request handler context:
|
|
|
|
[source,typescript]
|
|
----
|
|
import type { CoreSetup, RequestHandlerContext, IScopedClusterClient } from '@kbn/core/server';
|
|
|
|
interface MyRequestHandlerContext extends RequestHandlerContext {
|
|
myPlugin: {
|
|
client: IScopedClusterClient;
|
|
};
|
|
}
|
|
|
|
class MyPlugin {
|
|
setup(core: CoreSetup) {
|
|
const client = core.elasticsearch.createClient('myClient');
|
|
core.http.registerRouteHandlerContext<MyRequestHandlerContext, 'myPlugin'>('myPlugin', (context, req, res) => {
|
|
return { client: client.asScoped(req) };
|
|
});
|
|
const router = core.http.createRouter<MyRequestHandlerContext>();
|
|
router.get(
|
|
{ path: '/api/my-plugin/', validate: … },
|
|
async (context, req, res) => {
|
|
// context type is inferred as MyPluginContext
|
|
const data = await context.myPlugin.client.asCurrentUser('endpoint');
|
|
}
|
|
);
|
|
}
|
|
----
|