Skip to content

Commit 3f26145

Browse files
use NP deprecations in uiSettings (#53755) (#54009)
* use NP deprecation iunstead of manual one in uiSettings * add ServiceConfigDescriptor type Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 473c5a8 commit 3f26145

File tree

14 files changed

+54
-77
lines changed

14 files changed

+54
-77
lines changed

src/core/server/config/deprecation/core_deprecations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export const coreDeprecationProvider: ConfigDeprecationProvider = ({
9797
}) => [
9898
unusedFromRoot('savedObjects.indexCheckTimeout'),
9999
unusedFromRoot('server.xsrf.token'),
100-
unusedFromRoot('uiSettings.enabled'),
101100
renameFromRoot('optimize.lazy', 'optimize.watch'),
102101
renameFromRoot('optimize.lazyPort', 'optimize.watchPort'),
103102
renameFromRoot('optimize.lazyHost', 'optimize.watchHost'),

src/core/server/http/http_config.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ export const config = {
4242
validate: match(validBasePathRegex, "must start with a slash, don't end with one"),
4343
})
4444
),
45-
defaultRoute: schema.maybe(
46-
schema.string({
47-
validate(value) {
48-
if (!value.startsWith('/')) {
49-
return 'must start with a slash';
50-
}
51-
},
52-
})
53-
),
5445
cors: schema.conditional(
5546
schema.contextRef('dev'),
5647
true,
@@ -149,7 +140,6 @@ export class HttpConfig {
149140
public maxPayload: ByteSizeValue;
150141
public basePath?: string;
151142
public rewriteBasePath: boolean;
152-
public defaultRoute?: string;
153143
public ssl: SslConfig;
154144
public compression: { enabled: boolean; referrerWhitelist?: string[] };
155145
public csp: ICspConfig;
@@ -171,7 +161,6 @@ export class HttpConfig {
171161
this.socketTimeout = rawHttpConfig.socketTimeout;
172162
this.rewriteBasePath = rawHttpConfig.rewriteBasePath;
173163
this.ssl = new SslConfig(rawHttpConfig.ssl || {});
174-
this.defaultRoute = rawHttpConfig.defaultRoute;
175164
this.compression = rawHttpConfig.compression;
176165
this.csp = new CspConfig(rawCspConfig);
177166
this.xsrf = rawHttpConfig.xsrf;

src/core/server/http/http_service.mock.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ const createSetupContractMock = () => {
6868
getAuthHeaders: jest.fn(),
6969
},
7070
isTlsEnabled: false,
71-
config: {},
7271
};
7372
setupContract.createCookieSessionStorageFactory.mockResolvedValue(
7473
sessionStorageMock.createFactory()

src/core/server/http/http_service.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ export class HttpService implements CoreService<InternalHttpServiceSetup, HttpSe
112112
contextName: T,
113113
provider: RequestHandlerContextProvider<T>
114114
) => this.requestHandlerContext!.registerContext(pluginOpaqueId, contextName, provider),
115-
116-
config: {
117-
defaultRoute: config.defaultRoute,
118-
},
119115
};
120116

121117
return contract;

src/core/server/http/types.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,6 @@ export interface InternalHttpServiceSetup
250250
contextName: T,
251251
provider: RequestHandlerContextProvider<T>
252252
) => RequestHandlerContextContainer;
253-
config: {
254-
/**
255-
* @internalRemarks
256-
* Deprecated part of the server config, provided until
257-
* https://github.com/elastic/kibana/issues/40255
258-
*
259-
* @deprecated
260-
* */
261-
defaultRoute?: string;
262-
};
263253
}
264254

265255
/** @public */

src/core/server/internal_types.ts

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

20+
import { Type } from '@kbn/config-schema';
21+
2022
import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
23+
import { ConfigDeprecationProvider } from './config';
2124
import { ContextSetup } from './context';
2225
import { InternalElasticsearchServiceSetup } from './elasticsearch';
2326
import { InternalHttpServiceSetup } from './http';
@@ -47,3 +50,18 @@ export interface InternalCoreStart {
4750
savedObjects: InternalSavedObjectsServiceStart;
4851
uiSettings: InternalUiSettingsServiceStart;
4952
}
53+
54+
/**
55+
* @internal
56+
*/
57+
export interface ServiceConfigDescriptor<T = any> {
58+
path: string;
59+
/**
60+
* Schema to use to validate the configuration.
61+
*/
62+
schema: Type<T>;
63+
/**
64+
* Provider for the {@link ConfigDeprecation} to apply to the plugin configuration.
65+
*/
66+
deprecations?: ConfigDeprecationProvider;
67+
}

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

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

src/core/server/legacy/config/legacy_object_to_config_adapter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export class LegacyObjectToConfigAdapter extends ObjectToConfigAdapter {
6464
return {
6565
autoListen: configValue.autoListen,
6666
basePath: configValue.basePath,
67-
defaultRoute: configValue.defaultRoute,
6867
cors: configValue.cors,
6968
customResponseHeaders: configValue.customResponseHeaders,
7069
host: configValue.host,

src/core/server/server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ export class Server {
257257
];
258258

259259
this.configService.addDeprecationProvider(rootConfigPath, coreDeprecationProvider);
260+
this.configService.addDeprecationProvider(
261+
uiSettingsConfig.path,
262+
uiSettingsConfig.deprecations!
263+
);
260264

261265
for (const [path, schema] of schemas) {
262266
await this.configService.setSchema(path, schema);

src/core/server/ui_settings/ui_settings_config.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,35 @@
1818
*/
1919

2020
import { schema, TypeOf } from '@kbn/config-schema';
21+
import { ConfigDeprecationProvider } from 'src/core/server';
22+
import { ServiceConfigDescriptor } from '../internal_types';
2123

22-
export type UiSettingsConfigType = TypeOf<typeof config.schema>;
24+
const deprecations: ConfigDeprecationProvider = ({ unused, renameFromRoot }) => [
25+
unused('enabled'),
26+
renameFromRoot('server.defaultRoute', 'uiSettings.overrides.defaultRoute'),
27+
];
2328

24-
export const config = {
29+
const configSchema = schema.object({
30+
overrides: schema.object(
31+
{
32+
defaultRoute: schema.maybe(
33+
schema.string({
34+
validate(value) {
35+
if (!value.startsWith('/')) {
36+
return 'must start with a slash';
37+
}
38+
},
39+
})
40+
),
41+
},
42+
{ allowUnknowns: true }
43+
),
44+
});
45+
46+
export type UiSettingsConfigType = TypeOf<typeof configSchema>;
47+
48+
export const config: ServiceConfigDescriptor<UiSettingsConfigType> = {
2549
path: 'uiSettings',
26-
schema: schema.object({
27-
overrides: schema.object({}, { allowUnknowns: true }),
28-
// Deprecation is implemented in LP.
29-
// We define schema here not to fail on the validation step.
30-
enabled: schema.maybe(schema.boolean()),
31-
}),
50+
schema: configSchema,
51+
deprecations,
3252
};

0 commit comments

Comments
 (0)