Use explicit settings for simple bool settings (elastic/x-pack-elasticsearch#1871)
We made the mistake to generate way to many settings in xpack which makes finding out the right string and where it's defined super difficult. If we use constants we can just use commandline tools to find where the settings are defined. This also removes 1.x and 2.x BWC from the enabled settings which should be removed in 6.x Original commit: elastic/x-pack-elasticsearch@ec25e6c40c
This commit is contained in:
parent
2c7e39155d
commit
2f10afa40e
|
@ -8,7 +8,6 @@ package org.elasticsearch.xpack;
|
|||
import org.elasticsearch.common.Booleans;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Setting.Property;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.xpack.security.Security;
|
||||
import org.elasticsearch.xpack.ssl.SSLClientAuth;
|
||||
import org.elasticsearch.xpack.ssl.SSLConfigurationSettings;
|
||||
|
@ -18,47 +17,48 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* A container for xpack setting constants.
|
||||
*/
|
||||
public class XPackSettings {
|
||||
/** All setting constants created in this class. */
|
||||
private static final List<Setting<?>> ALL_SETTINGS = new ArrayList<>();
|
||||
|
||||
/** Setting for enabling or disabling security. Defaults to true. */
|
||||
public static final Setting<Boolean> SECURITY_ENABLED = enabledSetting(XPackPlugin.SECURITY, true);
|
||||
public static final Setting<Boolean> SECURITY_ENABLED = Setting.boolSetting("xpack.security.enabled", true, Setting.Property.NodeScope);
|
||||
|
||||
/** Setting for enabling or disabling monitoring. Defaults to true if not a tribe node. */
|
||||
public static final Setting<Boolean> MONITORING_ENABLED = enabledSetting(XPackPlugin.MONITORING,
|
||||
public static final Setting<Boolean> MONITORING_ENABLED = Setting.boolSetting("xpack.monitoring.enabled",
|
||||
// By default, monitoring is disabled on tribe nodes
|
||||
s -> String.valueOf(XPackPlugin.isTribeNode(s) == false && XPackPlugin.isTribeClientNode(s) == false));
|
||||
s -> String.valueOf(XPackPlugin.isTribeNode(s) == false && XPackPlugin.isTribeClientNode(s) == false),
|
||||
Setting.Property.NodeScope);
|
||||
|
||||
/** Setting for enabling or disabling watcher. Defaults to true. */
|
||||
public static final Setting<Boolean> WATCHER_ENABLED = enabledSetting(XPackPlugin.WATCHER, true);
|
||||
public static final Setting<Boolean> WATCHER_ENABLED = Setting.boolSetting("xpack.watcher.enabled", true, Setting.Property.NodeScope);
|
||||
|
||||
/** Setting for enabling or disabling graph. Defaults to true. */
|
||||
public static final Setting<Boolean> GRAPH_ENABLED = enabledSetting(XPackPlugin.GRAPH, true);
|
||||
public static final Setting<Boolean> GRAPH_ENABLED = Setting.boolSetting("xpack.graph.enabled", true, Setting.Property.NodeScope);
|
||||
|
||||
/** Setting for enabling or disabling machine learning. Defaults to false. */
|
||||
public static final Setting<Boolean> MACHINE_LEARNING_ENABLED = enabledSetting(XPackPlugin.MACHINE_LEARNING, true);
|
||||
public static final Setting<Boolean> MACHINE_LEARNING_ENABLED = Setting.boolSetting("xpack.ml.enabled", true,
|
||||
Setting.Property.NodeScope);
|
||||
|
||||
/** Setting for enabling or disabling auditing. Defaults to false. */
|
||||
public static final Setting<Boolean> AUDIT_ENABLED = enabledSetting(XPackPlugin.SECURITY + ".audit", false);
|
||||
public static final Setting<Boolean> AUDIT_ENABLED = Setting.boolSetting("xpack.security.audit.enabled", false,
|
||||
Setting.Property.NodeScope);
|
||||
|
||||
/** Setting for enabling or disabling document/field level security. Defaults to true. */
|
||||
public static final Setting<Boolean> DLS_FLS_ENABLED = enabledSetting(XPackPlugin.SECURITY + ".dls_fls", true);
|
||||
public static final Setting<Boolean> DLS_FLS_ENABLED = Setting.boolSetting("xpack.security.dls_fls.enabled", true,
|
||||
Setting.Property.NodeScope);
|
||||
|
||||
/** Setting for enabling or disabling Logstash extensions. Defaults to true. */
|
||||
public static final Setting<Boolean> LOGSTASH_ENABLED = enabledSetting(XPackPlugin.LOGSTASH, true);
|
||||
public static final Setting<Boolean> LOGSTASH_ENABLED = Setting.boolSetting("xpack.logstash.enabled", true,
|
||||
Setting.Property.NodeScope);
|
||||
|
||||
/**
|
||||
* Legacy setting for enabling or disabling transport ssl. Defaults to true. This is just here to make upgrading easier since the
|
||||
* user needs to set this setting in 5.x to upgrade
|
||||
*/
|
||||
private static final Setting<Boolean> TRANSPORT_SSL_ENABLED =
|
||||
new Setting<>(XPackPlugin.featureSettingPrefix(XPackPlugin.SECURITY) + ".transport.ssl.enabled", (s) -> Boolean.toString(true),
|
||||
new Setting<>("xpack.security.transport.ssl.enabled", (s) -> Boolean.toString(true),
|
||||
(s) -> {
|
||||
final boolean parsed = Booleans.parseBoolean(s);
|
||||
if (parsed == false) {
|
||||
|
@ -69,14 +69,16 @@ public class XPackSettings {
|
|||
}, Property.NodeScope, Property.Deprecated);
|
||||
|
||||
/** Setting for enabling or disabling http ssl. Defaults to false. */
|
||||
public static final Setting<Boolean> HTTP_SSL_ENABLED = enabledSetting(XPackPlugin.SECURITY + ".http.ssl", false);
|
||||
public static final Setting<Boolean> HTTP_SSL_ENABLED = Setting.boolSetting("xpack.security.http.ssl.enabled", false,
|
||||
Setting.Property.NodeScope);
|
||||
|
||||
/** Setting for enabling or disabling the reserved realm. Defaults to true */
|
||||
public static final Setting<Boolean> RESERVED_REALM_ENABLED_SETTING =
|
||||
enabledSetting(XPackPlugin.SECURITY + ".authc.reserved_realm", true);
|
||||
public static final Setting<Boolean> RESERVED_REALM_ENABLED_SETTING = Setting.boolSetting("xpack.security.authc.reserved_realm.enabled",
|
||||
true, Setting.Property.NodeScope);
|
||||
|
||||
/** Setting for enabling or disabling the token service. Defaults to true */
|
||||
public static final Setting<Boolean> TOKEN_SERVICE_ENABLED_SETTING = enabledSetting("security.authc.token", true);
|
||||
public static final Setting<Boolean> TOKEN_SERVICE_ENABLED_SETTING = Setting.boolSetting("xpack.security.authc.token.enabled", true,
|
||||
Setting.Property.NodeScope);
|
||||
|
||||
/*
|
||||
* SSL settings. These are the settings that are specifically registered for SSL. Many are private as we do not explicitly use them
|
||||
|
@ -103,49 +105,24 @@ public class XPackSettings {
|
|||
public static final String TRANSPORT_SSL_PREFIX = Security.setting("transport.ssl.");
|
||||
private static final SSLConfigurationSettings TRANSPORT_SSL = SSLConfigurationSettings.withPrefix(TRANSPORT_SSL_PREFIX);
|
||||
|
||||
/* End SSL settings */
|
||||
|
||||
static {
|
||||
ALL_SETTINGS.addAll(GLOBAL_SSL.getAllSettings());
|
||||
ALL_SETTINGS.addAll(HTTP_SSL.getAllSettings());
|
||||
ALL_SETTINGS.addAll(TRANSPORT_SSL.getAllSettings());
|
||||
ALL_SETTINGS.add(TRANSPORT_SSL_ENABLED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Setting for the enabled state of features in xpack.
|
||||
*
|
||||
* The given feature by be enabled or disabled with:
|
||||
* {@code "xpack.<feature>.enabled": true | false}
|
||||
*
|
||||
* For backward compatibility with 1.x and 2.x, the following also works:
|
||||
* {@code "<feature>.enabled": true | false}
|
||||
*
|
||||
* @param featureName The name of the feature in xpack
|
||||
* @param defaultValue True if the feature should be enabled by defualt, false otherwise
|
||||
*/
|
||||
private static Setting<Boolean> enabledSetting(String featureName, boolean defaultValue) {
|
||||
return enabledSetting(featureName, s -> String.valueOf(defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a setting for the enabled state of a feature, with a complex default value.
|
||||
* @param featureName The name of the feature in xpack
|
||||
* @param defaultValueFn A function to determine the default value based on the existing settings
|
||||
* @see #enabledSetting(String,boolean)
|
||||
*/
|
||||
private static Setting<Boolean> enabledSetting(String featureName, Function<Settings,String> defaultValueFn) {
|
||||
String fallbackName = featureName + ".enabled";
|
||||
Setting<Boolean> fallback = Setting.boolSetting(fallbackName, defaultValueFn,
|
||||
Setting.Property.NodeScope, Setting.Property.Deprecated);
|
||||
String settingName = XPackPlugin.featureSettingPrefix(featureName) + ".enabled";
|
||||
Setting<Boolean> setting = Setting.boolSetting(settingName, fallback, Setting.Property.NodeScope);
|
||||
ALL_SETTINGS.add(setting);
|
||||
return setting;
|
||||
}
|
||||
|
||||
/** Returns all settings created in {@link XPackSettings}. */
|
||||
static List<Setting<?>> getAllSettings() {
|
||||
return Collections.unmodifiableList(ALL_SETTINGS);
|
||||
ArrayList<Setting<?>> settings = new ArrayList<>();
|
||||
settings.addAll(GLOBAL_SSL.getAllSettings());
|
||||
settings.addAll(HTTP_SSL.getAllSettings());
|
||||
settings.addAll(TRANSPORT_SSL.getAllSettings());
|
||||
settings.add(SECURITY_ENABLED);
|
||||
settings.add(MONITORING_ENABLED);
|
||||
settings.add(GRAPH_ENABLED);
|
||||
settings.add(MACHINE_LEARNING_ENABLED);
|
||||
settings.add(AUDIT_ENABLED);
|
||||
settings.add(WATCHER_ENABLED);
|
||||
settings.add(DLS_FLS_ENABLED);
|
||||
settings.add(LOGSTASH_ENABLED);
|
||||
settings.add(TRANSPORT_SSL_ENABLED);
|
||||
settings.add(HTTP_SSL_ENABLED);
|
||||
settings.add(RESERVED_REALM_ENABLED_SETTING);
|
||||
settings.add(TOKEN_SERVICE_ENABLED_SETTING);
|
||||
return Collections.unmodifiableList(settings);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue