This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/master by this push:
new 9798468daf Allow usage of Encrypted password in mongo connection,
fixes #2241
new 739f3f59a9 Merge pull request #2555 from hansva/master
9798468daf is described below
commit 9798468daf33448f0444404e0d22c58720b308b3
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Sun Mar 12 11:14:21 2023 +0100
Allow usage of Encrypted password in mongo connection, fixes #2241
---
.../integration-tests/integration-tests-mongo.yaml | 11 +-
integration-tests/mongo/dev-env-config.json | 39 +++---
.../mongo/metadata/mongodb-connection/mongo.json | 10 +-
.../mongo-delete/delete-3-customers-json-test.hpl | 6 +-
.../tests/mongo-delete/delete-5-customers-test.hpl | 152 ++++++++++-----------
.../hop/mongo/metadata/MongoDbConnection.java | 11 +-
6 files changed, 117 insertions(+), 112 deletions(-)
diff --git a/docker/integration-tests/integration-tests-mongo.yaml
b/docker/integration-tests/integration-tests-mongo.yaml
index d2f6cdf504..1c198d0bfb 100644
--- a/docker/integration-tests/integration-tests-mongo.yaml
+++ b/docker/integration-tests/integration-tests-mongo.yaml
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-version: '2.4'
+version: '3.5'
services:
integration_test_mongo:
extends:
@@ -32,8 +32,13 @@ services:
ports:
- "27017"
healthcheck:
- test: echo 'db.runCommand("ping").ok' | mongo 127.0.0.1:27017/test
--quiet
+ test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test
--quiet
interval: 30s
timeout: 10s
retries: 6
- start_period: 240s
\ No newline at end of file
+ start_period: 240s
+ environment:
+ MONGO_INITDB_DATABASE: my_db
+ MONGO_INITDB_ROOT_USERNAME: root
+ MONGO_INITDB_ROOT_PASSWORD: example
+ command: mongod --auth
\ No newline at end of file
diff --git a/integration-tests/mongo/dev-env-config.json
b/integration-tests/mongo/dev-env-config.json
index d4d5af3080..4583b384c4 100644
--- a/integration-tests/mongo/dev-env-config.json
+++ b/integration-tests/mongo/dev-env-config.json
@@ -1,24 +1,19 @@
{
- "variables": [
- {
- "name": "MONGO_HOSTNAME",
- "value": "mongo",
- "description": "The MongoDB hostname"
- },
- {
- "name": "MONGO_PORT",
- "value": "27017",
- "description": "The data port "
- },
- {
- "name": "MONGO_USERNAME",
- "value": "",
- "description": "Username: none"
- },
- {
- "name": "MONGO_PASSWORD",
- "value": "",
- "description": "Password: none"
- }
- ]
+ "variables" : [ {
+ "name" : "MONGO_HOSTNAME",
+ "value" : "mongo",
+ "description" : "The MongoDB hostname"
+ }, {
+ "name" : "MONGO_PORT",
+ "value" : "27017",
+ "description" : "The data port "
+ }, {
+ "name" : "MONGO_USERNAME",
+ "value" : "root",
+ "description" : "Username: none"
+ }, {
+ "name" : "MONGO_PASSWORD",
+ "value" : "Encrypted 2be98afc86aa7f2e4cb1cb671d382a3df",
+ "description" : "Password: none"
+ } ]
}
\ No newline at end of file
diff --git a/integration-tests/mongo/metadata/mongodb-connection/mongo.json
b/integration-tests/mongo/metadata/mongodb-connection/mongo.json
index 9c0e1abf98..f900a4a65b 100644
--- a/integration-tests/mongo/metadata/mongodb-connection/mongo.json
+++ b/integration-tests/mongo/metadata/mongodb-connection/mongo.json
@@ -1,20 +1,20 @@
{
- "authenticationDatabaseName": "",
+ "authenticationDatabaseName": "admin",
"usingKerberos": false,
"journaled": true,
"dbName": "local",
"authenticationUser": "${MONGO_USERNAME}",
- "writeConcern": "",
"connectTimeoutMs": "",
- "usingSslSocketFactory": false,
+ "writeConcern": "",
"authenticationPassword": "${MONGO_PASSWORD}",
"usingAllReplicaSetMembers": false,
+ "usingSslSocketFactory": false,
"replicationTimeoutMs": "",
"hostname": "${MONGO_HOSTNAME}",
"port": "${MONGO_PORT}",
- "socketTimeoutMs": "",
"name": "mongo",
"readPreference": "PRIMARY",
+ "socketTimeoutMs": "",
"readPrefTagSets": "",
- "authenticationMechanism": "PLAIN"
+ "authenticationMechanism": "SCRAM_SHA_1"
}
\ No newline at end of file
diff --git
a/integration-tests/mongo/tests/mongo-delete/delete-3-customers-json-test.hpl
b/integration-tests/mongo/tests/mongo-delete/delete-3-customers-json-test.hpl
index fd54ab8072..f934a5f518 100644
---
a/integration-tests/mongo/tests/mongo-delete/delete-3-customers-json-test.hpl
+++
b/integration-tests/mongo/tests/mongo-delete/delete-3-customers-json-test.hpl
@@ -34,8 +34,6 @@ limitations under the License.
<created_date>2022/07/11 10:41:09.996</created_date>
<modified_user>-</modified_user>
<modified_date>2022/07/11 10:41:09.996</modified_date>
- <key_for_session_key>H4sIAAAAAAAAAAMAAAAAAAAAAAA=</key_for_session_key>
- <is_key_private>N</is_key_private>
</info>
<notepads>
</notepads>
@@ -88,7 +86,7 @@ limitations under the License.
<fields>
<field>
<name>firstname</name>
- <path>$..firstname</path>
+ <path>$.firstname</path>
<type>String</type>
<format/>
<currency/>
@@ -101,7 +99,7 @@ limitations under the License.
</field>
<field>
<name>lastname</name>
- <path>$..name</path>
+ <path>$.name</path>
<type>String</type>
<format/>
<currency/>
diff --git
a/integration-tests/mongo/tests/mongo-delete/delete-5-customers-test.hpl
b/integration-tests/mongo/tests/mongo-delete/delete-5-customers-test.hpl
index fccb20b64c..3f9634251e 100644
--- a/integration-tests/mongo/tests/mongo-delete/delete-5-customers-test.hpl
+++ b/integration-tests/mongo/tests/mongo-delete/delete-5-customers-test.hpl
@@ -34,8 +34,6 @@ limitations under the License.
<created_date>2022/07/11 10:41:09.996</created_date>
<modified_user>-</modified_user>
<modified_date>2022/07/11 10:41:09.996</modified_date>
- <key_for_session_key>H4sIAAAAAAAAAAMAAAAAAAAAAAA=</key_for_session_key>
- <is_key_private>N</is_key_private>
</info>
<notepads>
</notepads>
@@ -57,8 +55,8 @@ limitations under the License.
</hop>
</order>
<transform>
- <name>read customers</name>
- <type>MongoDbInput</type>
+ <name>get first name, last name</name>
+ <type>JsonInput</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
@@ -67,23 +65,73 @@ limitations under the License.
<method>none</method>
<schema_name/>
</partitioning>
- <connection>mongo</connection>
- <fields_name/>
- <collection>m_inserts_1</collection>
- <json_field_name>json</json_field_name>
- <json_query>{}</json_query>
- <output_json>Y</output_json>
- <query_is_pipeline>N</query_is_pipeline>
- <execute_for_each_row>N</execute_for_each_row>
+ <include>N</include>
+ <include_field/>
+ <rownum>N</rownum>
+ <addresultfile>N</addresultfile>
+ <readurl>N</readurl>
+ <removeSourceField>N</removeSourceField>
+ <IsIgnoreEmptyFile>N</IsIgnoreEmptyFile>
+ <doNotFailIfNoFile>Y</doNotFailIfNoFile>
+ <ignoreMissingPath>Y</ignoreMissingPath>
+ <defaultPathLeafToNull>Y</defaultPathLeafToNull>
+ <rownum_field/>
+ <file>
+ <name/>
+ <filemask/>
+ <exclude_filemask/>
+ <file_required>N</file_required>
+ <include_subfolders>N</include_subfolders>
+ </file>
+ <fields>
+ <field>
+ <name>firstname</name>
+ <path>$.firstname</path>
+ <type>String</type>
+ <format/>
+ <currency/>
+ <decimal/>
+ <group/>
+ <length>-1</length>
+ <precision>-1</precision>
+ <trim_type>none</trim_type>
+ <repeat>N</repeat>
+ </field>
+ <field>
+ <name>lastname</name>
+ <path>$.name</path>
+ <type>String</type>
+ <format/>
+ <currency/>
+ <decimal/>
+ <group/>
+ <length>-1</length>
+ <precision>-1</precision>
+ <trim_type>none</trim_type>
+ <repeat>N</repeat>
+ </field>
+ </fields>
+ <limit>0</limit>
+ <IsInFields>Y</IsInFields>
+ <IsAFile>N</IsAFile>
+ <valueField>json</valueField>
+ <shortFileFieldName/>
+ <pathFieldName/>
+ <hiddenFieldName/>
+ <lastModificationTimeFieldName/>
+ <uriNameFieldName/>
+ <rootUriNameFieldName/>
+ <extensionFieldName/>
+ <sizeFieldName/>
<attributes/>
<GUI>
- <xloc>144</xloc>
+ <xloc>288</xloc>
<yloc>80</yloc>
</GUI>
</transform>
<transform>
- <name>test</name>
- <type>Dummy</type>
+ <name>read customers</name>
+ <type>MongoDbInput</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
@@ -92,9 +140,17 @@ limitations under the License.
<method>none</method>
<schema_name/>
</partitioning>
+ <connection>mongo</connection>
+ <fields_name/>
+ <collection>m_inserts_1</collection>
+ <json_field_name>json</json_field_name>
+ <json_query>{}</json_query>
+ <output_json>Y</output_json>
+ <query_is_pipeline>N</query_is_pipeline>
+ <execute_for_each_row>N</execute_for_each_row>
<attributes/>
<GUI>
- <xloc>544</xloc>
+ <xloc>144</xloc>
<yloc>80</yloc>
</GUI>
</transform>
@@ -133,8 +189,8 @@ limitations under the License.
</GUI>
</transform>
<transform>
- <name>get first name, last name</name>
- <type>JsonInput</type>
+ <name>test</name>
+ <type>Dummy</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
@@ -143,67 +199,9 @@ limitations under the License.
<method>none</method>
<schema_name/>
</partitioning>
- <include>N</include>
- <include_field/>
- <rownum>N</rownum>
- <addresultfile>N</addresultfile>
- <readurl>N</readurl>
- <removeSourceField>N</removeSourceField>
- <IsIgnoreEmptyFile>N</IsIgnoreEmptyFile>
- <doNotFailIfNoFile>Y</doNotFailIfNoFile>
- <ignoreMissingPath>Y</ignoreMissingPath>
- <defaultPathLeafToNull>Y</defaultPathLeafToNull>
- <rownum_field/>
- <file>
- <name/>
- <filemask/>
- <exclude_filemask/>
- <file_required>N</file_required>
- <include_subfolders>N</include_subfolders>
- </file>
- <fields>
- <field>
- <name>firstname</name>
- <path>$..firstname</path>
- <type>String</type>
- <format/>
- <currency/>
- <decimal/>
- <group/>
- <length>-1</length>
- <precision>-1</precision>
- <trim_type>none</trim_type>
- <repeat>N</repeat>
- </field>
- <field>
- <name>lastname</name>
- <path>$..name</path>
- <type>String</type>
- <format/>
- <currency/>
- <decimal/>
- <group/>
- <length>-1</length>
- <precision>-1</precision>
- <trim_type>none</trim_type>
- <repeat>N</repeat>
- </field>
- </fields>
- <limit>0</limit>
- <IsInFields>Y</IsInFields>
- <IsAFile>N</IsAFile>
- <valueField>json</valueField>
- <shortFileFieldName/>
- <pathFieldName/>
- <hiddenFieldName/>
- <lastModificationTimeFieldName/>
- <uriNameFieldName/>
- <rootUriNameFieldName/>
- <extensionFieldName/>
- <sizeFieldName/>
<attributes/>
<GUI>
- <xloc>288</xloc>
+ <xloc>544</xloc>
<yloc>80</yloc>
</GUI>
</transform>
diff --git
a/plugins/transforms/mongodb/src/main/java/org/apache/hop/mongo/metadata/MongoDbConnection.java
b/plugins/transforms/mongodb/src/main/java/org/apache/hop/mongo/metadata/MongoDbConnection.java
index 71a764e2dd..1a4adec6f5 100644
---
a/plugins/transforms/mongodb/src/main/java/org/apache/hop/mongo/metadata/MongoDbConnection.java
+++
b/plugins/transforms/mongodb/src/main/java/org/apache/hop/mongo/metadata/MongoDbConnection.java
@@ -23,6 +23,7 @@ import org.apache.hop.core.gui.plugin.GuiElementType;
import org.apache.hop.core.gui.plugin.GuiPlugin;
import org.apache.hop.core.gui.plugin.GuiWidgetElement;
import org.apache.hop.core.logging.ILogChannel;
+import org.apache.hop.core.util.Utils;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.metadata.api.HopMetadata;
import org.apache.hop.metadata.api.HopMetadataBase;
@@ -293,7 +294,8 @@ public class MongoDbConnection extends HopMetadataBase
implements IHopMetadata {
setIfNotNullOrEmpty(
variables, propertiesBuilder, MongoProp.AUTH_DATABASE,
authenticationDatabaseName);
setIfNotNullOrEmpty(variables, propertiesBuilder, MongoProp.USERNAME,
authenticationUser);
- setIfNotNullOrEmpty(variables, propertiesBuilder, MongoProp.PASSWORD,
authenticationPassword);
+ setIfNotNullOrEmptyPassword(
+ variables, propertiesBuilder, MongoProp.PASSWORD,
authenticationPassword);
setIfNotNullOrEmpty(
variables, propertiesBuilder, MongoProp.AUTH_MECHA,
authenticationMechanism.name());
setIfNotNullOrEmpty(
@@ -312,6 +314,13 @@ public class MongoDbConnection extends HopMetadataBase
implements IHopMetadata {
}
}
+ private static void setIfNotNullOrEmptyPassword(
+ IVariables variables, MongoProperties.Builder builder, MongoProp prop,
String value) {
+ if (StringUtils.isNotEmpty(value)) {
+ builder.set(prop, Utils.resolvePassword(variables,
variables.resolve(value)));
+ }
+ }
+
/**
* Gets hostname
*