diff --git a/src/main/java/com/cisd/tms/modules/init/executor/ConfigurableInitStepExecutor.java b/src/main/java/com/cisd/tms/modules/init/executor/ConfigurableInitStepExecutor.java index a929acd..8614a8a 100644 --- a/src/main/java/com/cisd/tms/modules/init/executor/ConfigurableInitStepExecutor.java +++ b/src/main/java/com/cisd/tms/modules/init/executor/ConfigurableInitStepExecutor.java @@ -817,11 +817,9 @@ public class ConfigurableInitStepExecutor implements InitStepExecutor { int changed = 0; for (Path configFile : configFiles) { - changed += replaceProperty(configFile, "spring.rabbitmq.username", configuredUsername); - changed += replaceProperty(configFile, "spring.rabbitmq.password", configuredPassword); - appendLog(logFile, "updated app rabbitmq credentials: " + configFile); + appendLog(logFile, "skipped app rabbitmq credential rewrite: " + configFile); } - return InitStepExecutionResult.success("应用MQ凭据已应用,变更数量=" + changed, 0, logFile.toString()); + return InitStepExecutionResult.success("应用MQ凭据回写已跳过,变更数量=" + changed, 0, logFile.toString()); } private InitStepExecutionResult executeDirectDbInit(InitTaskEntity task, InitTaskStepEntity step) throws IOException { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e13cbfb..1f771a5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -147,7 +147,7 @@ tms: standard-rabbit-queue-script-path-02: ${TMS_INIT_EXECUTOR_STANDARD_RABBIT_QUEUE_SCRIPT_PATH_02:${tms.init.executor.standard-home-dir}/cpackage/rabq/addrabq_R_02.sh} # 通道用户授权 vhost(默认 /RQ)。 rabbit-vhost: ${TMS_INIT_EXECUTOR_RABBIT_VHOST:/RQ} - # 标准版应用配置文件匹配规则;用于回写 RabbitMQ 通道账号密码。 + # 标准版应用配置文件匹配规则;保留历史配置项,当前不再回写 RabbitMQ 通道账号密码。 standard-rabbit-app-config-patterns: - ${TMS_INIT_EXECUTOR_STANDARD_RABBIT_APP_CONFIG_PATTERN_1:${tms.init.executor.standard-home-dir}/cmsp/application-prd*.properties} - ${TMS_INIT_EXECUTOR_STANDARD_RABBIT_APP_CONFIG_PATTERN_2:${tms.init.executor.standard-home-dir}/cmtp/application-prd*.properties} @@ -166,7 +166,7 @@ tms: cisd: preset: # 设备预制版本:ENTERPRISE / INDIRECT / DIRECT。 - product-type: ${TMS_CISD_PRESET_PRODUCT_TYPE:ENTERPRISE} + product-type: ${TMS_CISD_PRESET_PRODUCT_TYPE:INDIRECT} # 预制版本号(用于前端展示与任务记录)。 version: ${TMS_CISD_PRESET_VERSION:V1.0.0} # 预制信息来源标识(CONFIG/DB 等自定义值)。 diff --git a/src/test/java/com/cisd/tms/modules/init/executor/ConfigurableInitStepExecutorTest.java b/src/test/java/com/cisd/tms/modules/init/executor/ConfigurableInitStepExecutorTest.java index b5e6426..8446294 100644 --- a/src/test/java/com/cisd/tms/modules/init/executor/ConfigurableInitStepExecutorTest.java +++ b/src/test/java/com/cisd/tms/modules/init/executor/ConfigurableInitStepExecutorTest.java @@ -380,7 +380,7 @@ class ConfigurableInitStepExecutorTest { } @Test - void shouldApplyStandardAppMqCredentials() throws Exception { + void shouldNotRewriteStandardAppMqCredentials() throws Exception { Path tempRoot = Files.createTempDirectory("init-executor-standard-rabbit-cred-test"); Path cmspDir = tempRoot.resolve("cmsp"); Path cmtpDir = tempRoot.resolve("cmtp"); @@ -424,12 +424,58 @@ class ConfigurableInitStepExecutorTest { InitStepExecutionResult result = executor.execute(task, step); Assertions.assertTrue(result.isSuccess()); - String encryptedUser = encryptWith3DesHex("new_user", "ABCDEFGHIJKLMN1234567890"); - String encryptedPass = encryptWith3DesHex("new_pass", "ABCDEFGHIJKLMN1234567890"); - Assertions.assertTrue(Files.readString(cmspCfg).contains("spring.rabbitmq.username=" + encryptedUser)); - Assertions.assertTrue(Files.readString(cmspCfg).contains("spring.rabbitmq.password=" + encryptedPass)); - Assertions.assertTrue(Files.readString(cmtpCfg).contains("spring.rabbitmq.username=" + encryptedUser)); - Assertions.assertTrue(Files.readString(cmtpCfg).contains("spring.rabbitmq.password=" + encryptedPass)); + Assertions.assertEquals("spring.rabbitmq.username=OLD\nspring.rabbitmq.password=OLD\n", Files.readString(cmspCfg)); + Assertions.assertEquals("spring.rabbitmq.username=OLD\nspring.rabbitmq.password=OLD\n", Files.readString(cmtpCfg)); + } + + @Test + void shouldNotRewriteStandardMediaTemplateWhenApplyingAppMqCredentials() throws Exception { + Path tempRoot = Files.createTempDirectory("init-executor-standard-rabbit-template-test"); + Path templateDir = tempRoot.resolve("cpackage/cmsp/01"); + Path runtimeDir = tempRoot.resolve("cmsp"); + Files.createDirectories(templateDir); + Files.createDirectories(runtimeDir); + Path templateCfg = templateDir.resolve("application-prd-ci01.properties"); + Path runtimeCfg = runtimeDir.resolve("application-prd-ci01.properties"); + String original = "spring.rabbitmq.username=FIXED\nspring.rabbitmq.password=FIXED\n"; + Files.writeString(templateCfg, original); + Files.writeString(runtimeCfg, "spring.rabbitmq.username=OLD\nspring.rabbitmq.password=OLD\n"); + + InitExecutorProperties properties = new InitExecutorProperties(); + properties.setMode(InitExecutorProperties.Mode.LOCAL); + properties.setLogDir(tempRoot.resolve("logs").toString()); + properties.setStandardRabbitAppConfigPatterns(List.of( + templateCfg.toString(), + runtimeCfg.toString() + )); + ConfigurableInitStepExecutor executor = new ConfigurableInitStepExecutor(properties, new ObjectMapper()); + + InitTaskEntity task = new InitTaskEntity(); + task.setTaskId("TASK-APP-CRED-TEMPLATE-1"); + task.setProductType("ENTERPRISE"); + task.setInitPlanJson(buildInitPlanJson( + "ENTERPRISE", + Map.of( + "orgCodeType", "BIC", + "orgCode", "AAAABBBBXXX", + "orgNameCn", "测试机构", + "orgNameEn", "TEST BANK", + "deployMode", "SINGLE", + "nodes", Map.of("node01Ip", "10.0.1.1"), + "mq", Map.of("mqType", "RABBITMQ", "channelUsername", "new_user", "channelPassword", "new_pass"), + "licenses", Map.of("receiverLicenseFileId", "file-receiver-001") + ) + )); + + InitTaskStepEntity step = new InitTaskStepEntity(); + step.setStepNo(1); + step.setStepCode("APP_MQ_CREDENTIALS_APPLY"); + step.setCommandLine("internal::app_mq_credentials_apply"); + + InitStepExecutionResult result = executor.execute(task, step); + Assertions.assertTrue(result.isSuccess()); + Assertions.assertEquals(original, Files.readString(templateCfg)); + Assertions.assertEquals("spring.rabbitmq.username=OLD\nspring.rabbitmq.password=OLD\n", Files.readString(runtimeCfg)); } @Test