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

Migrate instance uuid logic to new platform #52060

Merged
merged 27 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
732ccf2
move and migrate uuid code to new platform
pgayvallet Dec 2, 2019
bb7c5f0
create and wire uuid service
pgayvallet Dec 3, 2019
958b28e
handle legacy compatibility
pgayvallet Dec 3, 2019
3ed08c5
update generated docs
pgayvallet Dec 3, 2019
6964d1e
add `set` to LegacyConfig interface
pgayvallet Dec 6, 2019
88f9790
Fix types
pgayvallet Dec 6, 2019
c8a808d
fix config access
pgayvallet Dec 6, 2019
81a0dc0
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 9, 2019
7bbd025
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 11, 2019
b850444
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 12, 2019
a499ff1
respect naming conventions for uuid
pgayvallet Dec 12, 2019
afcdf9a
remove hardcoded config paths
pgayvallet Dec 12, 2019
6c0c880
rename manageInstanceUuid to resolveInstanceUuid
pgayvallet Dec 12, 2019
6139832
moves legacy config uuid set from uuid to legacy service
pgayvallet Dec 12, 2019
26719cb
log specific message depending on how uuid was resolved
pgayvallet Dec 12, 2019
1783d71
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 13, 2019
ba3a23f
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 13, 2019
8bcc718
resolve merge conflicts
pgayvallet Dec 13, 2019
f4b11d8
use fs.promises
pgayvallet Dec 13, 2019
fa6ea93
add forgotten @public in uuid contract
pgayvallet Dec 13, 2019
a6f5980
add explicit errors and tests
pgayvallet Dec 13, 2019
1844093
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 13, 2019
83eb19f
ensure uuid is valid in configuration
pgayvallet Dec 13, 2019
1b8e6b6
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 16, 2019
8767b73
fix read/write tests
pgayvallet Dec 16, 2019
9f27f5a
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 16, 2019
16e9a2f
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export interface CoreSetup
| [http](./kibana-plugin-server.coresetup.http.md) | <code>HttpServiceSetup</code> | [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) |
| [savedObjects](./kibana-plugin-server.coresetup.savedobjects.md) | <code>SavedObjectsServiceSetup</code> | [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) |
| [uiSettings](./kibana-plugin-server.coresetup.uisettings.md) | <code>UiSettingsServiceSetup</code> | [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md) |
| [uuid](./kibana-plugin-server.coresetup.uuid.md) | <code>UuidServiceSetup</code> | [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md) |

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; [CoreSetup](./kibana-plugin-server.coresetup.md) &gt; [uuid](./kibana-plugin-server.coresetup.uuid.md)

## CoreSetup.uuid property

[UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md)

<b>Signature:</b>

```typescript
uuid: UuidServiceSetup;
```
1 change: 1 addition & 0 deletions docs/development/core/server/kibana-plugin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) | UiSettings parameters defined by the plugins. |
| [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md) | |
| [UserProvidedValues](./kibana-plugin-server.userprovidedvalues.md) | Describes the values explicitly set by user. |
| [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md) | APIs to access the application's instance uuid. |

## Variables

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md) &gt; [getInstanceUuid](./kibana-plugin-server.uuidservicesetup.getinstanceuuid.md)

## UuidServiceSetup.getInstanceUuid() method

Retrieve the Kibana instance uuid.

<b>Signature:</b>

```typescript
getInstanceUuid(): string;
```
<b>Returns:</b>

`string`

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md)

## UuidServiceSetup interface

APIs to access the application's instance uuid.

<b>Signature:</b>

```typescript
export interface UuidServiceSetup
```

## Methods

| Method | Description |
| --- | --- |
| [getInstanceUuid()](./kibana-plugin-server.uuidservicesetup.getinstanceuuid.md) | Retrieve the Kibana instance uuid. |

9 changes: 9 additions & 0 deletions src/core/server/http/http_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import uuid from 'uuid';
import { config, HttpConfig } from '.';
import { Env } from '../config';
import { getEnvOptions } from '../config/__mocks__/env';
Expand Down Expand Up @@ -77,6 +78,14 @@ test('throws if basepath is not specified, but rewriteBasePath is set', () => {
expect(() => httpSchema.validate(obj)).toThrowErrorMatchingSnapshot();
});

test('accepts only valid uuids for server.uuid', () => {
const httpSchema = config.schema;
expect(() => httpSchema.validate({ uuid: uuid.v4() })).not.toThrow();
expect(() => httpSchema.validate({ uuid: 'not an uuid' })).toThrowErrorMatchingInlineSnapshot(
`"[uuid]: must be a valid uuid"`
);
});

describe('with TLS', () => {
test('throws if TLS is enabled but `key` is not specified', () => {
const httpSchema = config.schema;
Expand Down
6 changes: 6 additions & 0 deletions src/core/server/http/http_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { CspConfigType, CspConfig, ICspConfig } from '../csp';
import { SslConfig, sslSchema } from './ssl_config';

const validBasePathRegex = /(^$|^\/.*[^\/]$)/;
const uuidRegexp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

const match = (regex: RegExp, errorMsg: string) => (str: string) =>
regex.test(str) ? undefined : errorMsg;
Expand Down Expand Up @@ -92,6 +93,11 @@ export const config = {
)
),
}),
uuid: schema.maybe(
schema.string({
validate: match(uuidRegexp, 'must be a valid uuid'),
})
),
},
{
validate: rawConfig => {
Expand Down
4 changes: 4 additions & 0 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { IUiSettingsClient, UiSettingsServiceSetup } from './ui_settings';
import { SavedObjectsClientContract } from './saved_objects/types';
import { SavedObjectsServiceSetup, SavedObjectsServiceStart } from './saved_objects';
import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
import { UuidServiceSetup } from './uuid';

export { bootstrap } from './bootstrap';
export { Capabilities, CapabilitiesProvider, CapabilitiesSwitcher } from './capabilities';
Expand Down Expand Up @@ -269,6 +270,8 @@ export interface CoreSetup {
savedObjects: SavedObjectsServiceSetup;
/** {@link UiSettingsServiceSetup} */
uiSettings: UiSettingsServiceSetup;
/** {@link UuidServiceSetup} */
uuid: UuidServiceSetup;
}

/**
Expand All @@ -290,4 +293,5 @@ export {
PluginsServiceSetup,
PluginsServiceStart,
PluginOpaqueId,
UuidServiceSetup,
};
2 changes: 2 additions & 0 deletions src/core/server/internal_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
InternalSavedObjectsServiceSetup,
} from './saved_objects';
import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
import { UuidServiceSetup } from './uuid';

/** @internal */
export interface InternalCoreSetup {
Expand All @@ -35,6 +36,7 @@ export interface InternalCoreSetup {
elasticsearch: InternalElasticsearchServiceSetup;
uiSettings: InternalUiSettingsServiceSetup;
savedObjects: InternalSavedObjectsServiceSetup;
uuid: UuidServiceSetup;
}

/**
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class LegacyObjectToConfigAdapter extends ObjectToConfigAdapter {
keepaliveTimeout: configValue.keepaliveTimeout,
socketTimeout: configValue.socketTimeout,
compression: configValue.compression,
uuid: configValue.uuid,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/server/legacy/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
export interface LegacyConfig {
get<T>(key?: string): T;
has(key: string): boolean;
set(key: string, value: any): void;
set(config: Record<string, any>): void;
}

/**
Expand Down
39 changes: 39 additions & 0 deletions src/core/server/legacy/legacy_service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { LegacyServiceDiscoverPlugins } from './legacy_service';

const createDiscoverMock = () => {
const setupContract: DeeplyMockedKeys<LegacyServiceDiscoverPlugins> = {
pluginSpecs: [],
disabledPluginSpecs: [],
uiExports: {} as any,
settings: {},
pluginExtendedConfig: {
get: jest.fn(),
has: jest.fn(),
set: jest.fn(),
} as any,
};
return setupContract;
};

export const legacyServiceMock = {
createDiscover: createDiscoverMock,
};
34 changes: 34 additions & 0 deletions src/core/server/legacy/legacy_service.test.mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const findLegacyPluginSpecsMock = jest
.fn()
.mockImplementation((settings: Record<string, any>) => ({
pluginSpecs: [],
pluginExtendedConfig: {
has: jest.fn(),
get: jest.fn(() => settings),
set: jest.fn(),
},
disabledPluginSpecs: [],
uiExports: [],
}));
jest.doMock('./plugins/find_legacy_plugin_specs.ts', () => ({
findLegacyPluginSpecs: findLegacyPluginSpecsMock,
}));
Loading