parent
66c7a0b252
commit
e74d99b794
|
|
@ -590,6 +590,22 @@ public class MongoPlugin extends BasePlugin {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean hostStringHasConnectionURIHead(String host) {
|
||||
if (!StringUtils.isEmpty(host) && (host.contains("mongodb://") || host.contains("mongodb+srv"))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isHostStringConnectionURI(Endpoint endpoint) {
|
||||
if (endpoint != null && hostStringHasConnectionURIHead(endpoint.getHost())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> validateDatasource(DatasourceConfiguration datasourceConfiguration) {
|
||||
Set<String> invalids = new HashSet<>();
|
||||
|
|
@ -641,7 +657,7 @@ public class MongoPlugin extends BasePlugin {
|
|||
if (!CollectionUtils.isEmpty(endpoints)) {
|
||||
boolean usingUri = endpoints
|
||||
.stream()
|
||||
.anyMatch(endPoint -> endPoint.getHost().matches(MONGO_URI_REGEX));
|
||||
.anyMatch(endPoint -> isHostStringConnectionURI(endPoint));
|
||||
|
||||
if (usingUri) {
|
||||
invalids.add("It seems that you are trying to use a mongo connection string URI. Please " +
|
||||
|
|
|
|||
|
|
@ -496,7 +496,12 @@ public class MongoPluginTest {
|
|||
@Test
|
||||
public void testErrorMessageOnNonSrvUri() {
|
||||
DatasourceConfiguration dsConfig = createDatasourceConfiguration();
|
||||
dsConfig.getEndpoints().get(0).setHost("mongodb://user:pass@url.net:1234,url.net:1234/dbName");
|
||||
List<Endpoint> endpoints = new ArrayList<>();
|
||||
endpoints.add(new Endpoint("url", 123L));
|
||||
endpoints.add(null);
|
||||
endpoints.add(new Endpoint(null, 123L));
|
||||
endpoints.add(new Endpoint("mongodb://user:pass@url.net:1234,url.net:1234/dbName", 123L));
|
||||
dsConfig.setEndpoints(endpoints);
|
||||
dsConfig.setProperties(List.of(new Property("Import from URI", "No")));
|
||||
Mono<Set<String>> invalidsMono = Mono.just(pluginExecutor.validateDatasource(dsConfig));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user