jesmith17 commented on code in PR #3322:
URL: https://github.com/apache/logging-log4j2/pull/3322#discussion_r1899155857
##########
log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbProvider.java:
##########
@@ -57,12 +58,40 @@ public static class Builder<B extends Builder<B>> extends
AbstractFilterable.Bui
@PluginAttribute("collectionName")
private String collectionName = null;
- @PluginAttribute("datbaseName")
+ @PluginAttribute("databaseName")
private String databaseName = null;
@Override
public MongoDbProvider build() {
- return new MongoDbProvider(connectionStringSource, capped,
collectionSize, databaseName, collectionName);
+ LOGGER.debug("Creating ConnectionString {}...",
connectionStringSource);
+ ConnectionString connectionString;
+ try {
+ connectionString = new
ConnectionString(connectionStringSource);
+ } catch (final IllegalArgumentException e) {
+ LOGGER.error("Invalid MongoDB connection string `{}`.",
connectionStringSource, e);
+ return null;
+ }
+
+ String effectiveDatabaseName = databaseName != null ? databaseName
: connectionString.getDatabase();
+ String effectiveCollectionName = collectionName != null ?
collectionName: connectionString.getCollection();
+ // Validate the provided databaseName property
+ try {
+
MongoNamespace.checkDatabaseNameValidity(effectiveDatabaseName);
+ databaseName = effectiveDatabaseName;
+ } catch (final IllegalArgumentException e) {
+ LOGGER.error("Invalid MongoDB database name `{}`.",
effectiveDatabaseName, e);
+ return null;
+ }
+ // Validate the provided collectionName property
+ try {
+
MongoNamespace.checkCollectionNameValidity(effectiveCollectionName);
+ collectionName = effectiveCollectionName;
Review Comment:
Good point. Done
##########
log4j-mongodb/src/main/java/org/apache/logging/log4j/mongodb/MongoDbProvider.java:
##########
@@ -57,12 +58,40 @@ public static class Builder<B extends Builder<B>> extends
AbstractFilterable.Bui
@PluginAttribute("collectionName")
private String collectionName = null;
- @PluginAttribute("datbaseName")
+ @PluginAttribute("databaseName")
private String databaseName = null;
@Override
public MongoDbProvider build() {
- return new MongoDbProvider(connectionStringSource, capped,
collectionSize, databaseName, collectionName);
+ LOGGER.debug("Creating ConnectionString {}...",
connectionStringSource);
+ ConnectionString connectionString;
+ try {
+ connectionString = new
ConnectionString(connectionStringSource);
+ } catch (final IllegalArgumentException e) {
+ LOGGER.error("Invalid MongoDB connection string `{}`.",
connectionStringSource, e);
+ return null;
+ }
+
+ String effectiveDatabaseName = databaseName != null ? databaseName
: connectionString.getDatabase();
+ String effectiveCollectionName = collectionName != null ?
collectionName: connectionString.getCollection();
+ // Validate the provided databaseName property
+ try {
+
MongoNamespace.checkDatabaseNameValidity(effectiveDatabaseName);
+ databaseName = effectiveDatabaseName;
Review Comment:
Done
##########
log4j-mongodb/pom.xml:
##########
@@ -141,7 +142,11 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]