-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
legacy_object_to_config_adapter.ts
109 lines (97 loc) · 3.4 KB
/
legacy_object_to_config_adapter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { ConfigPath } from '../config';
import { ObjectToConfigAdapter } from '../object_to_config_adapter';
// TODO: fix once core schemas are moved to this package
type LoggingConfigType = any;
/**
* @internal
* @deprecated
*/
export type LegacyVars = Record<string, any>;
/**
* Represents logging config supported by the legacy platform.
*/
export interface LegacyLoggingConfig {
silent?: boolean;
verbose?: boolean;
quiet?: boolean;
dest?: string;
json?: boolean;
events?: Record<string, string>;
}
type MixedLoggingConfig = LegacyLoggingConfig & Partial<LoggingConfigType>;
/**
* Represents adapter between config provided by legacy platform and `Config`
* supported by the current platform.
* @internal
*/
export class LegacyObjectToConfigAdapter extends ObjectToConfigAdapter {
private static transformLogging(configValue: MixedLoggingConfig = {}) {
const { appenders, root, loggers, ...legacyLoggingConfig } = configValue;
const loggingConfig = {
appenders: {
...appenders,
default: { kind: 'legacy-appender', legacyLoggingConfig },
},
root: { level: 'info', ...root },
loggers,
};
if (configValue.silent) {
loggingConfig.root.level = 'off';
} else if (configValue.quiet) {
loggingConfig.root.level = 'error';
} else if (configValue.verbose) {
loggingConfig.root.level = 'all';
}
return loggingConfig;
}
private static transformServer(configValue: any = {}) {
// TODO: New platform uses just a subset of `server` config from the legacy platform,
// new values will be exposed once we need them
return {
autoListen: configValue.autoListen,
basePath: configValue.basePath,
cors: configValue.cors,
customResponseHeaders: configValue.customResponseHeaders,
host: configValue.host,
maxPayload: configValue.maxPayloadBytes,
name: configValue.name,
port: configValue.port,
publicBaseUrl: configValue.publicBaseUrl,
rewriteBasePath: configValue.rewriteBasePath,
ssl: configValue.ssl,
keepaliveTimeout: configValue.keepaliveTimeout,
socketTimeout: configValue.socketTimeout,
compression: configValue.compression,
uuid: configValue.uuid,
xsrf: configValue.xsrf,
};
}
private static transformPlugins(configValue: LegacyVars = {}) {
// These properties are the only ones we use from the existing `plugins` config node
// since `scanDirs` isn't respected by new platform plugin discovery.
return {
initialize: configValue.initialize,
paths: configValue.paths,
};
}
public get(configPath: ConfigPath) {
const configValue = super.get(configPath);
switch (configPath) {
case 'logging':
return LegacyObjectToConfigAdapter.transformLogging(configValue as LegacyLoggingConfig);
case 'server':
return LegacyObjectToConfigAdapter.transformServer(configValue);
case 'plugins':
return LegacyObjectToConfigAdapter.transformPlugins(configValue as LegacyVars);
default:
return configValue;
}
}
}