-
Notifications
You must be signed in to change notification settings - Fork 0
Incorporated SRV format in connection string #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 8 commits
e05342a
48971e9
26d95a6
56334ec
ba1cba7
62ae69e
1af6b88
c9d58af
87ef57b
c168339
51fcc54
83ea240
2d18182
5e4f7b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,7 @@ public class MongoDBConfig extends PluginConfig { | |
| @Name(MongoDBConstants.PORT) | ||
| @Description("Port that MongoDB is listening to.") | ||
| @Macro | ||
| private int port; | ||
| private Integer port; | ||
|
|
||
| @Name(MongoDBConstants.DATABASE) | ||
| @Description("MongoDB database name.") | ||
|
|
@@ -76,21 +76,27 @@ public class MongoDBConfig extends PluginConfig { | |
| @Nullable | ||
| private String password; | ||
|
|
||
| @Name(MongoDBConstants.USE_SRV) | ||
| @Description("Enable SRV format for connection string") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use Connect Using SRV String as field and label name in widget and also add the same in md doc file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add same description that you have added in md file |
||
| @Nullable | ||
| private boolean useSRV; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change field name also
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall I make it as connectUsingSRV ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this name should be same as given in widget.json |
||
|
|
||
| @Name(MongoDBConstants.CONNECTION_ARGUMENTS) | ||
| @Description("A list of arbitrary string key/value pairs as connection arguments.") | ||
| @Macro | ||
| @Nullable | ||
| private String connectionArguments; | ||
|
|
||
| public MongoDBConfig(String referenceName, String host, int port, String database, String collection, String user, | ||
| String password, String connectionArguments) { | ||
| String password, boolean useSRV, String connectionArguments) { | ||
| this.referenceName = referenceName; | ||
| this.host = host; | ||
| this.port = port; | ||
| this.database = database; | ||
| this.collection = collection; | ||
| this.user = user; | ||
| this.password = password; | ||
| this.useSRV = useSRV; | ||
| this.connectionArguments = connectionArguments; | ||
| } | ||
|
|
||
|
|
@@ -102,7 +108,8 @@ public String getHost() { | |
| return host; | ||
| } | ||
|
|
||
| public int getPort() { | ||
| @Nullable | ||
| public Integer getPort() { | ||
| return port; | ||
| } | ||
|
|
||
|
|
@@ -124,6 +131,10 @@ public String getPassword() { | |
| return password; | ||
| } | ||
|
|
||
| public boolean isUseSRV() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding 'is' as a prefix doesnt make much sense, keep it just connectUsingSRVString |
||
| return useSRV; | ||
| } | ||
|
|
||
| @Nullable | ||
| public String getConnectionArguments() { | ||
| return connectionArguments; | ||
|
|
@@ -146,7 +157,7 @@ public void validate() { | |
| if (!containsMacro(MongoDBConstants.HOST) && Strings.isNullOrEmpty(host)) { | ||
| throw new InvalidConfigPropertyException("Host must be specified", MongoDBConstants.HOST); | ||
| } | ||
| if (!containsMacro(MongoDBConstants.PORT)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep this condition as when useSRV is not macro and not true, this validation is required
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
| if ((!containsMacro(MongoDBConstants.USE_SRV) && !useSRV) && !containsMacro(MongoDBConstants.PORT)) { | ||
| if (port < 1) { | ||
| throw new InvalidConfigPropertyException("Port number must be greater than 0", MongoDBConstants.PORT); | ||
| } | ||
|
|
@@ -161,25 +172,43 @@ public void validate() { | |
|
|
||
| /** | ||
| * Constructs a connection string such as: "mongodb://admin:password@localhost:27017/admin.analytics?key=value;" | ||
| * using host, port, username, password, database, collection and optional connection properties. In the case when | ||
| * username or password is not provided the connection string will not contain credentials: | ||
| * using host, port, username, password, database, collection and optional connection properties. | ||
| * If SRV is enabled, the connection string will use the "mongodb+srv://" protocol instead of "mongodb://". | ||
| * In the case when username or password is not provided, the connection string will not contain credentials: | ||
| * "mongodb://localhost:27017/admin.analytics?key=value;" | ||
| * When SRV is not used, the port will be included in the connection string. | ||
| * | ||
| * @return connection string. | ||
| */ | ||
| public String getConnectionString() { | ||
| StringBuilder connectionStringBuilder = new StringBuilder("mongodb://"); | ||
|
|
||
| StringBuilder connectionStringBuilder = new StringBuilder(); | ||
|
|
||
| if (isUseSRV()) { | ||
| connectionStringBuilder.append("mongodb+srv://"); | ||
| } else { | ||
| connectionStringBuilder.append("mongodb://"); | ||
| } | ||
|
|
||
| if (!Strings.isNullOrEmpty(user) || !Strings.isNullOrEmpty(password)) { | ||
| connectionStringBuilder.append(user).append(":").append(password).append("@"); | ||
| } | ||
| connectionStringBuilder.append(host).append(":").append(port).append("/") | ||
| .append(database).append(".").append(collection); | ||
|
|
||
| connectionStringBuilder.append(host); | ||
|
|
||
| if (!isUseSRV()) { | ||
| connectionStringBuilder.append(":").append(port); | ||
| } | ||
|
|
||
| connectionStringBuilder.append("/").append(database).append(".").append(collection); | ||
|
|
||
| if (!Strings.isNullOrEmpty(connectionArguments)) { | ||
| connectionStringBuilder.append("?").append(connectionArguments); | ||
| } | ||
|
|
||
| return connectionStringBuilder.toString(); | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove blank lines |
||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,11 @@ private MongoDBConstants() { | |
| */ | ||
| public static final String PASSWORD = "password"; | ||
|
|
||
| /** | ||
| * | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a small description |
||
| */ | ||
| public static final String USE_SRV = "connectUsingSRVString"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename this also to CONNECT_USING_SRV_STRING |
||
|
|
||
| /** | ||
| * Configuration property name used to specify auxiliary MongoDB connection string to authenticate against when | ||
| * constructing splits. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,8 +171,8 @@ public static class MongoDBSinkConfig extends MongoDBConfig { | |
| private String idField; | ||
|
|
||
| public MongoDBSinkConfig(String referenceName, String host, int port, String database, String collection, | ||
| String user, String password, String connectionArguments, String idField) { | ||
| super(referenceName, host, port, database, collection, user, password, connectionArguments); | ||
| String user, String password, Boolean useSRV, String connectionArguments, String idField) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make boolean primitive at all places |
||
| super(referenceName, host, port, database, collection, user, password, useSRV, connectionArguments); | ||
| this.idField = idField; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add same to sink also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!