Skip to content

Commit

Permalink
Fake request interface compatible with Kibana Request (#40363) (#40409)
Browse files Browse the repository at this point in the history
* make FakeRequest compatible with http request

* FakeRequest compatible with Http Request
  • Loading branch information
mshustov authored Jul 5, 2019
1 parent d70349e commit cfad101
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## ElasticsearchErrorHelpers class

Helpers provided to simplify future migration away from Boom as internal Error.
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 `body.error.header[WWW-Authenticate]`

<b>Signature:</b>

Expand All @@ -25,7 +25,7 @@ Handle errors

```js
try {
await client.callWithRequest(request, '...');
await client.asScoped(request).callAsCurrentUser(...);
} 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 @@ -9,5 +9,5 @@ Headers used for authentication against Elasticsearch
<b>Signature:</b>

```typescript
headers: Record<string, string>;
headers: Headers;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export interface FakeRequest

| Property | Type | Description |
| --- | --- | --- |
| [headers](./kibana-plugin-server.fakerequest.headers.md) | <code>Record&lt;string, string&gt;</code> | Headers used for authentication against Elasticsearch |
| [headers](./kibana-plugin-server.fakerequest.headers.md) | <code>Headers</code> | Headers used for authentication against Elasticsearch |

2 changes: 1 addition & 1 deletion docs/development/core/server/kibana-plugin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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>). |
| [ElasticsearchErrorHelpers](./kibana-plugin-server.elasticsearcherrorhelpers.md) | Helpers provided to simplify future migration away from Boom as internal Error. |
| [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) | |
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/elasticsearch/cluster_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Request } from 'hapi';

import { ElasticsearchErrorHelpers } from './errors';
import { GetAuthHeaders, isRealRequest } from '../http';
import { filterHeaders, KibanaRequest, ensureRawRequest } from '../http/router';
import { filterHeaders, Headers, KibanaRequest, ensureRawRequest } from '../http/router';
import { Logger } from '../logging';
import {
ElasticsearchClientConfig,
Expand Down Expand Up @@ -106,7 +106,7 @@ async function callAPI(
*/
export interface FakeRequest {
/** Headers used for authentication against Elasticsearch */
headers: Record<string, string>;
headers: Headers;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export interface ElasticsearchServiceSetup {

// @public
export interface FakeRequest {
headers: Record<string, string>;
headers: Headers;
}

// @public
Expand Down

0 comments on commit cfad101

Please sign in to comment.