diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/settings/get/TransportGetSettingsAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/settings/get/TransportGetSettingsAction.java index 1be42802df4..b9393d7fdd7 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/settings/get/TransportGetSettingsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/settings/get/TransportGetSettingsAction.java @@ -80,7 +80,7 @@ public class TransportGetSettingsAction extends TransportMasterNodeReadAction patterns = new CopyOnWriteArrayList<>(); + private final Set patterns; + private final String patternString; - public SettingsFilter(Settings settings) { + public SettingsFilter(Settings settings, Collection patterns) { super(settings); + HashSet set = new HashSet<>(); + for (String pattern : patterns) { + if (isValidPattern(pattern) == false) { + throw new IllegalArgumentException("invalid pattern: " + pattern); + } + } + this.patterns = Collections.unmodifiableSet(new HashSet<>(patterns)); + patternString = Strings.collectionToDelimitedString(patterns, ","); } /** - * Adds a new simple pattern to the list of filters + * Returns a set of patterns */ - public void addFilter(String pattern) { - patterns.add(pattern); + public Set getPatterns() { + return patterns; } /** - * Removes a simple pattern from the list of filters + * Returns true iff the given string is either a valid settings key pattern or a simple regular expression + * @see Regex + * @see AbstractScopedSettings#isValidKey(String) */ - public void removeFilter(String pattern) { - patterns.remove(pattern); - } - - public String getPatterns() { - return Strings.collectionToDelimitedString(patterns, ","); + public static boolean isValidPattern(String pattern) { + return AbstractScopedSettings.isValidKey(pattern) || Regex.isSimpleMatchPattern(pattern); } public void addFilterSettingParams(RestRequest request) { if (patterns.isEmpty() == false) { - request.params().put(SETTINGS_FILTER_PARAM, getPatterns()); + request.params().put(SETTINGS_FILTER_PARAM, patternString); } } public static Settings filterSettings(Params params, Settings settings) { String patterns = params.param(SETTINGS_FILTER_PARAM); - Settings filteredSettings = settings; + final Settings filteredSettings; if (patterns != null && patterns.isEmpty() == false) { - filteredSettings = SettingsFilter.filterSettings(patterns, filteredSettings); + filteredSettings = filterSettings(Strings.commaDelimitedListToSet(patterns), settings); + } else { + filteredSettings = settings; } return filteredSettings; } - public static Settings filterSettings(String patterns, Settings settings) { - String[] patternArray = Strings.delimitedListToStringArray(patterns, ","); + public Settings filter(Settings settings) { + return filterSettings(patterns, settings); + } + + private static Settings filterSettings(Iterable patterns, Settings settings) { Settings.Builder builder = Settings.settingsBuilder().put(settings); List simpleMatchPatternList = new ArrayList<>(); - for (String pattern : patternArray) { + for (String pattern : patterns) { if (Regex.isSimpleMatchPattern(pattern)) { simpleMatchPatternList.add(pattern); } else { @@ -102,4 +118,4 @@ public final class SettingsFilter extends AbstractComponent { } return builder.build(); } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java b/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java index 5d2f4d3054b..31c13a8dfd0 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java +++ b/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java @@ -20,11 +20,13 @@ package org.elasticsearch.common.settings; import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.regex.Regex; import org.elasticsearch.tribe.TribeService; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.function.Predicate; /** @@ -35,15 +37,14 @@ import java.util.function.Predicate; public class SettingsModule extends AbstractModule { private final Settings settings; - private final SettingsFilter settingsFilter; + private final Set settingsFilterPattern = new HashSet<>(); private final Map> clusterSettings = new HashMap<>(); private final Map> indexSettings = new HashMap<>(); private static final Predicate TRIBE_CLIENT_NODE_SETTINGS_PREDICATE = (s) -> s.startsWith("tribe.") && TribeService.TRIBE_SETTING_KEYS.contains(s) == false; - public SettingsModule(Settings settings, SettingsFilter settingsFilter) { + public SettingsModule(Settings settings) { this.settings = settings; - this.settingsFilter = settingsFilter; for (Setting setting : ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) { registerSetting(setting); } @@ -62,7 +63,7 @@ public class SettingsModule extends AbstractModule { clusterSettings.validate(settings.filter(acceptOnlyClusterSettings)); validateTribeSettings(settings, clusterSettings); bind(Settings.class).toInstance(settings); - bind(SettingsFilter.class).toInstance(settingsFilter); + bind(SettingsFilter.class).toInstance(new SettingsFilter(settings, settingsFilterPattern)); bind(ClusterSettings.class).toInstance(clusterSettings); bind(IndexScopedSettings.class).toInstance(indexScopedSettings); @@ -85,6 +86,23 @@ public class SettingsModule extends AbstractModule { } } + public void registerSettingsFilter(String filter) { + if (SettingsFilter.isValidPattern(filter) == false) { + throw new IllegalArgumentException("filter [" + filter +"] is invalid must be either a key or a regex pattern"); + } + if (settingsFilterPattern.contains(filter)) { + throw new IllegalArgumentException("filter [" + filter + "] has already been registered"); + } + settingsFilterPattern.add(filter); + } + + public void registerSettingsFilterIfMissing(String filter) { + if (settingsFilterPattern.contains(filter)) { + registerSettingsFilter(filter); + } + } + + public void validateTribeSettings(Settings settings, ClusterSettings clusterSettings) { Map groups = settings.filter(TRIBE_CLIENT_NODE_SETTINGS_PREDICATE).getGroups("tribe.", true); for (Map.Entry tribeSettings : groups.entrySet()) { diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 49952cf609b..db942ffd284 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -183,7 +183,6 @@ public class Node implements Closeable { throw new IllegalStateException("Failed to created node environment", ex); } final NetworkService networkService = new NetworkService(settings); - final SettingsFilter settingsFilter = new SettingsFilter(settings); final ThreadPool threadPool = new ThreadPool(settings); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); boolean success = false; @@ -197,7 +196,7 @@ public class Node implements Closeable { modules.add(pluginModule); } modules.add(new PluginsModule(pluginsService)); - SettingsModule settingsModule = new SettingsModule(this.settings, settingsFilter); + SettingsModule settingsModule = new SettingsModule(this.settings); modules.add(settingsModule); modules.add(new EnvironmentModule(environment)); modules.add(new NodeModule(this, monitorService)); diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterGetSettingsAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterGetSettingsAction.java index e7c97abbbd1..62779292ac1 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterGetSettingsAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/settings/RestClusterGetSettingsAction.java @@ -25,8 +25,10 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.AbstractScopedSettings; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; @@ -45,12 +47,14 @@ import java.io.IOException; public class RestClusterGetSettingsAction extends BaseRestHandler { private final ClusterSettings clusterSettings; + private final SettingsFilter settingsFilter; @Inject - public RestClusterGetSettingsAction(Settings settings, RestController controller, Client client, ClusterSettings clusterSettings) { + public RestClusterGetSettingsAction(Settings settings, RestController controller, Client client, ClusterSettings clusterSettings, SettingsFilter settingsFilter) { super(settings, client); this.clusterSettings = clusterSettings; controller.registerHandler(RestRequest.Method.GET, "/_cluster/settings", this); + this.settingsFilter = settingsFilter; } @Override @@ -81,7 +85,7 @@ public class RestClusterGetSettingsAction extends BaseRestHandler { if (renderDefaults) { builder.startObject("defaults"); - clusterSettings.diff(state.metaData().settings(), this.settings).toXContent(builder, params); + settingsFilter.filter(clusterSettings.diff(state.metaData().settings(), this.settings)).toXContent(builder, params); builder.endObject(); } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java index e54b3d92cbd..4c307f4ba0e 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java @@ -31,6 +31,7 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.xcontent.ToXContent.Params; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; @@ -54,13 +55,15 @@ import static org.elasticsearch.rest.RestStatus.OK; public class RestGetIndicesAction extends BaseRestHandler { private final IndexScopedSettings indexScopedSettings; + private final SettingsFilter settingsFilter; @Inject - public RestGetIndicesAction(Settings settings, RestController controller, Client client, IndexScopedSettings indexScopedSettings) { + public RestGetIndicesAction(Settings settings, RestController controller, Client client, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter) { super(settings, client); this.indexScopedSettings = indexScopedSettings; controller.registerHandler(GET, "/{index}", this); controller.registerHandler(GET, "/{index}/{type}", this); + this.settingsFilter = settingsFilter; } @Override @@ -143,7 +146,7 @@ public class RestGetIndicesAction extends BaseRestHandler { builder.endObject(); if (renderDefaults) { builder.startObject("defaults"); - indexScopedSettings.diff(settings, settings).toXContent(builder, request); + settingsFilter.filter(indexScopedSettings.diff(settings, RestGetIndicesAction.this.settings)).toXContent(builder, request); builder.endObject(); } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java index 7d8748955fd..300423a6ed5 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java @@ -28,6 +28,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; @@ -43,14 +44,16 @@ import static org.elasticsearch.rest.RestStatus.OK; public class RestGetSettingsAction extends BaseRestHandler { private final IndexScopedSettings indexScopedSettings; + private final SettingsFilter settingsFilter; @Inject - public RestGetSettingsAction(Settings settings, RestController controller, Client client, IndexScopedSettings indexScopedSettings) { + public RestGetSettingsAction(Settings settings, RestController controller, Client client, IndexScopedSettings indexScopedSettings, final SettingsFilter settingsFilter) { super(settings, client); this.indexScopedSettings = indexScopedSettings; controller.registerHandler(GET, "/{index}/_settings/{name}", this); controller.registerHandler(GET, "/_settings/{name}", this); controller.registerHandler(GET, "/{index}/_setting/{name}", this); + this.settingsFilter = settingsFilter; } @Override @@ -80,7 +83,7 @@ public class RestGetSettingsAction extends BaseRestHandler { builder.endObject(); if (renderDefaults) { builder.startObject("defaults"); - indexScopedSettings.diff(cursor.value, settings).toXContent(builder, request); + settingsFilter.filter(indexScopedSettings.diff(cursor.value, settings)).toXContent(builder, request); builder.endObject(); } builder.endObject(); diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java b/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java index 7af4e375fdc..2c2bab24605 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java @@ -36,7 +36,6 @@ import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsModule; public class ClusterModuleTests extends ModuleTestCase { @@ -74,8 +73,7 @@ public class ClusterModuleTests extends ModuleTestCase { } public void testRegisterClusterDynamicSettingDuplicate() { - final SettingsFilter settingsFilter = new SettingsFilter(Settings.EMPTY); - SettingsModule module = new SettingsModule(Settings.EMPTY, settingsFilter); + SettingsModule module = new SettingsModule(Settings.EMPTY); try { module.registerSetting(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING); } catch (IllegalArgumentException e) { @@ -84,14 +82,13 @@ public class ClusterModuleTests extends ModuleTestCase { } public void testRegisterClusterDynamicSetting() { - final SettingsFilter settingsFilter = new SettingsFilter(Settings.EMPTY); - SettingsModule module = new SettingsModule(Settings.EMPTY, settingsFilter); + SettingsModule module = new SettingsModule(Settings.EMPTY); module.registerSetting(Setting.boolSetting("foo.bar", false, true, Setting.Scope.CLUSTER)); assertInstanceBinding(module, ClusterSettings.class, service -> service.hasDynamicSetting("foo.bar")); } public void testRegisterIndexDynamicSettingDuplicate() { - SettingsModule module = new SettingsModule(Settings.EMPTY, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(Settings.EMPTY); try { module.registerSetting(EnableAllocationDecider.INDEX_ROUTING_ALLOCATION_ENABLE_SETTING); } catch (IllegalArgumentException e) { @@ -100,8 +97,7 @@ public class ClusterModuleTests extends ModuleTestCase { } public void testRegisterIndexDynamicSetting() { - final SettingsFilter settingsFilter = new SettingsFilter(Settings.EMPTY); - SettingsModule module = new SettingsModule(Settings.EMPTY, settingsFilter); + SettingsModule module = new SettingsModule(Settings.EMPTY); module.registerSetting(Setting.boolSetting("foo.bar", false, true, Setting.Scope.INDEX)); assertInstanceBinding(module, IndexScopedSettings.class, service -> service.hasDynamicSetting("foo.bar")); } diff --git a/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java b/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java index 97e527d1a0a..2cd46ef0104 100644 --- a/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java @@ -66,27 +66,8 @@ public class SettingsFilteringIT extends ESIntegTestCase { public void onModule(SettingsModule module) { module.registerSetting(Setting.groupSetting("index.filter_test.", false, Setting.Scope.INDEX)); - } - - @Override - public Collection nodeModules() { - return Collections.singletonList(new SettingsFilteringModule()); - } - } - - public static class SettingsFilteringModule extends AbstractModule { - - @Override - protected void configure() { - bind(SettingsFilteringService.class).asEagerSingleton(); - } - } - - public static class SettingsFilteringService { - @Inject - public SettingsFilteringService(SettingsFilter settingsFilter) { - settingsFilter.addFilter("index.filter_test.foo"); - settingsFilter.addFilter("index.filter_test.bar*"); + module.registerSettingsFilter("index.filter_test.foo"); + module.registerSettingsFilter("index.filter_test.bar*"); } } diff --git a/core/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java b/core/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java index 5eb8ef8ca04..14e93a3bbc3 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/SettingsFilterTests.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.common.settings; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.rest.RestRequest; @@ -25,25 +26,16 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; import static org.hamcrest.CoreMatchers.equalTo; public class SettingsFilterTests extends ESTestCase { public void testAddingAndRemovingFilters() { - SettingsFilter settingsFilter = new SettingsFilter(Settings.EMPTY); - settingsFilter.addFilter("foo"); - settingsFilter.addFilter("bar"); - settingsFilter.addFilter("baz"); - assertThat(settingsFilter.getPatterns(), equalTo("foo,bar,baz")); - - settingsFilter.removeFilter("bar"); - assertThat(settingsFilter.getPatterns(), equalTo("foo,baz")); - - settingsFilter.removeFilter("bar"); - settingsFilter.removeFilter("foo"); - settingsFilter.removeFilter("baz"); - - assertThat(settingsFilter.getPatterns(), equalTo("")); + HashSet hashSet = new HashSet<>(Arrays.asList("foo", "bar", "baz")); + SettingsFilter settingsFilter = new SettingsFilter(Settings.EMPTY, hashSet); + assertEquals(settingsFilter.getPatterns(), hashSet); } public void testSettingsFiltering() throws IOException { @@ -58,7 +50,7 @@ public class SettingsFilterTests extends ESTestCase { Settings.builder() .put("foo1", "foo1_test") .build(), - "foo,bar*" + "foo", "bar*" ); testFiltering(Settings.builder() @@ -84,7 +76,7 @@ public class SettingsFilterTests extends ESTestCase { .build(), Settings.builder() .build(), - "foo,bar*,foo*" + "foo", "bar*", "foo*" ); testFiltering(Settings.builder() @@ -98,16 +90,24 @@ public class SettingsFilterTests extends ESTestCase { .put("baz", "baz_test") .build() ); + + testFiltering(Settings.builder() + .put("a.b.something.d", "foo_test") + .put("a.b.something.c", "foo1_test") + .build(), + Settings.builder() + .put("a.b.something.c", "foo1_test") + .build(), + "a.b.*.d" + ); + } private void testFiltering(Settings source, Settings filtered, String... patterns) throws IOException { - SettingsFilter settingsFilter = new SettingsFilter(Settings.EMPTY); - for (String pattern : patterns) { - settingsFilter.addFilter(pattern); - } + SettingsFilter settingsFilter = new SettingsFilter(Settings.EMPTY, Arrays.asList(patterns)); // Test using direct filtering - Settings filteredSettings = SettingsFilter.filterSettings(settingsFilter.getPatterns(), source); + Settings filteredSettings = settingsFilter.filter(source); assertThat(filteredSettings.getAsMap().entrySet(), equalTo(filtered.getAsMap().entrySet())); // Test using toXContent filtering diff --git a/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java b/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java index e60e4043a99..67ecb78a7cf 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java @@ -26,12 +26,12 @@ public class SettingsModuleTests extends ModuleTestCase { public void testValidate() { { Settings settings = Settings.builder().put("cluster.routing.allocation.balance.shard", "2.0").build(); - SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(settings); assertInstanceBinding(module, Settings.class, (s) -> s == settings); } { Settings settings = Settings.builder().put("cluster.routing.allocation.balance.shard", "[2.0]").build(); - SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(settings); try { assertInstanceBinding(module, Settings.class, (s) -> s == settings); fail(); @@ -44,13 +44,13 @@ public class SettingsModuleTests extends ModuleTestCase { public void testRegisterSettings() { { Settings settings = Settings.builder().put("some.custom.setting", "2.0").build(); - SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(settings); module.registerSetting(Setting.floatSetting("some.custom.setting", 1.0f, false, Setting.Scope.CLUSTER)); assertInstanceBinding(module, Settings.class, (s) -> s == settings); } { Settings settings = Settings.builder().put("some.custom.setting", "false").build(); - SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(settings); module.registerSetting(Setting.floatSetting("some.custom.setting", 1.0f, false, Setting.Scope.CLUSTER)); try { assertInstanceBinding(module, Settings.class, (s) -> s == settings); @@ -64,12 +64,12 @@ public class SettingsModuleTests extends ModuleTestCase { public void testTribeSetting() { { Settings settings = Settings.builder().put("tribe.t1.cluster.routing.allocation.balance.shard", "2.0").build(); - SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(settings); assertInstanceBinding(module, Settings.class, (s) -> s == settings); } { Settings settings = Settings.builder().put("tribe.t1.cluster.routing.allocation.balance.shard", "[2.0]").build(); - SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(settings); try { assertInstanceBinding(module, Settings.class, (s) -> s == settings); fail(); @@ -82,12 +82,12 @@ public class SettingsModuleTests extends ModuleTestCase { public void testSpecialTribeSetting() { { Settings settings = Settings.builder().put("tribe.blocks.write", "false").build(); - SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(settings); assertInstanceBinding(module, Settings.class, (s) -> s == settings); } { Settings settings = Settings.builder().put("tribe.blocks.write", "BOOM").build(); - SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(settings); try { assertInstanceBinding(module, Settings.class, (s) -> s == settings); fail(); @@ -97,7 +97,7 @@ public class SettingsModuleTests extends ModuleTestCase { } { Settings settings = Settings.builder().put("tribe.blocks.wtf", "BOOM").build(); - SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(settings); try { assertInstanceBinding(module, Settings.class, (s) -> s == settings); fail(); @@ -111,13 +111,13 @@ public class SettingsModuleTests extends ModuleTestCase { public void testLoggerSettings() { { Settings settings = Settings.builder().put("logger._root", "TRACE").put("logger.transport", "INFO").build(); - SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(settings); assertInstanceBinding(module, Settings.class, (s) -> s == settings); } { Settings settings = Settings.builder().put("logger._root", "BOOM").put("logger.transport", "WOW").build(); - SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + SettingsModule module = new SettingsModule(settings); try { assertInstanceBinding(module, Settings.class, (s) -> s == settings); fail(); diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index ac272171ede..d8d018284e9 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -197,7 +197,7 @@ public abstract class AbstractQueryTestCase> final TestClusterService clusterService = new TestClusterService(); clusterService.setState(new ClusterState.Builder(clusterService.state()).metaData(new MetaData.Builder().put( new IndexMetaData.Builder(index.getName()).settings(indexSettings).numberOfShards(1).numberOfReplicas(0)))); - SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings)); + SettingsModule settingsModule = new SettingsModule(settings); settingsModule.registerSetting(InternalSettingsPlugin.VERSION_CREATED); final Client proxy = (Client) Proxy.newProxyInstance( Client.class.getClassLoader(), diff --git a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java index 7561b9b2b12..c16759e1b92 100644 --- a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; @@ -50,14 +49,14 @@ public class NativeScriptTests extends ESTestCase { .put("node.name", "testNativeScript") .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); - SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings)); + SettingsModule settingsModule = new SettingsModule(settings); ScriptModule scriptModule = new ScriptModule(); scriptModule.prepareSettings(settingsModule); scriptModule.registerScript("my", MyNativeScriptFactory.class); Injector injector = new ModulesBuilder().add( new EnvironmentModule(new Environment(settings)), new ThreadPoolModule(new ThreadPool(settings)), - new SettingsModule(settings, new SettingsFilter(settings)), + new SettingsModule(settings), scriptModule).createInjector(); ScriptService scriptService = injector.getInstance(ScriptService.class); diff --git a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java index b214a1710ba..8521bd20395 100644 --- a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.text.Text; import org.elasticsearch.common.unit.TimeValue; @@ -88,7 +87,7 @@ public class SearchSourceBuilderTests extends ESTestCase { .build(); namedWriteableRegistry = new NamedWriteableRegistry(); injector = new ModulesBuilder().add( - new SettingsModule(settings, new SettingsFilter(settings)), + new SettingsModule(settings), new ThreadPoolModule(new ThreadPool(settings)), new SearchModule(settings, namedWriteableRegistry) { @Override diff --git a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java index f667d863556..e92a28db86b 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java +++ b/core/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java @@ -34,6 +34,7 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; @@ -76,26 +77,10 @@ public class MockRepository extends FsRepository { repositoriesModule.registerRepository("mock", MockRepository.class, BlobStoreIndexShardRepository.class); } - @Override - public Collection nodeModules() { - return Collections.singletonList(new SettingsFilteringModule()); + public void onModule(SettingsModule module) { + module.registerSettingsFilter("secret.mock.password"); + } - - public static class SettingsFilteringModule extends AbstractModule { - - @Override - protected void configure() { - bind(SettingsFilteringService.class).asEagerSingleton(); - } - } - - public static class SettingsFilteringService { - @Inject - public SettingsFilteringService(SettingsFilter settingsFilter) { - settingsFilter.addFilter("secret.mock.password"); - } - } - } private final AtomicLong failureCounter = new AtomicLong(); diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java index a9c75b31a74..2e19f660047 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; @@ -101,7 +100,7 @@ public class TemplateQueryParserTests extends ESTestCase { }); IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings); Index index = idxSettings.getIndex(); - SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings)); + SettingsModule settingsModule = new SettingsModule(settings); ScriptModule scriptModule = new ScriptModule(); scriptModule.prepareSettings(settingsModule); // TODO: make this use a mock engine instead of mustache and it will no longer be messy! diff --git a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java index cca590b2c51..a952c8982cc 100644 --- a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java +++ b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisTestUtils.java @@ -24,7 +24,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; @@ -46,7 +45,7 @@ public class AnalysisTestUtils { .build(); AnalysisModule analysisModule = new AnalysisModule(new Environment(settings)); new AnalysisICUPlugin().onModule(analysisModule); - Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings, new SettingsFilter(settings)), + Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), analysisModule) .createInjector(); final AnalysisService analysisService = parentInjector.getInstance(AnalysisRegistry.class).build(IndexSettingsModule.newIndexSettings(index, indexSettings)); diff --git a/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java b/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java index b34a8908f43..0b3f026b010 100644 --- a/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java +++ b/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java @@ -29,7 +29,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; @@ -203,7 +202,7 @@ public class KuromojiAnalysisTests extends ESTestCase { .loadFromStream(json, getClass().getResourceAsStream(json)) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); - final SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings)); + final SettingsModule settingsModule = new SettingsModule(settings); settingsModule.registerSetting(InternalSettingsPlugin.VERSION_CREATED); Index index = new Index("test", "_na_"); diff --git a/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java b/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java index 18fe8010fd8..f3d1d12f45a 100644 --- a/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java +++ b/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java @@ -24,7 +24,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; @@ -59,7 +58,7 @@ public class SimplePhoneticAnalysisTests extends ESTestCase { Index index = new Index("test", "_na_"); AnalysisModule analysisModule = new AnalysisModule(new Environment(settings)); new AnalysisPhoneticPlugin().onModule(analysisModule); - SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings)); + SettingsModule settingsModule = new SettingsModule(settings); settingsModule.registerSetting(InternalSettingsPlugin.VERSION_CREATED); Injector parentInjector = new ModulesBuilder().add(settingsModule, new EnvironmentModule(new Environment(settings)), analysisModule) diff --git a/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java b/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java index 613ff88f1ae..76761a67c9f 100644 --- a/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java +++ b/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SimpleSmartChineseAnalysisTests.java @@ -24,7 +24,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; @@ -52,7 +51,7 @@ public class SimpleSmartChineseAnalysisTests extends ESTestCase { .build(); AnalysisModule analysisModule = new AnalysisModule(new Environment(settings)); new AnalysisSmartChinesePlugin().onModule(analysisModule); - SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings)); + SettingsModule settingsModule = new SettingsModule(settings); settingsModule.registerSetting(InternalSettingsPlugin.VERSION_CREATED); Injector parentInjector = new ModulesBuilder().add(settingsModule, new EnvironmentModule(new Environment(settings)), analysisModule) diff --git a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java index 2a6309f4af8..8f76c908e4b 100644 --- a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java +++ b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java @@ -26,11 +26,9 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; -import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.pl.PolishStemTokenFilterFactory; import org.elasticsearch.indices.analysis.AnalysisModule; import org.elasticsearch.plugin.analysis.stempel.AnalysisStempelPlugin; @@ -56,7 +54,7 @@ public class PolishAnalysisTests extends ESTestCase { AnalysisModule analysisModule = new AnalysisModule(new Environment(settings)); new AnalysisStempelPlugin().onModule(analysisModule); - SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings)); + SettingsModule settingsModule = new SettingsModule(settings); settingsModule.registerSetting(InternalSettingsPlugin.VERSION_CREATED); Injector parentInjector = new ModulesBuilder().add(settingsModule, new EnvironmentModule(new Environment(settings)), analysisModule) diff --git a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java index 0b604b11ce0..890f4eceec1 100644 --- a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java +++ b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java @@ -29,7 +29,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; @@ -101,7 +100,7 @@ public class SimplePolishTokenFilterTests extends ESTestCase { private AnalysisService createAnalysisService(Index index, Settings settings) throws IOException { AnalysisModule analysisModule = new AnalysisModule(new Environment(settings)); new AnalysisStempelPlugin().onModule(analysisModule); - SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings)); + SettingsModule settingsModule = new SettingsModule(settings); settingsModule.registerSetting(InternalSettingsPlugin.VERSION_CREATED); Injector parentInjector = new ModulesBuilder().add(settingsModule, new EnvironmentModule(new Environment(settings)), analysisModule) diff --git a/plugins/discovery-azure/src/main/java/org/elasticsearch/cloud/azure/AzureDiscoveryModule.java b/plugins/discovery-azure/src/main/java/org/elasticsearch/cloud/azure/AzureDiscoveryModule.java index 5a9b9f5f412..5c6102a7f9c 100644 --- a/plugins/discovery-azure/src/main/java/org/elasticsearch/cloud/azure/AzureDiscoveryModule.java +++ b/plugins/discovery-azure/src/main/java/org/elasticsearch/cloud/azure/AzureDiscoveryModule.java @@ -23,7 +23,6 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cloud.azure.management.AzureComputeService; import org.elasticsearch.cloud.azure.management.AzureComputeService.Management; import org.elasticsearch.cloud.azure.management.AzureComputeServiceImpl; -import org.elasticsearch.cloud.azure.management.AzureComputeSettingsFilter; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; @@ -60,8 +59,6 @@ public class AzureDiscoveryModule extends AbstractModule { @Override protected void configure() { logger.debug("starting azure services"); - bind(AzureComputeSettingsFilter.class).asEagerSingleton(); - // If we have set discovery to azure, let's start the azure compute service if (isDiscoveryReady(settings, logger)) { logger.debug("starting azure discovery service"); diff --git a/plugins/discovery-azure/src/main/java/org/elasticsearch/cloud/azure/management/AzureComputeSettingsFilter.java b/plugins/discovery-azure/src/main/java/org/elasticsearch/cloud/azure/management/AzureComputeSettingsFilter.java deleted file mode 100644 index 3e9919401ab..00000000000 --- a/plugins/discovery-azure/src/main/java/org/elasticsearch/cloud/azure/management/AzureComputeSettingsFilter.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.cloud.azure.management; - -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; - -import static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.KEYSTORE_PASSWORD_SETTING; -import static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.KEYSTORE_PATH_SETTING; -import static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.KEYSTORE_TYPE_SETTING; -import static org.elasticsearch.cloud.azure.management.AzureComputeService.Management.SUBSCRIPTION_ID_SETTING; - -public class AzureComputeSettingsFilter extends AbstractComponent { - - @Inject - public AzureComputeSettingsFilter(Settings settings, SettingsFilter settingsFilter) { - super(settings); - // Cloud management API settings we need to hide - settingsFilter.addFilter(KEYSTORE_PATH_SETTING.getKey()); - settingsFilter.addFilter(KEYSTORE_PASSWORD_SETTING.getKey()); - settingsFilter.addFilter(KEYSTORE_TYPE_SETTING.getKey()); - settingsFilter.addFilter(SUBSCRIPTION_ID_SETTING.getKey()); - } -} diff --git a/plugins/discovery-azure/src/main/java/org/elasticsearch/plugin/discovery/azure/AzureDiscoveryPlugin.java b/plugins/discovery-azure/src/main/java/org/elasticsearch/plugin/discovery/azure/AzureDiscoveryPlugin.java index 9bee3b81ff3..a8282dc9561 100644 --- a/plugins/discovery-azure/src/main/java/org/elasticsearch/plugin/discovery/azure/AzureDiscoveryPlugin.java +++ b/plugins/discovery-azure/src/main/java/org/elasticsearch/plugin/discovery/azure/AzureDiscoveryPlugin.java @@ -34,9 +34,6 @@ import org.elasticsearch.plugins.Plugin; import java.util.Collection; import java.util.Collections; -/** - * - */ public class AzureDiscoveryPlugin extends Plugin { private final Settings settings; @@ -77,5 +74,10 @@ public class AzureDiscoveryPlugin extends Plugin { settingsModule.registerSetting(AzureComputeService.Management.SUBSCRIPTION_ID_SETTING); settingsModule.registerSetting(AzureComputeService.Management.SERVICE_NAME_SETTING); settingsModule.registerSetting(AzureComputeService.Discovery.HOST_TYPE_SETTING); + // Cloud management API settings we need to hide + settingsModule.registerSettingsFilter(AzureComputeService.Management.KEYSTORE_PATH_SETTING.getKey()); + settingsModule.registerSettingsFilter(AzureComputeService.Management.KEYSTORE_PASSWORD_SETTING.getKey()); + settingsModule.registerSettingsFilter(AzureComputeService.Management.KEYSTORE_TYPE_SETTING.getKey()); + settingsModule.registerSettingsFilter(AzureComputeService.Management.SUBSCRIPTION_ID_SETTING.getKey()); } } diff --git a/plugins/discovery-ec2/src/main/java/org/elasticsearch/cloud/aws/AwsEc2ServiceImpl.java b/plugins/discovery-ec2/src/main/java/org/elasticsearch/cloud/aws/AwsEc2ServiceImpl.java index 51dfd55b7b0..3c300e47722 100644 --- a/plugins/discovery-ec2/src/main/java/org/elasticsearch/cloud/aws/AwsEc2ServiceImpl.java +++ b/plugins/discovery-ec2/src/main/java/org/elasticsearch/cloud/aws/AwsEc2ServiceImpl.java @@ -43,7 +43,6 @@ import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; import java.util.Locale; import java.util.Random; @@ -58,15 +57,8 @@ public class AwsEc2ServiceImpl extends AbstractLifecycleComponent private AmazonEC2Client client; @Inject - public AwsEc2ServiceImpl(Settings settings, SettingsFilter settingsFilter, NetworkService networkService, DiscoveryNodeService discoveryNodeService) { + public AwsEc2ServiceImpl(Settings settings, NetworkService networkService, DiscoveryNodeService discoveryNodeService) { super(settings); - // Filter global settings - settingsFilter.addFilter(CLOUD_AWS.KEY); - settingsFilter.addFilter(CLOUD_AWS.SECRET); - settingsFilter.addFilter(CLOUD_AWS.PROXY_PASSWORD); - settingsFilter.addFilter(CLOUD_EC2.KEY); - settingsFilter.addFilter(CLOUD_EC2.SECRET); - settingsFilter.addFilter(CLOUD_EC2.PROXY_PASSWORD); // add specific ec2 name resolver networkService.addCustomNameResolver(new Ec2NameResolver(settings)); discoveryNodeService.addCustomAttributeProvider(new Ec2CustomNodeAttributes(settings)); diff --git a/plugins/discovery-ec2/src/main/java/org/elasticsearch/plugin/discovery/ec2/Ec2DiscoveryPlugin.java b/plugins/discovery-ec2/src/main/java/org/elasticsearch/plugin/discovery/ec2/Ec2DiscoveryPlugin.java index 3b3d206c255..2e689d9d26c 100644 --- a/plugins/discovery-ec2/src/main/java/org/elasticsearch/plugin/discovery/ec2/Ec2DiscoveryPlugin.java +++ b/plugins/discovery-ec2/src/main/java/org/elasticsearch/plugin/discovery/ec2/Ec2DiscoveryPlugin.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collection; import org.elasticsearch.SpecialPermission; +import org.elasticsearch.cloud.aws.AwsEc2Service; import org.elasticsearch.cloud.aws.AwsEc2ServiceImpl; import org.elasticsearch.cloud.aws.Ec2Module; import org.elasticsearch.common.component.LifecycleComponent; @@ -32,6 +33,7 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.ec2.AwsEc2UnicastHostsProvider; import org.elasticsearch.discovery.ec2.Ec2Discovery; @@ -100,4 +102,14 @@ public class Ec2DiscoveryPlugin extends Plugin { discoveryModule.addUnicastHostProvider(AwsEc2UnicastHostsProvider.class); } } + + public void onModule(SettingsModule settingsModule) { + // Filter global settings + settingsModule.registerSettingsFilterIfMissing(AwsEc2Service.CLOUD_AWS.KEY); + settingsModule.registerSettingsFilterIfMissing(AwsEc2Service.CLOUD_AWS.SECRET); + settingsModule.registerSettingsFilterIfMissing(AwsEc2Service.CLOUD_AWS.PROXY_PASSWORD); + settingsModule.registerSettingsFilterIfMissing(AwsEc2Service.CLOUD_EC2.KEY); + settingsModule.registerSettingsFilterIfMissing(AwsEc2Service.CLOUD_EC2.SECRET); + settingsModule.registerSettingsFilterIfMissing(AwsEc2Service.CLOUD_EC2.PROXY_PASSWORD); + } } diff --git a/plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/AzureRepositoryModule.java b/plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/AzureRepositoryModule.java index aa78ed4d835..92a87ff8ee1 100644 --- a/plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/AzureRepositoryModule.java +++ b/plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/AzureRepositoryModule.java @@ -21,7 +21,6 @@ package org.elasticsearch.cloud.azure; import org.elasticsearch.cloud.azure.storage.AzureStorageService; import org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl; -import org.elasticsearch.cloud.azure.storage.AzureStorageSettingsFilter; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.ESLogger; @@ -51,9 +50,6 @@ public class AzureRepositoryModule extends AbstractModule { @Override protected void configure() { - logger.debug("starting azure services"); - bind(AzureStorageSettingsFilter.class).asEagerSingleton(); - // If we have settings for azure repository, let's start the azure storage service logger.debug("starting azure repository service"); bind(AzureStorageService.class).to(storageServiceImpl).asEagerSingleton(); diff --git a/plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/storage/AzureStorageSettingsFilter.java b/plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/storage/AzureStorageSettingsFilter.java deleted file mode 100644 index 76ac68bd436..00000000000 --- a/plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/storage/AzureStorageSettingsFilter.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.cloud.azure.storage; - -import org.elasticsearch.cloud.azure.storage.AzureStorageService.Storage; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; - -public class AzureStorageSettingsFilter extends AbstractComponent { - - @Inject - public AzureStorageSettingsFilter(Settings settings, SettingsFilter settingsFilter) { - super(settings); - // Cloud storage API settings needed to be hidden - settingsFilter.addFilter(Storage.PREFIX + "*.account"); - settingsFilter.addFilter(Storage.PREFIX + "*.key"); - settingsFilter.addFilter(Storage.ACCOUNT_SETTING.getKey()); - } -} diff --git a/plugins/repository-azure/src/main/java/org/elasticsearch/plugin/repository/azure/AzureRepositoryPlugin.java b/plugins/repository-azure/src/main/java/org/elasticsearch/plugin/repository/azure/AzureRepositoryPlugin.java index 0c593e24ebf..616b150f954 100644 --- a/plugins/repository-azure/src/main/java/org/elasticsearch/plugin/repository/azure/AzureRepositoryPlugin.java +++ b/plugins/repository-azure/src/main/java/org/elasticsearch/plugin/repository/azure/AzureRepositoryPlugin.java @@ -74,5 +74,9 @@ public class AzureRepositoryPlugin extends Plugin { module.registerSetting(AzureStorageService.Storage.BASE_PATH_SETTING); module.registerSetting(AzureStorageService.Storage.CHUNK_SIZE_SETTING); module.registerSetting(AzureStorageService.Storage.LOCATION_MODE_SETTING); + // Cloud storage API settings needed to be hidden + module.registerSettingsFilter(AzureStorageService.Storage.PREFIX + "*.account"); + module.registerSettingsFilter(AzureStorageService.Storage.PREFIX + "*.key"); + module.registerSettingsFilter(AzureStorageService.Storage.ACCOUNT_SETTING.getKey()); } } diff --git a/plugins/repository-azure/src/test/java/org/elasticsearch/cloud/azure/storage/AzureStorageSettingsFilterTests.java b/plugins/repository-azure/src/test/java/org/elasticsearch/cloud/azure/storage/AzureStorageSettingsFilterTests.java index 6e36b27cebe..6f215069564 100644 --- a/plugins/repository-azure/src/test/java/org/elasticsearch/cloud/azure/storage/AzureStorageSettingsFilterTests.java +++ b/plugins/repository-azure/src/test/java/org/elasticsearch/cloud/azure/storage/AzureStorageSettingsFilterTests.java @@ -19,10 +19,13 @@ package org.elasticsearch.cloud.azure.storage; +import org.elasticsearch.common.inject.ModuleTestCase; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.plugin.repository.azure.AzureRepositoryPlugin; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; @@ -43,14 +46,13 @@ public class AzureStorageSettingsFilterTests extends ESTestCase { .build(); public void testSettingsFiltering() throws IOException { - - SettingsFilter settingsFilter = new SettingsFilter(Settings.EMPTY); - - // We just add Azure filters - new AzureStorageSettingsFilter(Settings.EMPTY, settingsFilter); + AzureRepositoryPlugin p = new AzureRepositoryPlugin(Settings.EMPTY); + SettingsModule module = new SettingsModule(Settings.EMPTY); + p.onModule(module); + SettingsFilter settingsFilter = ModuleTestCase.bindAndGetInstance(module, SettingsFilter.class); // Test using direct filtering - Settings filteredSettings = SettingsFilter.filterSettings(settingsFilter.getPatterns(), settings); + Settings filteredSettings = settingsFilter.filter(settings); assertThat(filteredSettings.getAsMap().keySet(), contains("cloud.azure.storage.azure1.default")); // Test using toXContent filtering diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java index a897cf6f899..5da3b33585c 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java @@ -54,16 +54,8 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent, AmazonS3Client> clients = new HashMap, AmazonS3Client>(); @Inject - public InternalAwsS3Service(Settings settings, SettingsFilter settingsFilter) { + public InternalAwsS3Service(Settings settings) { super(settings); - settingsFilter.addFilter(CLOUD_AWS.KEY); - settingsFilter.addFilter(CLOUD_AWS.SECRET); - settingsFilter.addFilter(CLOUD_AWS.PROXY_PASSWORD); - settingsFilter.addFilter(CLOUD_S3.KEY); - settingsFilter.addFilter(CLOUD_S3.SECRET); - settingsFilter.addFilter(CLOUD_S3.PROXY_PASSWORD); - settingsFilter.addFilter("access_key"); - settingsFilter.addFilter("secret_key"); } @Override diff --git a/plugins/repository-s3/src/main/java/org/elasticsearch/plugin/repository/s3/S3RepositoryPlugin.java b/plugins/repository-s3/src/main/java/org/elasticsearch/plugin/repository/s3/S3RepositoryPlugin.java index 2b486e5505c..9e3934a1c88 100644 --- a/plugins/repository-s3/src/main/java/org/elasticsearch/plugin/repository/s3/S3RepositoryPlugin.java +++ b/plugins/repository-s3/src/main/java/org/elasticsearch/plugin/repository/s3/S3RepositoryPlugin.java @@ -20,9 +20,11 @@ package org.elasticsearch.plugin.repository.s3; import org.elasticsearch.SpecialPermission; +import org.elasticsearch.cloud.aws.AwsS3Service; import org.elasticsearch.cloud.aws.S3Module; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoriesModule; @@ -85,4 +87,15 @@ public class S3RepositoryPlugin extends Plugin { public void onModule(RepositoriesModule repositoriesModule) { repositoriesModule.registerRepository(S3Repository.TYPE, S3Repository.class, BlobStoreIndexShardRepository.class); } + + public void onModule(SettingsModule module) { + module.registerSettingsFilterIfMissing(AwsS3Service.CLOUD_AWS.KEY); + module.registerSettingsFilterIfMissing(AwsS3Service.CLOUD_AWS.SECRET); + module.registerSettingsFilterIfMissing(AwsS3Service.CLOUD_AWS.PROXY_PASSWORD); + module.registerSettingsFilterIfMissing(AwsS3Service.CLOUD_S3.KEY); + module.registerSettingsFilterIfMissing(AwsS3Service.CLOUD_S3.SECRET); + module.registerSettingsFilterIfMissing(AwsS3Service.CLOUD_S3.PROXY_PASSWORD); + module.registerSettingsFilter("access_key"); // WTF is this? + module.registerSettingsFilter("secret_key"); // WTF is this? + } } diff --git a/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java b/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java index 959b03e2375..da2fcd2b4d3 100644 --- a/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java +++ b/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java @@ -45,8 +45,8 @@ public class TestAwsS3Service extends InternalAwsS3Service { IdentityHashMap clients = new IdentityHashMap(); @Inject - public TestAwsS3Service(Settings settings, SettingsFilter settingsFilter) { - super(settings, settingsFilter); + public TestAwsS3Service(Settings settings) { + super(settings); } diff --git a/core/src/test/java/org/elasticsearch/common/inject/ModuleTestCase.java b/test/framework/src/main/java/org/elasticsearch/common/inject/ModuleTestCase.java similarity index 91% rename from core/src/test/java/org/elasticsearch/common/inject/ModuleTestCase.java rename to test/framework/src/main/java/org/elasticsearch/common/inject/ModuleTestCase.java index 8ba500333e1..5ed024abfc8 100644 --- a/core/src/test/java/org/elasticsearch/common/inject/ModuleTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/common/inject/ModuleTestCase.java @@ -173,6 +173,28 @@ public abstract class ModuleTestCase extends ESTestCase { assertInstanceBindingWithAnnotation(module, to, tester, null); } + /** + * Configures the module, and returns an instance bound to the "to" class. + */ + public static T bindAndGetInstance(Module module, Class to) { + List elements = Elements.getElements(module); + for (Element element : elements) { + if (element instanceof InstanceBinding) { + InstanceBinding binding = (InstanceBinding) element; + if (to.equals(binding.getKey().getTypeLiteral().getType())) { + return to.cast(binding.getInstance()); + } + } else if (element instanceof ProviderInstanceBinding) { + ProviderInstanceBinding binding = (ProviderInstanceBinding) element; + if (to.equals(binding.getKey().getTypeLiteral().getType())) { + return to.cast(binding.getProviderInstance().get()); + } + } + } + fail("can't get instance for class " + to); + return null; // won't happen ;) + } + /** * Like {@link #assertInstanceBinding(Module, Class, Predicate)}, but filters the * classes checked by the given annotation.