Skip to content

Commit 8051797

Browse files
authored
Migrate instance uuid logic to new platform (#52060) (#53260)
* move and migrate uuid code to new platform * create and wire uuid service * handle legacy compatibility * update generated docs * add `set` to LegacyConfig interface * Fix types * fix config access * respect naming conventions for uuid * remove hardcoded config paths * rename manageInstanceUuid to resolveInstanceUuid * moves legacy config uuid set from uuid to legacy service * log specific message depending on how uuid was resolved * resolve merge conflicts * use fs.promises * add forgotten @public in uuid contract * add explicit errors and tests * ensure uuid is valid in configuration * fix read/write tests
1 parent e69183d commit 8051797

33 files changed

+742
-233
lines changed

docs/development/core/server/kibana-plugin-server.coresetup.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ export interface CoreSetup
2222
| [http](./kibana-plugin-server.coresetup.http.md) | <code>HttpServiceSetup</code> | [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) |
2323
| [savedObjects](./kibana-plugin-server.coresetup.savedobjects.md) | <code>SavedObjectsServiceSetup</code> | [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) |
2424
| [uiSettings](./kibana-plugin-server.coresetup.uisettings.md) | <code>UiSettingsServiceSetup</code> | [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md) |
25+
| [uuid](./kibana-plugin-server.coresetup.uuid.md) | <code>UuidServiceSetup</code> | [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md) |
2526

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[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)
4+
5+
## CoreSetup.uuid property
6+
7+
[UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md)
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
uuid: UuidServiceSetup;
13+
```

docs/development/core/server/kibana-plugin-server.md

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

142143
## Variables
143144

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[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)
4+
5+
## UuidServiceSetup.getInstanceUuid() method
6+
7+
Retrieve the Kibana instance uuid.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
getInstanceUuid(): string;
13+
```
14+
<b>Returns:</b>
15+
16+
`string`
17+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md)
4+
5+
## UuidServiceSetup interface
6+
7+
APIs to access the application's instance uuid.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export interface UuidServiceSetup
13+
```
14+
15+
## Methods
16+
17+
| Method | Description |
18+
| --- | --- |
19+
| [getInstanceUuid()](./kibana-plugin-server.uuidservicesetup.getinstanceuuid.md) | Retrieve the Kibana instance uuid. |
20+

src/core/server/http/http_config.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* under the License.
1818
*/
1919

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

81+
test('accepts only valid uuids for server.uuid', () => {
82+
const httpSchema = config.schema;
83+
expect(() => httpSchema.validate({ uuid: uuid.v4() })).not.toThrow();
84+
expect(() => httpSchema.validate({ uuid: 'not an uuid' })).toThrowErrorMatchingInlineSnapshot(
85+
`"[uuid]: must be a valid uuid"`
86+
);
87+
});
88+
8089
describe('with TLS', () => {
8190
test('throws if TLS is enabled but `key` is not specified', () => {
8291
const httpSchema = config.schema;

src/core/server/http/http_config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { CspConfigType, CspConfig, ICspConfig } from '../csp';
2323
import { SslConfig, sslSchema } from './ssl_config';
2424

2525
const validBasePathRegex = /(^$|^\/.*[^\/]$)/;
26+
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;
2627

2728
const match = (regex: RegExp, errorMsg: string) => (str: string) =>
2829
regex.test(str) ? undefined : errorMsg;
@@ -92,6 +93,11 @@ export const config = {
9293
)
9394
),
9495
}),
96+
uuid: schema.maybe(
97+
schema.string({
98+
validate: match(uuidRegexp, 'must be a valid uuid'),
99+
})
100+
),
95101
},
96102
{
97103
validate: rawConfig => {

src/core/server/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { IUiSettingsClient, UiSettingsServiceSetup } from './ui_settings';
4747
import { SavedObjectsClientContract } from './saved_objects/types';
4848
import { SavedObjectsServiceSetup, SavedObjectsServiceStart } from './saved_objects';
4949
import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
50+
import { UuidServiceSetup } from './uuid';
5051

5152
export { bootstrap } from './bootstrap';
5253
export { Capabilities, CapabilitiesProvider, CapabilitiesSwitcher } from './capabilities';
@@ -269,6 +270,8 @@ export interface CoreSetup {
269270
savedObjects: SavedObjectsServiceSetup;
270271
/** {@link UiSettingsServiceSetup} */
271272
uiSettings: UiSettingsServiceSetup;
273+
/** {@link UuidServiceSetup} */
274+
uuid: UuidServiceSetup;
272275
}
273276

274277
/**
@@ -290,4 +293,5 @@ export {
290293
PluginsServiceSetup,
291294
PluginsServiceStart,
292295
PluginOpaqueId,
296+
UuidServiceSetup,
293297
};

src/core/server/internal_types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
InternalSavedObjectsServiceSetup,
2727
} from './saved_objects';
2828
import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
29+
import { UuidServiceSetup } from './uuid';
2930

3031
/** @internal */
3132
export interface InternalCoreSetup {
@@ -35,6 +36,7 @@ export interface InternalCoreSetup {
3536
elasticsearch: InternalElasticsearchServiceSetup;
3637
uiSettings: InternalUiSettingsServiceSetup;
3738
savedObjects: InternalSavedObjectsServiceSetup;
39+
uuid: UuidServiceSetup;
3840
}
3941

4042
/**

src/core/server/legacy/config/__snapshots__/legacy_object_to_config_adapter.test.ts.snap

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)