Skip to content

Commit

Permalink
Merge branch 'master' into fix/allow-filters-without-index-backup
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Jun 18, 2020
2 parents 8cf2085 + 4ce91b3 commit 3373118
Show file tree
Hide file tree
Showing 107 changed files with 1,409 additions and 2,004 deletions.
1 change: 1 addition & 0 deletions docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [SavedObjectsExportResultDetails](./kibana-plugin-core-server.savedobjectsexportresultdetails.md) | Structure of the export result details entry |
| [SavedObjectsFindOptions](./kibana-plugin-core-server.savedobjectsfindoptions.md) | |
| [SavedObjectsFindResponse](./kibana-plugin-core-server.savedobjectsfindresponse.md) | Return type of the Saved Objects <code>find()</code> method.<!-- -->\*Note\*: this type is different between the Public and Server Saved Objects clients. |
| [SavedObjectsFindResult](./kibana-plugin-core-server.savedobjectsfindresult.md) | |
| [SavedObjectsImportConflictError](./kibana-plugin-core-server.savedobjectsimportconflicterror.md) | Represents a failure to import due to a conflict. |
| [SavedObjectsImportError](./kibana-plugin-core-server.savedobjectsimporterror.md) | Represents a failure to import. |
| [SavedObjectsImportMissingReferencesError](./kibana-plugin-core-server.savedobjectsimportmissingreferenceserror.md) | Represents a failure to import due to missing references. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export interface SavedObjectsFindResponse<T = unknown>
| --- | --- | --- |
| [page](./kibana-plugin-core-server.savedobjectsfindresponse.page.md) | <code>number</code> | |
| [per\_page](./kibana-plugin-core-server.savedobjectsfindresponse.per_page.md) | <code>number</code> | |
| [saved\_objects](./kibana-plugin-core-server.savedobjectsfindresponse.saved_objects.md) | <code>Array&lt;SavedObject&lt;T&gt;&gt;</code> | |
| [saved\_objects](./kibana-plugin-core-server.savedobjectsfindresponse.saved_objects.md) | <code>Array&lt;SavedObjectsFindResult&lt;T&gt;&gt;</code> | |
| [total](./kibana-plugin-core-server.savedobjectsfindresponse.total.md) | <code>number</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
saved_objects: Array<SavedObject<T>>;
saved_objects: Array<SavedObjectsFindResult<T>>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsFindResult](./kibana-plugin-core-server.savedobjectsfindresult.md)

## SavedObjectsFindResult interface


<b>Signature:</b>

```typescript
export interface SavedObjectsFindResult<T = unknown> extends SavedObject<T>
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [score](./kibana-plugin-core-server.savedobjectsfindresult.score.md) | <code>number</code> | The Elasticsearch <code>_score</code> of this result. |
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-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsFindResult](./kibana-plugin-core-server.savedobjectsfindresult.md) &gt; [score](./kibana-plugin-core-server.savedobjectsfindresult.score.md)

## SavedObjectsFindResult.score property

The Elasticsearch `_score` of this result.

<b>Signature:</b>

```typescript
score: number;
```
8 changes: 4 additions & 4 deletions packages/kbn-dev-utils/src/kbn_client/kbn_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/

import { ToolingLog } from '../tooling_log';
import { KbnClientRequester, ReqOptions } from './kbn_client_requester';
import { KibanaConfig, KbnClientRequester, ReqOptions } from './kbn_client_requester';
import { KbnClientStatus } from './kbn_client_status';
import { KbnClientPlugins } from './kbn_client_plugins';
import { KbnClientVersion } from './kbn_client_version';
import { KbnClientSavedObjects } from './kbn_client_saved_objects';
import { KbnClientUiSettings, UiSettingValues } from './kbn_client_ui_settings';

export class KbnClient {
private readonly requester = new KbnClientRequester(this.log, this.kibanaUrls);
private readonly requester = new KbnClientRequester(this.log, this.kibanaConfig);
readonly status = new KbnClientStatus(this.requester);
readonly plugins = new KbnClientPlugins(this.status);
readonly version = new KbnClientVersion(this.status);
Expand All @@ -43,10 +43,10 @@ export class KbnClient {
*/
constructor(
private readonly log: ToolingLog,
private readonly kibanaUrls: string[],
private readonly kibanaConfig: KibanaConfig,
private readonly uiSettingDefaults?: UiSettingValues
) {
if (!kibanaUrls.length) {
if (!kibanaConfig.url) {
throw new Error('missing Kibana urls');
}
}
Expand Down
38 changes: 28 additions & 10 deletions packages/kbn-dev-utils/src/kbn_client/kbn_client_requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/

import Url from 'url';

import Axios from 'axios';
import Https from 'https';
import Axios, { AxiosResponse } from 'axios';

import { isAxiosRequestError, isAxiosResponseError } from '../axios';
import { ToolingLog } from '../tooling_log';
Expand Down Expand Up @@ -70,20 +69,38 @@ const delay = (ms: number) =>
setTimeout(resolve, ms);
});

export interface KibanaConfig {
url: string;
ssl?: {
enabled: boolean;
key: string;
certificate: string;
certificateAuthorities: string;
};
}

export class KbnClientRequester {
constructor(private readonly log: ToolingLog, private readonly kibanaUrls: string[]) {}
private readonly httpsAgent: Https.Agent | null;
constructor(private readonly log: ToolingLog, private readonly kibanaConfig: KibanaConfig) {
this.httpsAgent =
kibanaConfig.ssl && kibanaConfig.ssl.enabled
? new Https.Agent({
cert: kibanaConfig.ssl.certificate,
key: kibanaConfig.ssl.key,
ca: kibanaConfig.ssl.certificateAuthorities,
})
: null;
}

private pickUrl() {
const url = this.kibanaUrls.shift()!;
this.kibanaUrls.push(url);
return url;
return this.kibanaConfig.url;
}

public resolveUrl(relativeUrl: string = '/') {
return Url.resolve(this.pickUrl(), relativeUrl);
}

async request<T>(options: ReqOptions): Promise<T> {
async request<T>(options: ReqOptions): Promise<AxiosResponse<T>> {
const url = Url.resolve(this.pickUrl(), options.path);
const description = options.description || `${options.method} ${url}`;
let attempt = 0;
Expand All @@ -93,17 +110,18 @@ export class KbnClientRequester {
attempt += 1;

try {
const response = await Axios.request<T>({
const response = await Axios.request({
method: options.method,
url,
data: options.body,
params: options.query,
headers: {
'kbn-xsrf': 'kbn-client',
},
httpsAgent: this.httpsAgent,
});

return response.data;
return response;
} catch (error) {
const conflictOnGet = isConcliftOnGetError(error);
const requestedRetries = options.retries !== undefined;
Expand Down
16 changes: 11 additions & 5 deletions packages/kbn-dev-utils/src/kbn_client/kbn_client_saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ export class KbnClientSavedObjects {
public async migrate() {
this.log.debug('Migrating saved objects');

return await this.requester.request<MigrateResponse>({
const { data } = await this.requester.request<MigrateResponse>({
description: 'migrate saved objects',
path: uriencode`/internal/saved_objects/_migrate`,
method: 'POST',
body: {},
});
return data;
}

/**
Expand All @@ -85,11 +86,12 @@ export class KbnClientSavedObjects {
public async get<Attributes extends Record<string, any>>(options: GetOptions) {
this.log.debug('Gettings saved object: %j', options);

return await this.requester.request<SavedObjectResponse<Attributes>>({
const { data } = await this.requester.request<SavedObjectResponse<Attributes>>({
description: 'get saved object',
path: uriencode`/api/saved_objects/${options.type}/${options.id}`,
method: 'GET',
});
return data;
}

/**
Expand All @@ -98,7 +100,7 @@ export class KbnClientSavedObjects {
public async create<Attributes extends Record<string, any>>(options: IndexOptions<Attributes>) {
this.log.debug('Creating saved object: %j', options);

return await this.requester.request<SavedObjectResponse<Attributes>>({
const { data } = await this.requester.request<SavedObjectResponse<Attributes>>({
description: 'update saved object',
path: options.id
? uriencode`/api/saved_objects/${options.type}/${options.id}`
Expand All @@ -113,6 +115,7 @@ export class KbnClientSavedObjects {
references: options.references,
},
});
return data;
}

/**
Expand All @@ -121,7 +124,7 @@ export class KbnClientSavedObjects {
public async update<Attributes extends Record<string, any>>(options: UpdateOptions<Attributes>) {
this.log.debug('Updating saved object: %j', options);

return await this.requester.request<SavedObjectResponse<Attributes>>({
const { data } = await this.requester.request<SavedObjectResponse<Attributes>>({
description: 'update saved object',
path: uriencode`/api/saved_objects/${options.type}/${options.id}`,
query: {
Expand All @@ -134,6 +137,7 @@ export class KbnClientSavedObjects {
references: options.references,
},
});
return data;
}

/**
Expand All @@ -142,10 +146,12 @@ export class KbnClientSavedObjects {
public async delete(options: GetOptions) {
this.log.debug('Deleting saved object %s/%s', options);

return await this.requester.request({
const { data } = await this.requester.request({
description: 'delete saved object',
path: uriencode`/api/saved_objects/${options.type}/${options.id}`,
method: 'DELETE',
});

return data;
}
}
3 changes: 2 additions & 1 deletion packages/kbn-dev-utils/src/kbn_client/kbn_client_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ export class KbnClientStatus {
* Get the full server status
*/
async get() {
return await this.requester.request<ApiResponseStatus>({
const { data } = await this.requester.request<ApiResponseStatus>({
method: 'GET',
path: 'api/status',
});
return data;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ export class KbnClientUiSettings {
* Unset a uiSetting
*/
async unset(setting: string) {
return await this.requester.request<any>({
const { data } = await this.requester.request<any>({
path: uriencode`/api/kibana/settings/${setting}`,
method: 'DELETE',
});
return data;
}

/**
Expand Down Expand Up @@ -105,11 +106,11 @@ export class KbnClientUiSettings {
}

private async getAll() {
const resp = await this.requester.request<UiSettingsApiResponse>({
const { data } = await this.requester.request<UiSettingsApiResponse>({
path: '/api/kibana/settings',
method: 'GET',
});

return resp.settings;
return data.settings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ const urlPartsSchema = () =>
password: Joi.string(),
pathname: Joi.string().regex(/^\//, 'start with a /'),
hash: Joi.string().regex(/^\//, 'start with a /'),
ssl: Joi.object()
.keys({
enabled: Joi.boolean().default(false),
certificate: Joi.string().optional(),
certificateAuthorities: Joi.string().optional(),
key: Joi.string().optional(),
})
.default(),
})
.default();

Expand Down Expand Up @@ -122,6 +130,7 @@ export const schema = Joi.object()
type: Joi.string().valid('chrome', 'firefox', 'ie', 'msedge').default('chrome'),

logPollingMs: Joi.number().default(100),
acceptInsecureCerts: Joi.boolean().default(false),
})
.default(),

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,34 @@
* specific language governing permissions and limitations
* under the License.
*/

import { kibanaTestUser } from './users';
import url from 'url';
import { kibanaTestUser } from './users';

interface UrlParts {
protocol?: string;
hostname?: string;
port?: number;
auth?: string;
username?: string;
password?: string;
}

export const kbnTestConfig = new (class KbnTestConfig {
getPort() {
return this.getUrlParts().port;
}

getUrlParts() {
getUrlParts(): UrlParts {
// allow setting one complete TEST_KIBANA_URL for ES like https://elastic:changeme@example.com:9200
if (process.env.TEST_KIBANA_URL) {
const testKibanaUrl = url.parse(process.env.TEST_KIBANA_URL);
return {
protocol: testKibanaUrl.protocol.slice(0, -1),
protocol: testKibanaUrl.protocol?.slice(0, -1),
hostname: testKibanaUrl.hostname,
port: parseInt(testKibanaUrl.port, 10),
port: testKibanaUrl.port ? parseInt(testKibanaUrl.port, 10) : undefined,
auth: testKibanaUrl.auth,
username: testKibanaUrl.auth.split(':')[0],
password: testKibanaUrl.auth.split(':')[1],
username: testKibanaUrl.auth?.split(':')[0],
password: testKibanaUrl.auth?.split(':')[1],
};
}

Expand All @@ -44,7 +52,7 @@ export const kbnTestConfig = new (class KbnTestConfig {
return {
protocol: process.env.TEST_KIBANA_PROTOCOL || 'http',
hostname: process.env.TEST_KIBANA_HOSTNAME || 'localhost',
port: parseInt(process.env.TEST_KIBANA_PORT, 10) || 5620,
port: process.env.TEST_KIBANA_PORT ? parseInt(process.env.TEST_KIBANA_PORT, 10) : 5620,
auth: `${username}:${password}`,
username,
password,
Expand Down
File renamed without changes.
Loading

0 comments on commit 3373118

Please sign in to comment.