Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch legacy compatible api #41468

Closed
12 changes: 0 additions & 12 deletions docs/development/core/server/kibana-plugin-server.apicaller.md

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [ClusterClient](./kibana-plugin-server.clusterclient.md) &gt; [callAsInternalUser](./kibana-plugin-server.clusterclient.callasinternaluser.md)
[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [ClusterClient](./kibana-plugin-server.clusterclient.md) &gt; [callWithInternalUser](./kibana-plugin-server.clusterclient.callwithinternaluser.md)

## ClusterClient.callAsInternalUser property
## ClusterClient.callWithInternalUser property

Calls specified endpoint with provided clientParams on behalf of the Kibana internal user.

<b>Signature:</b>

```typescript
callAsInternalUser: (endpoint: string, clientParams?: Record<string, unknown>, options?: CallAPIOptions | undefined) => Promise<any>;
callWithInternalUser: (endpoint: string, clientParams?: Record<string, unknown>, options?: CallAPIOptions | undefined) => Promise<any>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [ClusterClient](./kibana-plugin-server.clusterclient.md) &gt; [callWithRequest](./kibana-plugin-server.clusterclient.callwithrequest.md)

## ClusterClient.callWithRequest property

Calls specified `endpoint` with provided `clientParams` on behalf of the user initiated request to the Kibana server (via HTTP request headers).

<b>Signature:</b>

```typescript
callWithRequest: (request: Request | KibanaRequest<unknown, unknown, unknown> | FakeRequest, endpoint: string, clientParams?: Record<string, unknown>, options?: CallAPIOptions | undefined) => Promise<any>;
joshdover marked this conversation as resolved.
Show resolved Hide resolved
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## ClusterClient class

Represents an Elasticsearch cluster API client and allows to call API on behalf of the internal Kibana user and the actual user that is derived from the request headers (via `asScoped(...)`<!-- -->).
Represents an Elasticsearch cluster API client and allows to call API on behalf of the internal Kibana user and the actual user that is derived from the request headers.

<b>Signature:</b>

Expand All @@ -22,12 +22,12 @@ export declare class ClusterClient

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [callAsInternalUser](./kibana-plugin-server.clusterclient.callasinternaluser.md) | | <code>(endpoint: string, clientParams?: Record&lt;string, unknown&gt;, options?: CallAPIOptions &#124; undefined) =&gt; Promise&lt;any&gt;</code> | Calls specified endpoint with provided clientParams on behalf of the Kibana internal user. |
| [callWithInternalUser](./kibana-plugin-server.clusterclient.callwithinternaluser.md) | | <code>(endpoint: string, clientParams?: Record&lt;string, unknown&gt;, options?: CallAPIOptions &#124; undefined) =&gt; Promise&lt;any&gt;</code> | Calls specified endpoint with provided clientParams on behalf of the Kibana internal user. |
| [callWithRequest](./kibana-plugin-server.clusterclient.callwithrequest.md) | | <code>(request: Request &#124; KibanaRequest&lt;unknown, unknown, unknown&gt; &#124; FakeRequest, endpoint: string, clientParams?: Record&lt;string, unknown&gt;, options?: CallAPIOptions &#124; undefined) =&gt; Promise&lt;any&gt;</code> | Calls specified <code>endpoint</code> with provided <code>clientParams</code> on behalf of the user initiated request to the Kibana server (via HTTP request headers). |

## Methods

| Method | Modifiers | Description |
| --- | --- | --- |
| [asScoped(request)](./kibana-plugin-server.clusterclient.asscoped.md) | | Creates an instance of <code>ScopedClusterClient</code> based on the configuration the current cluster client that exposes additional <code>callAsCurrentUser</code> method scoped to the provided req. Consumers shouldn't worry about closing scoped client instances, these will be automatically closed as soon as the original cluster client isn't needed anymore and closed. |
| [close()](./kibana-plugin-server.clusterclient.close.md) | | Closes the cluster client. After that client cannot be used and one should create a new client instance to be able to interact with Elasticsearch API. |

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Handle errors

```js
try {
await client.asScoped(request).callAsCurrentUser(...);
await client.callWithRequest(request, ...)
} catch (err) {
if (ElasticsearchErrorHelpers.isNotAuthorizedError(err)) {
const authHeader = err.output.headers['WWW-Authenticate'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ readonly createClient: (type: string, clientConfig?: Partial<ElasticsearchClient

```js
const client = elasticsearch.createCluster('my-app-name', config);
const data = await client.callAsInternalUser();
const data = await client.callWithInternalUser();

```

4 changes: 1 addition & 3 deletions docs/development/core/server/kibana-plugin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->

| Class | Description |
| --- | --- |
| [ClusterClient](./kibana-plugin-server.clusterclient.md) | Represents an Elasticsearch cluster API client and allows to call API on behalf of the internal Kibana user and the actual user that is derived from the request headers (via <code>asScoped(...)</code>). |
| [ClusterClient](./kibana-plugin-server.clusterclient.md) | Represents an Elasticsearch cluster API client and allows to call API on behalf of the internal Kibana user and the actual user that is derived from the request headers. |
| [ElasticsearchErrorHelpers](./kibana-plugin-server.elasticsearcherrorhelpers.md) | Helpers for working with errors returned from the Elasticsearch service.Since the internal data of errors are subject to change, consumers of the Elasticsearch service should always use these helpers to classify errors instead of checking error internals such as <code>body.error.header[WWW-Authenticate]</code> |
| [KibanaRequest](./kibana-plugin-server.kibanarequest.md) | Kibana specific abstraction for an incoming request. |
| [Router](./kibana-plugin-server.router.md) | |
| [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md) | |
| [ScopedClusterClient](./kibana-plugin-server.scopedclusterclient.md) | Serves the same purpose as "normal" <code>ClusterClient</code> but exposes additional <code>callAsCurrentUser</code> method that doesn't use credentials of the Kibana internal user (as <code>callAsInternalUser</code> does) to request Elasticsearch API, but rather passes HTTP headers extracted from the current user request to the API |

## Interfaces

Expand Down Expand Up @@ -70,7 +69,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->

| Type Alias | Description |
| --- | --- |
| [APICaller](./kibana-plugin-server.apicaller.md) | |
| [AuthenticationHandler](./kibana-plugin-server.authenticationhandler.md) | |
| [AuthHeaders](./kibana-plugin-server.authheaders.md) | Auth Headers map |
| [ElasticsearchClientConfig](./kibana-plugin-server.elasticsearchclientconfig.md) | |
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions src/core/server/elasticsearch/cluster_client.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@

export const MockClient = jest.fn();
jest.mock('elasticsearch', () => ({
// Jest types don't include `requireActual` right now.
...jest.requireActual('elasticsearch'),
Client: MockClient,
}));

export const MockScopedClusterClient = jest.fn();
jest.mock('./scoped_cluster_client', () => ({
ScopedClusterClient: MockScopedClusterClient,
}));

export const mockParseElasticsearchClientConfig = jest.fn();
jest.mock('./elasticsearch_client_config', () => ({
parseElasticsearchClientConfig: mockParseElasticsearchClientConfig,
Expand Down
Loading