Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -132,9 +133,23 @@ public enum ClientProperty {
// RPC
RPC_TRANSPORT_IDLE_TIMEOUT("rpc.transport.idle.timeout", "3s", PropertyType.TIMEDURATION,
"The maximum duration to leave idle transports open in the client's transport pool", "2.1.0",
false),
false);

;
private static final HashMap<String,ClientProperty> propertiesByKey = new HashMap<>();

static {
Arrays.stream(ClientProperty.values()).forEach(p -> propertiesByKey.put(p.getKey(), p));
}

/**
* Gets a {@link Property} instance with the given key.
*
* @param key property key
* @return property, or null if not found
*/
public static ClientProperty getPropertyByKey(String key) {
return propertiesByKey.get(key);
}

private final String key;
private final String defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,53 @@
import static com.google.common.base.Suppliers.memoize;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An {@link AccumuloConfiguration} that contains only default values for properties. This class is
* a singleton.
*/
public class DefaultConfiguration extends AccumuloConfiguration {

private static final Supplier<DefaultConfiguration> instance = memoize(DefaultConfiguration::new);
private static final Logger LOG = LoggerFactory.getLogger(DefaultConfiguration.class);

private final Map<String,String> resolvedProps;
private boolean keyDuplication = false;

private DefaultConfiguration() {
Map<String,String> tmp = new HashMap<>();

tmp.putAll(Arrays.stream(Property.values()).filter(p -> p.getType() != PropertyType.PREFIX)
.collect(Collectors.toMap(Property::getKey, Property::getDefaultValue)));

private final Map<String,String> resolvedProps =
Arrays.stream(Property.values()).filter(p -> p.getType() != PropertyType.PREFIX)
.collect(Collectors.toMap(Property::getKey, Property::getDefaultValue));
Map<String,
String> clientDefaults = (Arrays.stream(ClientProperty.values())
.filter(p -> p.getType() != PropertyType.PREFIX)
.collect(Collectors.toMap(ClientProperty::getKey, ClientProperty::getDefaultValue)));

private DefaultConfiguration() {}
for (Entry<String,String> e : clientDefaults.entrySet()) {
if (tmp.containsKey(e.getKey())) {
keyDuplication = true;
if (keyDuplication) {
LOG.warn("Name collision between client and server properties: {}", e.getKey());
}

} else {
tmp.put(e.getKey(), e.getValue());
}
}

resolvedProps = Map.copyOf(tmp);
}

/**
* Gets a default configuration.
Expand All @@ -51,11 +80,19 @@ public static DefaultConfiguration getInstance() {

@Override
public String get(Property property) {
if (keyDuplication) {
throw new IllegalStateException(
"Name collision between client and server properties, check the log");
}
return resolvedProps.get(property.getKey());
}

@Override
public void getProperties(Map<String,String> props, Predicate<String> filter) {
if (keyDuplication) {
throw new IllegalStateException(
"Name collision between client and server properties, check the log");
}
resolvedProps.entrySet().stream().filter(p -> filter.test(p.getKey()))
.forEach(e -> props.put(e.getKey(), e.getValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ public void testSensitiveKeys() {
|| e.getKey().toLowerCase().endsWith("secret")
|| e.getKey().startsWith(Property.INSTANCE_CRYPTO_SENSITIVE_PREFIX.getKey());

Predicate<Entry<String,String>> isMarkedSensitive = e -> Property.isSensitive(e.getKey());
Predicate<Entry<String,String>> isMarkedSensitive = e -> Property.isSensitive(e.getKey())
|| (ClientProperty.getPropertyByKey(e.getKey()) != null && e.getKey().contains("password"));

TreeMap<String,String> expected = StreamSupport.stream(conf.spliterator(), false)
.filter(sensitiveNames).collect(treeMapCollector);
Expand Down