Skip to content

Commit fd4bb8e

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

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
@@ -39,15 +39,6 @@ export const config = {
3939
validate: match(validBasePathRegex, "must start with a slash, don't end with one"),
4040
})
4141
),
42-
defaultRoute: schema.maybe(
43-
schema.string({
44-
validate(value) {
45-
if (!value.startsWith('/')) {
46-
return 'must start with a slash';
47-
}
48-
},
49-
})
50-
),
5142
cors: schema.conditional(
5243
schema.contextRef('dev'),
5344
true,
@@ -134,7 +125,6 @@ export class HttpConfig {
134125
public maxPayload: ByteSizeValue;
135126
public basePath?: string;
136127
public rewriteBasePath: boolean;
137-
public defaultRoute?: string;
138128
public ssl: SslConfig;
139129
public compression: { enabled: boolean; referrerWhitelist?: string[] };
140130
public csp: ICspConfig;
@@ -153,7 +143,6 @@ export class HttpConfig {
153143
this.socketTimeout = rawHttpConfig.socketTimeout;
154144
this.rewriteBasePath = rawHttpConfig.rewriteBasePath;
155145
this.ssl = new SslConfig(rawHttpConfig.ssl || {});
156-
this.defaultRoute = rawHttpConfig.defaultRoute;
157146
this.compression = rawHttpConfig.compression;
158147
this.csp = new CspConfig(rawCspConfig);
159148
}

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
@@ -107,10 +107,6 @@ export class HttpService implements CoreService<InternalHttpServiceSetup, HttpSe
107107
contextName: T,
108108
provider: RequestHandlerContextProvider<T>
109109
) => this.requestHandlerContext!.registerContext(pluginOpaqueId, contextName, provider),
110-
111-
config: {
112-
defaultRoute: config.defaultRoute,
113-
},
114110
};
115111

116112
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
host: configValue.host,
7069
maxPayload: configValue.maxPayloadBytes,

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)