Fix/add mongo srv support (#3341)

Provide helpful error msg when srv url is provided to mongo plugin

Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
This commit is contained in:
Sumit Kumar 2021-03-03 18:31:04 +05:30 committed by GitHub
parent 75b0986b92
commit 639913703a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -338,6 +338,17 @@ public class MongoPlugin extends BasePlugin {
}
if(!CollectionUtils.isEmpty(endpoints)) {
boolean usingSrvUrl = endpoints
.stream()
.anyMatch(endPoint -> endPoint.getHost().contains("mongodb+srv"));
if (usingSrvUrl) {
invalids.add("MongoDb SRV URLs are not yet supported. Please extract the individual fields from " +
"the SRV URL into the datasource configuration form.");
}
}
DBAuth authentication = (DBAuth) datasourceConfiguration.getAuthentication();
if (authentication != null) {
DBAuth.Type authType = authentication.getAuthType();

View File

@ -26,6 +26,7 @@ import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import static org.junit.Assert.assertArrayEquals;
@ -404,4 +405,19 @@ public class MongoPluginTest {
})
.verifyComplete();
}
@Test
public void testErrorMessageOnSrvUrl() {
DatasourceConfiguration dsConfig = createDatasourceConfiguration();
dsConfig.getEndpoints().get(0).setHost("mongodb+srv:://url.net");
Mono<Set<String>> invalidsMono = Mono.just(pluginExecutor.validateDatasource(dsConfig));
StepVerifier.create(invalidsMono)
.assertNext(invalids -> {
assertTrue(invalids
.stream()
.anyMatch(error -> error.contains("MongoDb SRV URLs are not yet supported")));
})
.verifyComplete();
}
}