use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class ImportYmlConfigTask method writeSettings.
/**
* Write settings to the config file on the file system. It uses the {@link XContentBuilder}
* to build the YAML content and write it to the output stream.
*
* @param configYml path to a yml file where config will be written to.
* @param settings the settings to write
* @throws IOException exception during writing to the output stream.
*/
private void writeSettings(final Path configYml, final Settings settings) throws IOException {
try (OutputStream os = Files.newOutputStream(configYml, StandardOpenOption.APPEND);
XContentBuilder builder = new XContentBuilder(YamlXContent.yamlXContent, os)) {
builder.startObject();
final Map<String, String> params = new HashMap<>();
params.put("flat_settings", "true");
settings.toXContent(builder, new ToXContent.MapParams(params));
builder.endObject();
builder.flush();
} catch (Exception e) {
throw new SettingsException("Failed to write settings to " + configYml.toString(), e);
}
}
use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class GoogleCloudStorageClientSettingsTests method testProxyWrongHost.
public void testProxyWrongHost() {
final Settings settings = Settings.builder().put("gcs.client.default.proxy.type", randomFrom("socks", "http")).put("gcs.client.default.proxy.host", "thisisnotavalidhostorwehavebeensuperunlucky").put("gcs.client.default.proxy.port", 8080).build();
final SettingsException e = expectThrows(SettingsException.class, () -> GoogleCloudStorageClientSettings.load(settings));
assertEquals("Google Cloud Storage proxy host is unknown.", e.getMessage());
}
use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class GoogleCloudStorageClientSettingsTests method testProxyHostNotSet.
public void testProxyHostNotSet() {
final Settings settings = Settings.builder().put("gcs.client.default.proxy.port", 8080).put("gcs.client.default.proxy.type", randomFrom("socks", "http")).build();
final SettingsException e = expectThrows(SettingsException.class, () -> GoogleCloudStorageClientSettings.load(settings));
assertEquals("Google Cloud Storage proxy type has been set but proxy host or port is not defined.", e.getMessage());
}
use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class AzureStorageSettings method validateAndCreateProxySettings.
static ProxySettings validateAndCreateProxySettings(final Settings settings, final String clientName) {
final ProxySettings.ProxyType proxyType = getConfigValue(settings, clientName, PROXY_TYPE_SETTING);
final String proxyHost = getConfigValue(settings, clientName, PROXY_HOST_SETTING);
final int proxyPort = getConfigValue(settings, clientName, PROXY_PORT_SETTING);
final SecureString proxyUserName = getConfigValue(settings, clientName, PROXY_USERNAME_SETTING);
final SecureString proxyPassword = getConfigValue(settings, clientName, PROXY_PASSWORD_SETTING);
// Validate proxy settings
if (proxyType == ProxySettings.ProxyType.DIRECT && (proxyPort != 0 || Strings.hasText(proxyHost) || Strings.hasText(proxyUserName) || Strings.hasText(proxyPassword))) {
throw new SettingsException("Azure proxy port or host or username or password have been set but proxy type is not defined.");
}
if (proxyType != ProxySettings.ProxyType.DIRECT && (proxyPort == 0 || Strings.isEmpty(proxyHost))) {
throw new SettingsException("Azure proxy type has been set but proxy host or port is not defined.");
}
if (proxyType == ProxySettings.ProxyType.DIRECT) {
return ProxySettings.NO_PROXY_SETTINGS;
}
try {
final InetAddress proxyHostAddress = InetAddress.getByName(proxyHost);
return new ProxySettings(proxyType, proxyHostAddress, proxyPort, proxyUserName.toString(), proxyPassword.toString());
} catch (final UnknownHostException e) {
throw new SettingsException("Azure proxy host is unknown.", e);
}
}
use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class AzureStorageServiceTests method testProxyNoType.
public void testProxyNoType() {
final Settings settings = Settings.builder().setSecureSettings(buildSecureSettings()).put("azure.client.azure1.proxy.host", "127.0.0.1").put("azure.client.azure1.proxy.port", 8080).build();
final SettingsException e = expectThrows(SettingsException.class, () -> storageServiceWithSettingsValidation(settings));
assertEquals("Azure proxy port or host or username or password have been set but proxy type is not defined.", e.getMessage());
}
Aggregations