remove endpointValidation
This commit is contained in:
Родитель
43b4142aa1
Коммит
b894f1157b
|
@ -188,40 +188,8 @@ public class CosmosDBConfig extends AbstractConfig {
|
|||
return this.providerName;
|
||||
}
|
||||
|
||||
// VisibleForTesting
|
||||
public static void validateEndpoint(String endpoint) throws URISyntaxException, UnknownHostException {
|
||||
URI uri = new URI(endpoint);
|
||||
if (!VALID_ENDPOINT_SCHEME.equalsIgnoreCase(uri.getScheme())) {
|
||||
throw new ConfigException("Endpoint must have scheme: " + VALID_ENDPOINT_SCHEME);
|
||||
}
|
||||
if (uri.getPort() != -1 && VALID_ENDPOINT_PORT != uri.getPort()) {
|
||||
throw new ConfigException("Endpoint must have port: " + VALID_ENDPOINT_PORT);
|
||||
}
|
||||
if (uri.getPath() != null && !uri.getPath().isEmpty() && !uri.getPath().equalsIgnoreCase("/")) {
|
||||
throw new ConfigException("Endpoint must not contain path: " + uri.getPath());
|
||||
}
|
||||
if (uri.getQuery() != null) {
|
||||
throw new ConfigException("Endpoint must not contain query component: " + uri.getQuery());
|
||||
}
|
||||
if (uri.getFragment() != null) {
|
||||
throw new ConfigException("Endpoint must not contain fragment: " + uri.getFragment());
|
||||
}
|
||||
String host = uri.getHost();
|
||||
String cosmosInstance = host.split("\\.")[0];
|
||||
if (!VALID_ENDPOINT_COSMOS_INSTANCE_PATTERN.matcher(cosmosInstance).matches()) {
|
||||
throw new ConfigException("Invalid cosmos instance: " + cosmosInstance);
|
||||
}
|
||||
}
|
||||
|
||||
public static void validateConnection(Map<String, String> connectorConfigs, Map<String, ConfigValue> configValues) {
|
||||
String endpoint = connectorConfigs.get(CosmosDBSinkConfig.COSMOS_CONN_ENDPOINT_CONF);
|
||||
try {
|
||||
validateEndpoint(endpoint);
|
||||
} catch (Exception e) {
|
||||
configValues.get(CosmosDBSinkConfig.COSMOS_CONN_ENDPOINT_CONF)
|
||||
.addErrorMessage("Invalid endpoint: " + e.getMessage());
|
||||
}
|
||||
|
||||
String key = connectorConfigs.get(CosmosDBSinkConfig.COSMOS_CONN_KEY_CONF);
|
||||
try {
|
||||
createClient(endpoint, key);
|
||||
|
|
|
@ -116,40 +116,4 @@ public class CosmosDBSinkConnectorTest {
|
|||
.collect(Collectors.toMap(ConfigValue::name, ConfigValue::errorMessages));
|
||||
assertThat(errorMessages.get(CosmosDBSinkConfig.COSMOS_CONTAINER_TOPIC_MAP_CONF), not(empty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateEndpoint() throws Exception {
|
||||
assertThrows(ConfigException.class,
|
||||
() -> {
|
||||
CosmosDBConfig.validateEndpoint("http://not.valid.schema");
|
||||
});
|
||||
assertThrows(ConfigException.class,
|
||||
() -> {CosmosDBConfig.validateEndpoint("https://not.valid.port:1024");
|
||||
});
|
||||
assertThrows(ConfigException.class,
|
||||
() -> {CosmosDBConfig.validateEndpoint("https://not.valid.path:443/not/valid/path");
|
||||
});
|
||||
assertThrows(ConfigException.class,
|
||||
() -> {CosmosDBConfig.validateEndpoint("https://not.valid.query:443/?query=not-valid");
|
||||
});
|
||||
assertThrows(ConfigException.class,
|
||||
() -> {CosmosDBConfig.validateEndpoint("https://not.valid.query:443/#fragement-not-valid");
|
||||
});
|
||||
assertThrows(ConfigException.class,
|
||||
() -> {CosmosDBConfig.validateEndpoint("https://INSTANCE.documents.azure.com:443/");
|
||||
});
|
||||
assertThrows(ConfigException.class,
|
||||
() -> {CosmosDBConfig.validateEndpoint("https://1.documents.azure.com:443/");
|
||||
});
|
||||
assertThrows(ConfigException.class,
|
||||
() -> {CosmosDBConfig.validateEndpoint("https://longlonglonglonglonglonglonglonglonglonglonglonglonglonginstance.documents.azure.com:443/");
|
||||
});
|
||||
assertThrows(ConfigException.class,
|
||||
() -> {CosmosDBConfig.validateEndpoint("https://[::1]:443/");
|
||||
});
|
||||
|
||||
CosmosDBConfig.validateEndpoint("https://localhost:443/");
|
||||
CosmosDBConfig.validateEndpoint("https://cosmos-instance.documents.azure.com:443/");
|
||||
CosmosDBConfig.validateEndpoint("https://cosmos-instance.documents.azure.com:443");
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче