Merge pull request #16425 from s1monw/fix_settings_filter

Rewrite SettingsFilter to be immutable
This commit is contained in:
Simon Willnauer 2016-02-04 10:15:44 +01:00
commit 9649c791c1
36 changed files with 199 additions and 254 deletions

View File

@ -80,7 +80,7 @@ public class TransportGetSettingsAction extends TransportMasterNodeReadAction<Ge
continue;
}
Settings settings = SettingsFilter.filterSettings(settingsFilter.getPatterns(), indexMetaData.getSettings());
Settings settings = settingsFilter.filter(indexMetaData.getSettings());
if (request.humanReadable()) {
settings = IndexMetaData.addHumanReadableSettings(settings);
}

View File

@ -129,7 +129,6 @@ public class TransportClient extends AbstractClient {
final ThreadPool threadPool = new ThreadPool(settings);
final NetworkService networkService = new NetworkService(settings);
final SettingsFilter settingsFilter = new SettingsFilter(settings);
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
boolean success = false;
try {
@ -140,7 +139,7 @@ public class TransportClient extends AbstractClient {
modules.add(pluginModule);
}
modules.add(new PluginsModule(pluginsService));
modules.add(new SettingsModule(settings, settingsFilter));
modules.add(new SettingsModule(settings));
modules.add(new NetworkModule(networkService, settings, true, namedWriteableRegistry));
modules.add(new ClusterNameModule(settings));
modules.add(new ThreadPoolModule(threadPool));

View File

@ -25,14 +25,18 @@ import org.elasticsearch.common.xcontent.ToXContent.Params;
import org.elasticsearch.rest.RestRequest;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.Set;
/**
*
* A class that allows to filter settings objects by simple regular expression patterns or full settings keys.
* It's used for response filtering on the rest layer to for instance filter out sensitive information like access keys.
*/
public final class SettingsFilter extends AbstractComponent {
/**
@ -40,50 +44,62 @@ public final class SettingsFilter extends AbstractComponent {
*/
public static String SETTINGS_FILTER_PARAM = "settings_filter";
private final CopyOnWriteArrayList<String> patterns = new CopyOnWriteArrayList<>();
private final Set<String> patterns;
private final String patternString;
public SettingsFilter(Settings settings) {
public SettingsFilter(Settings settings, Collection<String> patterns) {
super(settings);
HashSet<String> 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<String> getPatterns() {
return patterns;
}
/**
* Removes a simple pattern from the list of filters
* Returns <code>true</code> 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<String> patterns, Settings settings) {
Settings.Builder builder = Settings.settingsBuilder().put(settings);
List<String> simpleMatchPatternList = new ArrayList<>();
for (String pattern : patternArray) {
for (String pattern : patterns) {
if (Regex.isSimpleMatchPattern(pattern)) {
simpleMatchPatternList.add(pattern);
} else {

View File

@ -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<String> settingsFilterPattern = new HashSet<>();
private final Map<String, Setting<?>> clusterSettings = new HashMap<>();
private final Map<String, Setting<?>> indexSettings = new HashMap<>();
private static final Predicate<String> 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<String, Settings> groups = settings.filter(TRIBE_CLIENT_NODE_SETTINGS_PREDICATE).getGroups("tribe.", true);
for (Map.Entry<String, Settings> tribeSettings : groups.entrySet()) {

View File

@ -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));

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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();

View File

@ -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"));
}

View File

@ -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<Module> nodeModules() {
return Collections.<Module>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*");
}
}

View File

@ -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<String> 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

View File

@ -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();

View File

@ -197,7 +197,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
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(),

View File

@ -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);

View File

@ -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

View File

@ -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,28 +77,12 @@ public class MockRepository extends FsRepository {
repositoriesModule.registerRepository("mock", MockRepository.class, BlobStoreIndexShardRepository.class);
}
@Override
public Collection<Module> nodeModules() {
return Collections.<Module>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();
public long getFailureCount() {

View File

@ -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!

View File

@ -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));

View File

@ -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_");

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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");

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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<AwsEc2Service>
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));

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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

View File

@ -54,16 +54,8 @@ public class InternalAwsS3Service extends AbstractLifecycleComponent<AwsS3Servic
private Map<Tuple<String, String>, AmazonS3Client> clients = new HashMap<Tuple<String,String>, 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

View File

@ -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?
}
}

View File

@ -45,8 +45,8 @@ public class TestAwsS3Service extends InternalAwsS3Service {
IdentityHashMap<AmazonS3, TestAmazonS3> clients = new IdentityHashMap<AmazonS3, TestAmazonS3>();
@Inject
public TestAwsS3Service(Settings settings, SettingsFilter settingsFilter) {
super(settings, settingsFilter);
public TestAwsS3Service(Settings settings) {
super(settings);
}

View File

@ -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> T bindAndGetInstance(Module module, Class<T> to) {
List<Element> 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.