From 348dc19ffbb8e62b4be11ac66f3a5ba2965927d8 Mon Sep 17 00:00:00 2001 From: weizhao1 Date: Thu, 23 Mar 2023 17:00:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0job=20db=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=8A=A0=E8=A7=A3=E5=AF=86=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/util/JobDataBasePwdDecryptUtil.java | 2 +- core/src/test/java/ConfigurationTest.java | 27 ++++++++- .../test/resources/conf/.secret.properties | 9 +++ .../resources/dwd_g2park_inout_report_s.json | 55 +++++++++++++++++++ 4 files changed, 89 insertions(+), 4 deletions(-) create mode 100755 core/src/test/resources/conf/.secret.properties create mode 100644 core/src/test/resources/dwd_g2park_inout_report_s.json diff --git a/core/src/main/java/com/alibaba/datax/core/util/JobDataBasePwdDecryptUtil.java b/core/src/main/java/com/alibaba/datax/core/util/JobDataBasePwdDecryptUtil.java index fd536ab5..c0a00c29 100644 --- a/core/src/main/java/com/alibaba/datax/core/util/JobDataBasePwdDecryptUtil.java +++ b/core/src/main/java/com/alibaba/datax/core/util/JobDataBasePwdDecryptUtil.java @@ -23,7 +23,7 @@ public class JobDataBasePwdDecryptUtil { //加密key String key = SecretUtil.getSecurityProperties().getProperty(CoreConstant.DB_ENCRYPT_KEY); if (StringUtils.isEmpty(key)) { - LOG.warn("{} is empty,use original password,", CoreConstant.DB_ENCRYPT_KEY); + LOG.warn("{} is empty,use original password", CoreConstant.DB_ENCRYPT_KEY); return; } if (StringUtils.isNotEmpty(readerPwd)) { diff --git a/core/src/test/java/ConfigurationTest.java b/core/src/test/java/ConfigurationTest.java index 5bb3b4cc..150efdd5 100644 --- a/core/src/test/java/ConfigurationTest.java +++ b/core/src/test/java/ConfigurationTest.java @@ -1,4 +1,7 @@ import com.alibaba.datax.common.util.Configuration; +import com.alibaba.datax.core.util.JobDataBasePwdDecryptUtil; +import com.alibaba.datax.core.util.SecretUtil; +import com.alibaba.datax.core.util.container.CoreConstant; import com.alibaba.fastjson2.JSON; import org.junit.Test; @@ -10,9 +13,27 @@ import java.io.File; * @Version 1.0 */ public class ConfigurationTest { + String key = "1qaz2wsx"; + String nativePassword = "12345678"; + + /** + * 测试密码解密 + */ @Test - public void configParseTest(){ - Configuration configuration=Configuration.from(new File("/Users/weizhao.dong/Documents/soft/datax_install_d/script/dwd_g2park_inout_report_s.json")); - System.out.println(JSON.toJSONString(configuration)); + public void dbEncryptPasswrdTest() { + System.setProperty("datax.home",System.getProperty("user.dir")+"/src/test/resources"); + Configuration configuration = Configuration.from(new File("src/test/resources/dwd_g2park_inout_report_s.json")); + JobDataBasePwdDecryptUtil.decrypt(configuration); + assert configuration.getString(CoreConstant.DATA_JOB_READER_PARAMETER_PASSWORD).equals(nativePassword); + assert configuration.getString(CoreConstant.DATA_JOB_WRITER_PARAMETER_PASSWORD).equals(nativePassword); + } + + /** + * 生成加密密码 + */ + @Test + public void generateEncryptPassword() { + //密码为:ZnOZROJwLiMeI3FQluEhHg== + System.out.println(SecretUtil.encrypt3DES(nativePassword, key)); } } diff --git a/core/src/test/resources/conf/.secret.properties b/core/src/test/resources/conf/.secret.properties new file mode 100755 index 00000000..f1f2485f --- /dev/null +++ b/core/src/test/resources/conf/.secret.properties @@ -0,0 +1,9 @@ +#ds basicAuth config +auth.user= +auth.pass= +current.keyVersion= +current.publicKey= +current.privateKey= +current.service.username= +current.service.password= +db.encrypt.key=1qaz2wsx diff --git a/core/src/test/resources/dwd_g2park_inout_report_s.json b/core/src/test/resources/dwd_g2park_inout_report_s.json new file mode 100644 index 00000000..84b011ff --- /dev/null +++ b/core/src/test/resources/dwd_g2park_inout_report_s.json @@ -0,0 +1,55 @@ +{ + "job": { + "content": [ + { + "reader": { + "name": "mysqlreader", + "parameter": { + "column": [ + "1 AS inout_type","i.enter_time AS report_date","i.create_time as create_time","i.park_code AS park_code","i.inout_id as inout_id","i.enter_time as enter_time","i.depart_time as depart_time","CAST( YEAR ( i.enter_time ) AS SIGNED ) AS report_year","CAST( MONTH ( i.enter_time ) AS SIGNED ) AS report_month","CAST( HOUR ( i.enter_time ) AS SIGNED ) AS report_hour","(CASE WHEN CHAR_LENGTH(i.client_no) = 0 OR i.client_no IS NULL THEN '0' ELSE i.client_no END) AS client_no","IFNULL(i.in_gateway, '0') AS gateway_no","1 AS total_num","( CASE WHEN i.vehicle_category = 1 THEN 1 ELSE 0 END ) AS big_car_num","( CASE WHEN i.vehicle_category <> 1 THEN 1 ELSE 0 END ) AS small_car_num","( CASE WHEN (i.vehicle_no REGEXP '[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DABCEFGHJK])|([DABCEFGHJK][A-HJ-NP-Z0-9][0-9]{4}))$' ) THEN 1 ELSE 0 END ) AS new_power_car_num","( CASE WHEN i.in_label = 2 OR i.in_label = 3 THEN 1 ELSE 0 END ) AS reserve_num","( CASE WHEN i.in_label = 1 THEN 1 ELSE 0 END ) AS white_list_num","( CASE WHEN i.vehicle_category = 1 AND ( i.in_label = 2 OR i.in_label = 3 ) THEN 1 ELSE 0 END ) AS big_car_reserve_num","( CASE WHEN i.vehicle_category = 1 AND i.in_label = 1 THEN 1 ELSE 0 END ) AS big_car_white_list_num","( CASE WHEN i.vehicle_category <> 1 AND ( i.in_label = 2 OR i.in_label = 3 ) THEN 1 ELSE 0 END ) AS small_car_reserve_num","( CASE WHEN i.vehicle_category <> 1 AND i.in_label = 1 THEN 1 ELSE 0 END ) AS small_car_white_list_num","( CASE WHEN ( i.in_label = 2 OR i.in_label = 3 ) AND ( i.vehicle_no REGEXP '[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DABCEFGHJK])|([DABCEFGHJK][A-HJ-NP-Z0-9][0-9]{4}))$' ) THEN 1 ELSE 0 END ) AS new_power_reserve_num","( CASE WHEN i.in_label = 1 AND ( i.vehicle_no REGEXP '[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DABCEFGHJK])|([DABCEFGHJK][A-HJ-NP-Z0-9][0-9]{4}))$' ) THEN 1 ELSE 0 END ) AS new_power_white_list_num"," i.deleted","CURRENT_TIMESTAMP AS update_time" + ], + "splitPk": "inout_id", + "connection": [ + { + "jdbcUrl": ["jdbc:mysql://127.0.0.1:3306/test_db?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&characterEncoding=utf-8&allowMultiQueries=true"], + "table": ["g2park_inout_record i"] + } + ], + "password": "ZnOZROJwLiMeI3FQluEhHg==", + "username": "root", + "where": "i.enter_time is not null and update_time > '${updateTime}' " + } + }, + "writer": { + "name": "mysqlwriter", + "parameter": { + "writeMode": "replace", + "column": [ + "inout_type","report_date","create_time","park_code","inout_id","enter_time","depart_time","report_year","report_month","report_hour","client_no","gateway_no","total_num","big_car_num","small_car_num","new_power_car_num","reserve_num","white_list_num","big_car_reserve_num","big_car_white_list_num","small_car_reserve_num","small_car_white_list_num","new_power_reserve_num","new_power_white_list_num","deleted","update_time" + ], + "connection": [ + { + "jdbcUrl": "jdbc:mysql://127.0.0.1:3306/test_db?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&characterEncoding=utf-8&allowMultiQueries=true", + "table": ["dwd_g2park_inout_report_s"] + } + ], + "password": "ZnOZROJwLiMeI3FQluEhHg==", + "username": "root", + "preSql": [], + "session": [ + "set session sql_mode='ANSI'" + ] + + } + } + } + ], + "setting": { + "speed": { + "channel": "2" + }, + "passwdEncrypt":true + + } + } +}