Adopt settings cleanups from core (elastic/x-pack-elasticsearch#2605)
Relates to elastic/elasticsearch#26739 Original commit: elastic/x-pack-elasticsearch@dd13d099de
This commit is contained in:
parent
1bb9c4fe71
commit
e7b5702f50
|
@ -9,6 +9,10 @@ import org.elasticsearch.common.Booleans;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.SettingsException;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.xpack.common.http.HttpClient;
|
||||
import org.elasticsearch.xpack.common.http.HttpMethod;
|
||||
import org.elasticsearch.xpack.common.http.HttpProxy;
|
||||
|
@ -18,6 +22,7 @@ import org.elasticsearch.xpack.common.http.Scheme;
|
|||
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Collections;
|
||||
|
@ -68,7 +73,15 @@ public class JiraAccount {
|
|||
if (Strings.isEmpty(this.password)) {
|
||||
throw requiredSettingException(name, PASSWORD_SETTING);
|
||||
}
|
||||
this.issueDefaults = Collections.unmodifiableMap(settings.getAsSettings(ISSUE_DEFAULTS_SETTING).getAsStructuredMap());
|
||||
try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) {
|
||||
builder.startObject();
|
||||
settings.getAsSettings(ISSUE_DEFAULTS_SETTING).toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
this.issueDefaults = Collections.unmodifiableMap(XContentType.JSON.xContent()
|
||||
.createParser(new NamedXContentRegistry(Collections.emptyList()), builder.bytes()).map());
|
||||
} catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.elasticsearch.action.ActionListener;
|
|||
import org.elasticsearch.bootstrap.BootstrapCheck;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.SettingsException;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.watcher.FileChangesListener;
|
||||
import org.elasticsearch.watcher.FileWatcher;
|
||||
|
@ -127,8 +128,8 @@ public class DnRoleMapper implements UserRoleMapper {
|
|||
}
|
||||
}
|
||||
|
||||
try (InputStream in = Files.newInputStream(path)) {
|
||||
Settings settings = Settings.builder().loadFromStream(path.toString(), in).build();
|
||||
try {
|
||||
Settings settings = Settings.builder().loadFromPath(path).build();
|
||||
|
||||
Map<DN, Set<String>> dnToRoles = new HashMap<>();
|
||||
Set<String> roles = settings.names();
|
||||
|
@ -163,7 +164,7 @@ public class DnRoleMapper implements UserRoleMapper {
|
|||
logger.debug("[{}] role mappings found in file [{}] for realm [{}/{}]", dnToRoles.size(), path.toAbsolutePath(), realmType,
|
||||
realmName);
|
||||
return unmodifiableMap(dnToRoles);
|
||||
} catch (IOException | YAMLException e) {
|
||||
} catch (IOException | SettingsException e) {
|
||||
throw new ElasticsearchException("could not read realm [" + realmType + "/" + realmName + "] role mappings file [" +
|
||||
path.toAbsolutePath() + "]", e);
|
||||
}
|
||||
|
|
|
@ -83,10 +83,8 @@ public final class RestrictedTrustConfig extends TrustConfig {
|
|||
}
|
||||
|
||||
private CertificateTrustRestrictions readTrustGroup(Path path) throws IOException {
|
||||
try (InputStream in = Files.newInputStream(path)) {
|
||||
Settings settings = Settings.builder().loadFromStream(path.toString(), in).build();
|
||||
Settings settings = Settings.builder().loadFromPath(path).build();
|
||||
final String[] trustNodeNames = settings.getAsArray(RESTRICTIONS_KEY_SUBJECT_NAME);
|
||||
return new CertificateTrustRestrictions(Arrays.asList(trustNodeNames));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -586,7 +586,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase {
|
|||
|
||||
public void testChildrenAggregation() throws Exception {
|
||||
assertAcked(client().admin().indices().prepareCreate("test")
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.setSettings(Settings.builder().put("index.version.created", Version.V_5_6_0.id))
|
||||
.addMapping("type1", "field1", "type=text", "field2", "type=text")
|
||||
.addMapping("type2", "_parent", "type=type1", "field3", "type=text,fielddata=true")
|
||||
);
|
||||
|
@ -643,7 +643,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase {
|
|||
|
||||
public void testParentChild_parentField() {
|
||||
assertAcked(prepareCreate("test")
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.setSettings(Settings.builder().put("index.version.created", Version.V_5_6_0.id))
|
||||
.addMapping("parent")
|
||||
.addMapping("child", "_parent", "type=parent", "field1", "type=text", "field2", "type=text", "field3", "type=text"));
|
||||
ensureGreen();
|
||||
|
|
|
@ -1221,7 +1221,7 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase {
|
|||
|
||||
public void testParentChild_parentField() {
|
||||
assertAcked(prepareCreate("test")
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.setSettings(Settings.builder().put("index.version.created", Version.V_5_6_0.id))
|
||||
.addMapping("parent")
|
||||
.addMapping("child", "_parent", "type=parent"));
|
||||
ensureGreen();
|
||||
|
|
|
@ -214,7 +214,7 @@ public abstract class SecurityIntegTestCase extends ESIntegTestCase {
|
|||
// Disable native ML autodetect_process as the c++ controller won't be available
|
||||
.put(MachineLearning.AUTODETECT_PROCESS.getKey(), false);
|
||||
Settings customSettings = customSecuritySettingsSource.nodeSettings(nodeOrdinal);
|
||||
builder.put(customSettings.getAsMap()); // handle secure settings separately
|
||||
builder.put(customSettings, false); // handle secure settings separately
|
||||
Settings.Builder customBuilder = Settings.builder().put(customSettings);
|
||||
if (customBuilder.getSecureSettings() != null) {
|
||||
SecuritySettingsSource.addSecureSettings(builder, secureSettings ->
|
||||
|
|
|
@ -79,7 +79,7 @@ public class GraphTests extends XPackSingleNodeTestCase {
|
|||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
assertAcked(client().admin().indices().prepareCreate("test")
|
||||
.setSettings(SETTING_NUMBER_OF_SHARDS, 2, SETTING_NUMBER_OF_REPLICAS, 0)
|
||||
.setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 2).put(SETTING_NUMBER_OF_REPLICAS, 0))
|
||||
.addMapping("type",
|
||||
"decade", "type=keyword",
|
||||
"people", "type=keyword",
|
||||
|
|
|
@ -92,16 +92,12 @@ public class MonitoringSettingsIntegTests extends MonitoringIntegTestCase {
|
|||
MonitoringSettings.JOB_STATS_TIMEOUT};
|
||||
for (Setting<?> setting : monitoringSettings) {
|
||||
if (setting.isDynamic()) {
|
||||
Object updated = null;
|
||||
if (setting.get(Settings.EMPTY) instanceof TimeValue) {
|
||||
updated = newRandomTimeValue();
|
||||
transientSettings.put(setting.getKey(), updated);
|
||||
transientSettings.put(setting.getKey(), newRandomTimeValue().toString());
|
||||
} else if (setting.get(Settings.EMPTY) instanceof Boolean) {
|
||||
updated = randomBoolean();
|
||||
transientSettings.put(setting.getKey(), updated);
|
||||
transientSettings.put(setting.getKey(), randomBoolean());
|
||||
} else if (setting.get(Settings.EMPTY) instanceof List) {
|
||||
updated = randomStringArray();
|
||||
transientSettings.putArray(setting.getKey(), (String[]) updated);
|
||||
transientSettings.putArray(setting.getKey(), randomStringArray());
|
||||
} else {
|
||||
fail("unknown dynamic setting [" + setting + "]");
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ public class JiraAccountTests extends ESTestCase {
|
|||
for (Map.Entry<String, Object> setting : defaults.entrySet()) {
|
||||
String key = "xpack.notification.jira.account." + name + "." + JiraAccount.ISSUE_DEFAULTS_SETTING + "." + setting.getKey();
|
||||
if (setting.getValue() instanceof String) {
|
||||
builder.put(key, setting.getValue());
|
||||
builder.put(key, setting.getValue().toString());
|
||||
} else if (setting.getValue() instanceof Map) {
|
||||
builder.putProperties((Map) setting.getValue(), s -> key + "." + s);
|
||||
}
|
||||
|
|
|
@ -226,17 +226,19 @@ public class SecurityTribeIT extends NativeRealmIntegTestCase {
|
|||
}
|
||||
};
|
||||
final Settings settingsTemplate = cluster2SettingsSource.nodeSettings(0);
|
||||
|
||||
Map<String, String> asMap = new HashMap<>(settingsTemplate.getAsMap());
|
||||
asMap.remove(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey());
|
||||
Settings.Builder tribe1Defaults = Settings.builder();
|
||||
Settings.Builder tribe2Defaults = Settings.builder();
|
||||
for (Map.Entry<String, String> entry : asMap.entrySet()) {
|
||||
if (entry.getKey().startsWith("path.")) {
|
||||
continue;
|
||||
} else if (entry.getKey().equals("transport.tcp.port")) {
|
||||
continue;
|
||||
Settings tribeSettings = settingsTemplate.filter(k -> {
|
||||
if (k.equals(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey())) {
|
||||
return false;
|
||||
} if (k.startsWith("path.")) {
|
||||
return false;
|
||||
} else if (k.equals("transport.tcp.port")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
for (Map.Entry<String, String> entry : tribeSettings.getAsMap().entrySet()) {
|
||||
tribe1Defaults.put("tribe.t1." + entry.getKey(), entry.getValue());
|
||||
tribe2Defaults.put("tribe.t2." + entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
@ -255,7 +257,7 @@ public class SecurityTribeIT extends NativeRealmIntegTestCase {
|
|||
|
||||
Settings merged = Settings.builder()
|
||||
.put(internalCluster().getDefaultSettings())
|
||||
.put(asMap)
|
||||
.put(tribeSettings, false)
|
||||
.put("tribe.t1.cluster.name", internalCluster().getClusterName())
|
||||
.put("tribe.t2.cluster.name", cluster2.getClusterName())
|
||||
.put("tribe.blocks.write", false)
|
||||
|
|
|
@ -102,7 +102,6 @@ public class ServerTransportFilterIntegrationTests extends SecurityIntegTestCase
|
|||
|
||||
// test that starting up a node works
|
||||
Settings.Builder nodeSettings = Settings.builder()
|
||||
.put()
|
||||
.put("node.name", "my-test-node")
|
||||
.put("network.host", "localhost")
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
|
|
|
@ -95,7 +95,7 @@ public class DNSOnlyHostnameVerificationTests extends SecurityIntegTestCase {
|
|||
public Settings nodeSettings(int nodeOrdinal) {
|
||||
Settings defaultSettings = super.nodeSettings(nodeOrdinal);
|
||||
Settings.Builder builder = Settings.builder()
|
||||
.put(defaultSettings.filter((s) -> s.startsWith("xpack.ssl.") == false).getAsMap())
|
||||
.put(defaultSettings.filter((s) -> s.startsWith("xpack.ssl.") == false), false)
|
||||
.put("transport.host", hostName);
|
||||
Path keystorePath = nodeConfigPath(nodeOrdinal).resolve("keystore.jks");
|
||||
try (OutputStream os = Files.newOutputStream(keystorePath)) {
|
||||
|
|
|
@ -31,7 +31,7 @@ public class IPHostnameVerificationTests extends SecurityIntegTestCase {
|
|||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
Settings settings = super.nodeSettings(nodeOrdinal);
|
||||
Settings.Builder builder = Settings.builder()
|
||||
.put(settings.filter((s) -> s.startsWith("xpack.ssl.") == false).getAsMap());
|
||||
.put(settings.filter((s) -> s.startsWith("xpack.ssl.") == false), false);
|
||||
settings = builder.build();
|
||||
|
||||
// The default Unicast test behavior is to use 'localhost' with the port number. For this test we need to use IP
|
||||
|
|
|
@ -38,7 +38,7 @@ public class CustomRealmIT extends ESIntegTestCase {
|
|||
protected Settings externalClusterClientSettings() {
|
||||
return Settings.builder()
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.USER_HEADER, CustomRealm.KNOWN_USER)
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.PW_HEADER, CustomRealm.KNOWN_PW)
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.PW_HEADER, CustomRealm.KNOWN_PW.toString())
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "security4")
|
||||
.build();
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class CustomRealmIT extends ESIntegTestCase {
|
|||
.put("cluster.name", clusterName)
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString())
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.USER_HEADER, CustomRealm.KNOWN_USER)
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.PW_HEADER, CustomRealm.KNOWN_PW)
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.PW_HEADER, CustomRealm.KNOWN_PW.toString())
|
||||
.build();
|
||||
try (TransportClient client = new PreBuiltXPackTransportClient(settings)) {
|
||||
client.addTransportAddress(publishAddress);
|
||||
|
@ -98,7 +98,7 @@ public class CustomRealmIT extends ESIntegTestCase {
|
|||
.put("cluster.name", clusterName)
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString())
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.USER_HEADER, CustomRealm.KNOWN_USER + randomAlphaOfLength(1))
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.PW_HEADER, CustomRealm.KNOWN_PW)
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.PW_HEADER, CustomRealm.KNOWN_PW.toString())
|
||||
.build();
|
||||
try (TransportClient client = new PreBuiltXPackTransportClient(settings)) {
|
||||
client.addTransportAddress(publishAddress);
|
||||
|
|
|
@ -40,7 +40,7 @@ public class CustomRolesProviderIT extends ESIntegTestCase {
|
|||
protected Settings externalClusterClientSettings() {
|
||||
return Settings.builder()
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.USER_HEADER, CustomRealm.KNOWN_USER)
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.PW_HEADER, CustomRealm.KNOWN_PW)
|
||||
.put(ThreadContext.PREFIX + "." + CustomRealm.PW_HEADER, CustomRealm.KNOWN_PW.toString())
|
||||
.put(NetworkModule.TRANSPORT_TYPE_KEY, "security4")
|
||||
.build();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue