From c4c6939fd2ec421a98614f2ff18fe9bb4cf6b2bc Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Thu, 8 Oct 2020 21:45:05 +0800 Subject: [PATCH 01/21] #1119 add unit tests --- .gitignore | 1 + .../com/webank/cmdb/config/TestConfig.java | 2 +- .../ui/helper/UIWrapperServiceTest.java | 50 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 cmdb-core/src/test/java/com/webank/cmdb/controller/ui/helper/UIWrapperServiceTest.java diff --git a/.gitignore b/.gitignore index e629dd4ec..cf5a93bbc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ target/ +cmdb-core/data/ # Ignore the generated front-end resource **/resources/static/ # Ignore the generated index.html diff --git a/cmdb-core/src/test/java/com/webank/cmdb/config/TestConfig.java b/cmdb-core/src/test/java/com/webank/cmdb/config/TestConfig.java index f3dcd23c8..7c66fa28d 100755 --- a/cmdb-core/src/test/java/com/webank/cmdb/config/TestConfig.java +++ b/cmdb-core/src/test/java/com/webank/cmdb/config/TestConfig.java @@ -16,7 +16,7 @@ import org.springframework.jdbc.datasource.embedded.ConnectionProperties; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseConfigurer; -@Configuration +//@Configuration @Import(DatabaseConfig.class) public class TestConfig { private static Logger logger = LoggerFactory.getLogger(TestConfig.class); diff --git a/cmdb-core/src/test/java/com/webank/cmdb/controller/ui/helper/UIWrapperServiceTest.java b/cmdb-core/src/test/java/com/webank/cmdb/controller/ui/helper/UIWrapperServiceTest.java new file mode 100644 index 000000000..690cc3a7f --- /dev/null +++ b/cmdb-core/src/test/java/com/webank/cmdb/controller/ui/helper/UIWrapperServiceTest.java @@ -0,0 +1,50 @@ +package com.webank.cmdb.controller.ui.helper; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.webank.cmdb.dto.CiData; +import com.webank.cmdb.dto.QueryRequest; +import com.webank.cmdb.dto.QueryResponse; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class UIWrapperServiceTest { + + @Autowired + private UIWrapperService uiWrapperService; + + @Test + public void test_queryCiDataByType() { + Integer ciTypeId = 32; + QueryRequest queryObject = new QueryRequest(); + QueryResponse response = uiWrapperService.queryCiData( ciTypeId, queryObject); + + System.out.println(response.getContents().size()); + } + + @Test + public void test_updateCiData(){ + + Integer ciTypeId = 32; + List> ciDatas = new ArrayList<>(); + Map ciData = new HashMap<>(); + ciData.put("guid", "0032_0000000002"); + ciData.put("description", "test"); + + ciDatas.add(ciData); + + List> result = uiWrapperService.updateCiData( ciTypeId, ciDatas); + + System.out.println(result); + } + +} From 3042ed4fcb46ec90ef847806dcd2609be6445027 Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Sat, 10 Oct 2020 10:01:59 +0800 Subject: [PATCH 02/21] #1119 add ci update intf --- .../cmdb/service/UIWrapperServiceTests.java | 38 +++++++++++++++++ .../cmdb/service/testQueryReferenceData.json | 42 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java create mode 100644 cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json diff --git a/cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java b/cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java new file mode 100644 index 000000000..1727bd888 --- /dev/null +++ b/cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java @@ -0,0 +1,38 @@ +package com.webank.cmdb.service; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.FileUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.webank.cmdb.controller.ui.helper.UIWrapperService; +import com.webank.cmdb.dto.QueryRequest; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class UIWrapperServiceTests { + + String filename = "testQueryReferenceData.json"; + + @Autowired + private UIWrapperService wrapperService; + + @Test + public void testQueryReferenceData() throws IOException { + File inputFile = FileUtils.toFile(UIWrapperServiceTests.class.getResource(filename)); + String inputJson = FileUtils.readFileToString(inputFile); + + System.out.println("inputJson:"+inputJson); + int referenceAttrId = 933; + QueryRequest queryObject = new QueryRequest(); + Object result = wrapperService.queryReferenceCiData(referenceAttrId, queryObject); + + System.out.println("result:"+result); + } + +} diff --git a/cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json b/cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json new file mode 100644 index 000000000..51e320b12 --- /dev/null +++ b/cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json @@ -0,0 +1,42 @@ +{ + "filters": [], + "paging": false, + "dialect": { + "associatedData": { + "code": "demonginx01_IP3424:10001", + "deploy_package": "0045_0000000007", + "memory": "1", + "deploy_package_url": "", + "r_guid": "0050_0000000015", + "monitor_port": "10001", + "description": "", + "deploy_user_password": "******", + "storage": "20", + "host_resource_instance": "0032_0000000021", + "rw_dir": "", + "start_script": "/data/PRD_TaDEMO_PROXY_NGINX/demo-app-nginx_0.1.1/bin/start.sh", + "monitor_key_name": "IP3424:10001", + "port_conflict": "IP3424:10001", + "state": 40, + "fixed_date": "2020-09-01 17:30:04", + "deploy_script": "/data/PRD_TaDEMO_PROXY_NGINX/demo-app-nginx_0.1.1/bin/deploy.sh", + "deploy_user": "root", + "stop_script": "/data/PRD_TaDEMO_PROXY_NGINX/demo-app-nginx_0.1.1/bin/stop.sh", + "app_log_files": "", + "cpu": "1", + "created_by": "umadmin", + "key_name": "demonginx01_IP3424:10001", + "p_guid": null, + "unit": "0048_0000000020", + "port": "10001", + "rw_file": "", + "variable_values": "port,\u0001backend_server_ip_1,\u0001backend_server_port_1,\u0001backend_server_ip_2,\u0001backend_server_port_2,\u0001context_path\u0001=\u0001,\u0001IP9754,\u000110001,\u0001IP3675,\u000110001,\u0001~*^.+$", + "name": "demonginx01", + "updated_by": null, + "guid": "0050_0000000015", + "created_date": "2020-05-22 16:30:47", + "updated_date": null, + "state_code": "created" + } + } +} \ No newline at end of file From 10e3dd34b52abf3f55d36b6ac111e8c6f61f9d34 Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Sat, 10 Oct 2020 17:41:32 +0800 Subject: [PATCH 03/21] #1119 add ci update interface --- .../controller/WecubeAdapterController.java | 16 ++++++ .../dto/wecube/OperateCiDataUpdateDto.java | 43 ++++++++++++++++ .../wecube/OperateCiDataUpdateDtoInputs.java | 16 ++++++ .../wecmdb/service/WecubeAdapterService.java | 50 +++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/dto/wecube/OperateCiDataUpdateDto.java create mode 100644 cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/dto/wecube/OperateCiDataUpdateDtoInputs.java diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/controller/WecubeAdapterController.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/controller/WecubeAdapterController.java index 66ca460e7..490dcd37d 100644 --- a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/controller/WecubeAdapterController.java +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/controller/WecubeAdapterController.java @@ -111,6 +111,22 @@ public OperateCiJsonResponse confirmBatchCiData(@RequestBody OperateCiDtoInputs } return response; } + + @PostMapping("/data/update") + @ResponseBody + public OperateCiJsonResponse updateCiData(@RequestBody OperateCiDataUpdateDtoInputs inputs) { + List operateCiDataUpdateDtos = inputs.getInputs(); + OperateCiJsonResponse response = new OperateCiJsonResponse(); + List exceptionHolders = new ArrayList(); + List> results = wecubeAdapterService.updateCiDataByGuid(operateCiDataUpdateDtos, exceptionHolders); + + if (exceptionHolders.size() > 0) { + response = OperateCiJsonResponse.errorWithData(String.format("Fail to update [%s] CIs, detail error in the data block", inputs), results); + } else { + response = OperateCiJsonResponse.okayWithData(results); + } + return response; + } @PostMapping("/data/refresh") @ResponseBody diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/dto/wecube/OperateCiDataUpdateDto.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/dto/wecube/OperateCiDataUpdateDto.java new file mode 100644 index 000000000..a28740d51 --- /dev/null +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/dto/wecube/OperateCiDataUpdateDto.java @@ -0,0 +1,43 @@ +package com.webank.plugins.wecmdb.dto.wecube; + +public class OperateCiDataUpdateDto { + private String callbackParameter; + private String entityName; + private String guid; + private String attrName; + private Object attrVal; + public String getCallbackParameter() { + return callbackParameter; + } + public void setCallbackParameter(String callbackParameter) { + this.callbackParameter = callbackParameter; + } + + public String getEntityName() { + return entityName; + } + public void setEntityName(String entityName) { + this.entityName = entityName; + } + public String getGuid() { + return guid; + } + public void setGuid(String guid) { + this.guid = guid; + } + public String getAttrName() { + return attrName; + } + public void setAttrName(String attrName) { + this.attrName = attrName; + } + public Object getAttrVal() { + return attrVal; + } + public void setAttrVal(Object attrVal) { + this.attrVal = attrVal; + } + + + +} diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/dto/wecube/OperateCiDataUpdateDtoInputs.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/dto/wecube/OperateCiDataUpdateDtoInputs.java new file mode 100644 index 000000000..7cbe336af --- /dev/null +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/dto/wecube/OperateCiDataUpdateDtoInputs.java @@ -0,0 +1,16 @@ +package com.webank.plugins.wecmdb.dto.wecube; + +import java.util.List; + +public class OperateCiDataUpdateDtoInputs { + + private List inputs; + + public List getInputs() { + return inputs; + } + + public void setInputs(List inputs) { + this.inputs = inputs; + } +} diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java index f17958e3f..145ce4766 100644 --- a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java @@ -23,6 +23,7 @@ import javax.transaction.Transactional; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -394,6 +395,55 @@ public List> updateCiData(String entityName, List> updateCiDataByGuid(List operateCiDataUpdateDtos, List exceptionHolders){ + List> results = new ArrayList<>(); + operateCiDataUpdateDtos.forEach(operateCiDataUpdateDto -> { + Map resultItem = new HashMap<>(); + resultItem.put(CALLBACK_PARAMETER, operateCiDataUpdateDto.getCallbackParameter()); + resultItem.put(ERROR_CODE, SUCCESS); + resultItem.put(ERROR_MESSAGE, ""); + + if (StringUtils.isBlank(operateCiDataUpdateDto.getGuid())) { + String errorMessage = "Field 'guid' is required for CI data update."; + resultItem.put(ERROR_CODE, SUCCESS); + resultItem.put(ERROR_MESSAGE, errorMessage); + results.add(resultItem); + return; + } + + String guid = operateCiDataUpdateDto.getGuid(); + + try { + updateSingleCiDataByGuid(operateCiDataUpdateDto); + resultItem.put("guid", guid); + results.add(resultItem); + }catch(Exception e) { + String errorMessage = String.format("Failed to update CI [guid = %s], error = %s", guid, e.getMessage()); + resultItem.put(ERROR_CODE, FAIL); + resultItem.put(ERROR_MESSAGE, errorMessage); + exceptionHolders.add(new ExceptionHolder(operateCiDataUpdateDto.getCallbackParameter(), operateCiDataUpdateDto, errorMessage, null)); + results.add(resultItem); + return; + } + }); + + return results; + } + + private void updateSingleCiDataByGuid(OperateCiDataUpdateDto operateCiDataUpdateDto) { + String entityName = operateCiDataUpdateDto.getEntityName(); + String guid = operateCiDataUpdateDto.getGuid(); + String attrName = operateCiDataUpdateDto.getAttrName(); + Object attrVal = operateCiDataUpdateDto.getAttrVal(); + + Map convertedUpdateReq = new HashMap(); + convertedUpdateReq.put("guid", guid); + convertedUpdateReq.put(attrName, attrVal); + + updateCiData(entityName, Arrays.asList(convertedUpdateReq)); + } private List> convertedRequest(List> originRequest) { List> convertedRequest = new ArrayList<>(); From 0564c7f23df49b525ae1c84e5c57659a0f67e954 Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Mon, 12 Oct 2020 14:29:32 +0800 Subject: [PATCH 04/21] #1119 add log and update interface --- cmdb-core/src/main/resources/application.yml | 6 ------ .../src/main/resources/logback-spring.xml | 2 +- .../com/webank/cmdb/config/TestConfig.java | 2 +- .../src/test/resources/application-test.yml | 18 +++++++++--------- cmdb-plugin/register.xml | 13 +++++++++++++ .../wecmdb/service/WecubeAdapterService.java | 1 + cmdb-plugin/src/main/resources/application.yml | 12 ++++++------ .../src/main/resources/logback-spring.xml | 4 ++-- 8 files changed, 33 insertions(+), 25 deletions(-) diff --git a/cmdb-core/src/main/resources/application.yml b/cmdb-core/src/main/resources/application.yml index ca8c5883f..04fc42aff 100755 --- a/cmdb-core/src/main/resources/application.yml +++ b/cmdb-core/src/main/resources/application.yml @@ -62,9 +62,3 @@ cmdb: #Effective ONLY when security-enabled set as true whitelist-ip-address: 127.0.0.1 -logging: - level: - root: INFO - com: - webank: - cmdb: INFO diff --git a/cmdb-core/src/main/resources/logback-spring.xml b/cmdb-core/src/main/resources/logback-spring.xml index d4cfcbcfd..c8964e136 100644 --- a/cmdb-core/src/main/resources/logback-spring.xml +++ b/cmdb-core/src/main/resources/logback-spring.xml @@ -1,7 +1,7 @@ - + diff --git a/cmdb-core/src/test/java/com/webank/cmdb/config/TestConfig.java b/cmdb-core/src/test/java/com/webank/cmdb/config/TestConfig.java index 7c66fa28d..f3dcd23c8 100755 --- a/cmdb-core/src/test/java/com/webank/cmdb/config/TestConfig.java +++ b/cmdb-core/src/test/java/com/webank/cmdb/config/TestConfig.java @@ -16,7 +16,7 @@ import org.springframework.jdbc.datasource.embedded.ConnectionProperties; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseConfigurer; -//@Configuration +@Configuration @Import(DatabaseConfig.class) public class TestConfig { private static Logger logger = LoggerFactory.getLogger(TestConfig.class); diff --git a/cmdb-core/src/test/resources/application-test.yml b/cmdb-core/src/test/resources/application-test.yml index 0b6a0e709..86240b028 100755 --- a/cmdb-core/src/test/resources/application-test.yml +++ b/cmdb-core/src/test/resources/application-test.yml @@ -21,12 +21,12 @@ cmdb: enabled: false whitelist-ip-address: 127.0.0.1 -logging: - level: - root: WARN - com: - webank: - cmdb: INFO - org: - hibernate: - SQL: INFO \ No newline at end of file +#logging: +# level: +# root: WARN +# com: +# webank: +# cmdb: INFO +# org: +# hibernate: +# SQL: INFO \ No newline at end of file diff --git a/cmdb-plugin/register.xml b/cmdb-plugin/register.xml index 67f1a674a..003916683 100644 --- a/cmdb-plugin/register.xml +++ b/cmdb-plugin/register.xml @@ -142,5 +142,18 @@ + + + + entityName + guid + attrName + attrVal + + + guid + + + diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java index 145ce4766..f515d6452 100644 --- a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java @@ -421,6 +421,7 @@ public List> updateCiDataByGuid(List results.add(resultItem); }catch(Exception e) { String errorMessage = String.format("Failed to update CI [guid = %s], error = %s", guid, e.getMessage()); + logger.warn(errorMessage, e); resultItem.put(ERROR_CODE, FAIL); resultItem.put(ERROR_MESSAGE, errorMessage); exceptionHolders.add(new ExceptionHolder(operateCiDataUpdateDto.getCallbackParameter(), operateCiDataUpdateDto, errorMessage, null)); diff --git a/cmdb-plugin/src/main/resources/application.yml b/cmdb-plugin/src/main/resources/application.yml index 960663b68..ffa2ebe78 100644 --- a/cmdb-plugin/src/main/resources/application.yml +++ b/cmdb-plugin/src/main/resources/application.yml @@ -77,10 +77,10 @@ platform: sub-system-private-key: MockPrivateKey auth-server-public-key: MockPublicKey -logging: - level: - root: INFO - com: - webank: - cmdb: INFO +#logging: +# level: +# root: INFO +# com: +# webank: +# cmdb: INFO \ No newline at end of file diff --git a/cmdb-plugin/src/main/resources/logback-spring.xml b/cmdb-plugin/src/main/resources/logback-spring.xml index facc04ec7..2c2878281 100644 --- a/cmdb-plugin/src/main/resources/logback-spring.xml +++ b/cmdb-plugin/src/main/resources/logback-spring.xml @@ -1,7 +1,7 @@ - + @@ -36,8 +36,8 @@ - From 82cdd8d6e25fd606230135ad6828841804177738 Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Mon, 12 Oct 2020 14:56:20 +0800 Subject: [PATCH 05/21] #1119 ignore unit test --- .../java/com/webank/cmdb/service/UIWrapperServiceTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java b/cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java index 1727bd888..9460342fa 100644 --- a/cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java +++ b/cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java @@ -4,6 +4,7 @@ import java.io.IOException; import org.apache.commons.io.FileUtils; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -13,6 +14,7 @@ import com.webank.cmdb.controller.ui.helper.UIWrapperService; import com.webank.cmdb.dto.QueryRequest; +@Ignore @RunWith(SpringRunner.class) @SpringBootTest public class UIWrapperServiceTests { From 0b0a6731e12d45284ff6851504e0d677db906a98 Mon Sep 17 00:00:00 2001 From: pobu168 <244202969@qq.com> Date: Tue, 13 Oct 2020 16:51:05 +0800 Subject: [PATCH 06/21] Upgrade variable_values tooltip display --- .../src/pages/components/cmdb-table/index.js | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/cmdb-ui/src/pages/components/cmdb-table/index.js b/cmdb-ui/src/pages/components/cmdb-table/index.js index 20cadeca5..f89c52ac1 100644 --- a/cmdb-ui/src/pages/components/cmdb-table/index.js +++ b/cmdb-ui/src/pages/components/cmdb-table/index.js @@ -581,6 +581,32 @@ export default { } }) }, + // 优化差异化变量tooltip显示 + managementContent (str) { + let arr = str.split(',') + const sIndex = arr.findIndex(item => item.indexOf('=') > 0) + let keyArr = [] + let valueArr = [] + arr.forEach((item, index) => { + if (index < sIndex) { + keyArr.push(item) + } else if (index === sIndex) { + let splitTag = item.split('=') + keyArr.push(splitTag[0]) + valueArr.unshift(splitTag[1]) + } else { + valueArr.push(item) + } + }) + // 差异化表达式中字段加了奇葩字符,加此空格优化显示 + keyArr[0] = ' ' + keyArr[0] + let res = [] + const len = Math.max(keyArr.length, valueArr.length) + for (let j = 0; j < len; j++) { + res.push((keyArr[j] || '***') + '=' + (valueArr[j] || '')) + } + return res.join('\n') + }, renderCol (col, isLastCol = false) { return { ...col, @@ -603,7 +629,6 @@ export default { } else { content = params.row.weTableForm[col.key] } - const containerId = 'ref' + Math.ceil(Math.random() * 1000000) return h( @@ -617,7 +642,11 @@ export default { ) { this.timer = setTimeout( params => { - this.tipContent = content + if (col.key === 'variable_values') { + this.tipContent = this.managementContent(content) + } else { + this.tipContent = content + } const popcorn = document.querySelector('#' + containerId) const tooltip = document.querySelector('#' + params.randomId) createPopper(popcorn, tooltip, { @@ -737,7 +766,7 @@ export default {
{this.tipContent && (
- {this.tipContent} +

{this.tipContent}

)}
From 25a35f1b06cf2ec0ba06a7f0210ff24740e5afeb Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Wed, 14 Oct 2020 13:37:37 +0800 Subject: [PATCH 07/21] #1142 add proc enc --- cmdb-plugin/pom.xml | 162 ++++++++------ .../webank/plugins/wecmdb/Application.java | 6 +- .../config/PluginApplicationProperties.java | 18 ++ .../wecmdb/propenc/EncryptionException.java | 37 ++++ .../propenc/RsaBasedStringEncryptor.java | 80 +++++++ .../RsaEncryptablePropertyDetector.java | 29 +++ .../plugins/wecmdb/propenc/RsaEncryptor.java | 209 ++++++++++++++++++ .../wecmdb/propenc/RsaKeyDetector.java | 86 +++++++ .../plugins/wecmdb/propenc/RsaKeyPair.java | 27 +++ .../wecmdb/propenc/RsaKeyPairBuilder.java | 37 ++++ .../src/main/resources/application.yml | 1 + 11 files changed, 619 insertions(+), 73 deletions(-) create mode 100644 cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/config/PluginApplicationProperties.java create mode 100644 cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/EncryptionException.java create mode 100644 cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaBasedStringEncryptor.java create mode 100644 cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaEncryptablePropertyDetector.java create mode 100644 cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaEncryptor.java create mode 100644 cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyDetector.java create mode 100644 cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyPair.java create mode 100644 cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyPairBuilder.java diff --git a/cmdb-plugin/pom.xml b/cmdb-plugin/pom.xml index 59c12d977..f6b64f8c7 100644 --- a/cmdb-plugin/pom.xml +++ b/cmdb-plugin/pom.xml @@ -1,81 +1,99 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + 4.0.0 - - com.webank.cmdb - cmdb - ${cmdb.version} - + + com.webank.cmdb + cmdb + ${cmdb.version} + - wecube-plugins-wecmdb - jar + wecube-plugins-wecmdb + jar - - - com.webank.cmdb - cmdb-core - ${cmdb.version} - - - org.springframework.boot - spring-boot-starter-web - - - org.apache.httpcomponents - httpclient - - - io.springfox - springfox-swagger2 - 2.9.2 - - - io.springfox - springfox-swagger-ui - 2.9.2 - + + + com.webank.cmdb + cmdb-core + ${cmdb.version} + + + org.springframework.boot + spring-boot-starter-web + + + org.apache.httpcomponents + httpclient + + + io.springfox + springfox-swagger2 + 2.9.2 + + + io.springfox + springfox-swagger-ui + 2.9.2 + - - org.springframework.boot - spring-boot-starter-test - test - - - junit - junit - test - - - com.alibaba - fastjson - 1.2.47 - - + + org.springframework.boot + spring-boot-starter-test + test + + + junit + junit + test + + + com.alibaba + fastjson + 1.2.47 + + + + org.bouncycastle + bcprov-ext-jdk15on + 1.63 + - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - 1 - true - -Xmx2048m -XX:MaxPermSize=256m - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + commons-codec + commons-codec + + + + com.github.ulisesbocchio + jasypt-spring-boot-starter + 3.0.3 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + 1 + true + -Xmx2048m -XX:MaxPermSize=256m + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/Application.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/Application.java index adc92fba9..c8f193b63 100644 --- a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/Application.java +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/Application.java @@ -4,11 +4,13 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Import; -import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; +import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; +import com.webank.cmdb.config.ApplicationProperties; import com.webank.cmdb.config.DatabaseConfig; import com.webank.cmdb.config.SpringAppConfig; import com.webank.cmdb.config.SpringWebConfig; @@ -17,6 +19,8 @@ @SpringBootApplication @EnableSwagger2 +@EnableConfigurationProperties({ApplicationProperties.class}) +@EnableEncryptableProperties @ComponentScan({ "com.webank.plugins.wecmdb.service", "com.webank.plugins.wecmdb.controller", "com.webank.plugins.wecmdb.mvc", "com.webank.cmdb.config", "com.webank.cmdb.repository" }) @Import({ DatabaseConfig.class }) public class Application extends AbstractAnnotationConfigDispatcherServletInitializer { diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/config/PluginApplicationProperties.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/config/PluginApplicationProperties.java new file mode 100644 index 000000000..5eeb77d79 --- /dev/null +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/config/PluginApplicationProperties.java @@ -0,0 +1,18 @@ +package com.webank.plugins.wecmdb.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "plugins") +public class PluginApplicationProperties { + private String propertyEncryptKeyPath; + + public String getPropertyEncryptKeyPath() { + return propertyEncryptKeyPath; + } + + public void setPropertyEncryptKeyPath(String propertyEncryptKeyPath) { + this.propertyEncryptKeyPath = propertyEncryptKeyPath; + } + + +} diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/EncryptionException.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/EncryptionException.java new file mode 100644 index 000000000..2a0cc871e --- /dev/null +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/EncryptionException.java @@ -0,0 +1,37 @@ +package com.webank.plugins.wecmdb.propenc; + +/** + * + * @author gavin + * + */ +public class EncryptionException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 115523361878991641L; + + public EncryptionException() { + super(); + } + + public EncryptionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + + public EncryptionException(String message, Throwable cause) { + super(message, cause); + } + + public EncryptionException(String message) { + super(message); + } + + public EncryptionException(Throwable cause) { + super(cause); + } + + + +} diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaBasedStringEncryptor.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaBasedStringEncryptor.java new file mode 100644 index 000000000..da0571513 --- /dev/null +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaBasedStringEncryptor.java @@ -0,0 +1,80 @@ +package com.webank.plugins.wecmdb.propenc; + +import javax.annotation.PostConstruct; + +import org.apache.commons.lang3.StringUtils; +import org.jasypt.encryption.StringEncryptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.webank.plugins.wecmdb.config.PluginApplicationProperties; + +/** + * + * @author gavin + * + */ +@Component("jasyptStringEncryptor") +public class RsaBasedStringEncryptor implements StringEncryptor { + private static final Logger log = LoggerFactory.getLogger(RsaBasedStringEncryptor.class); + + @Autowired + private PluginApplicationProperties appConfigProperties; + + private RsaKeyPair propencRsaKeyPair; + + @PostConstruct + public void afterPropertySet(){ + initPropencRsaKeyPair(); + } + + @Override + public String decrypt(String cipherValue) { + if(!isAvailable()) { + return cipherValue; + } + + try { + byte[] data = RsaEncryptor.decryptByPrivateKey(RsaEncryptor.decodeBase64(cipherValue), + propencRsaKeyPair.getPrivateKey()); + String rawValue = new String(data, RsaEncryptor.DEF_CHARSET); + + return rawValue; + } catch (Exception e) { + log.error("errors while decrypt {} with private key:{}", cipherValue, e.getMessage()); + throw new EncryptionException("Failed to decrypt cipher text due to " + e.getMessage()); + } + } + + @Override + public String encrypt(String rawValue) { + byte[] data = RsaEncryptor.encryptByPublicKey(rawValue.getBytes(RsaEncryptor.DEF_CHARSET), + propencRsaKeyPair.getPublicKey()); + return RsaEncryptor.encodeBase64String(data); + } + + protected void initPropencRsaKeyPair() { + RsaKeyDetector keyDetector = new RsaKeyDetector( + appConfigProperties.getPropertyEncryptKeyPath()); + RsaKeyPair keyPair = keyDetector.detectRsaKeyPair(); + if (keyPair != null) { + log.info("Property encryption RSA key prepared!"); + } + this.propencRsaKeyPair = keyPair; + } + + public boolean isAvailable() { + if(propencRsaKeyPair == null) { + return false; + } + + if(StringUtils.isBlank(propencRsaKeyPair.getPrivateKey())) { + return false; + } + + return true; + } + +} diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaEncryptablePropertyDetector.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaEncryptablePropertyDetector.java new file mode 100644 index 000000000..07682f0a9 --- /dev/null +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaEncryptablePropertyDetector.java @@ -0,0 +1,29 @@ +package com.webank.plugins.wecmdb.propenc; + +import org.springframework.stereotype.Component; + +import com.ulisesbocchio.jasyptspringboot.EncryptablePropertyDetector; + +/** + * + * @author gavin + * + */ +@Component("encryptablePropertyDetector") +public class RsaEncryptablePropertyDetector implements EncryptablePropertyDetector { + public static final String DEF_ENC_PREFIX = "RSA@"; + + @Override + public boolean isEncrypted(String value) { + if (value != null) { + return value.startsWith(DEF_ENC_PREFIX); + } + return false; + } + + @Override + public String unwrapEncryptedValue(String value) { + return value.trim().substring(DEF_ENC_PREFIX.length()); + } + +} diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaEncryptor.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaEncryptor.java new file mode 100644 index 000000000..449d603eb --- /dev/null +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaEncryptor.java @@ -0,0 +1,209 @@ +package com.webank.plugins.wecmdb.propenc; + +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.security.InvalidKeyException; +import java.security.KeyFactory; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.Security; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; + +import org.apache.commons.codec.binary.Base64; +import org.bouncycastle.jce.provider.BouncyCastleProvider; + +/** + * 512 PKCS#8 + * @author gavin + * + */ +public final class RsaEncryptor { + + public static final String KEY_ALGORITHM = "RSA"; + + public static final String DEF_ENCODING = "UTF-8"; + public static final Charset DEF_CHARSET = Charset.forName(DEF_ENCODING); + + private static final int KEY_SIZE = 512; + + private static final RsaEncryptor _INSTANCE = new RsaEncryptor(); + + private boolean useExternalProvider = true; + + private RsaEncryptor() { + } + + public static String encodeBase64String(byte[] data){ + return Base64.encodeBase64String(data); + } + + public static byte[] decodeBase64(String base64String){ + return Base64.decodeBase64(base64String); + } + + public static RsaKeyPair initKey() { + try { + return _INSTANCE.doInitKey(); + } catch (NoSuchAlgorithmException e) { + throw new EncryptionException(e.getMessage()); + } catch (UnsupportedEncodingException e) { + throw new EncryptionException(e.getMessage()); + } + } + + public static byte[] decryptByPrivateKey(byte[] data, String base64KeyVal){ + return decryptByPrivateKey(data, decodeBase64(base64KeyVal)); + } + + public static byte[] decryptByPrivateKey(byte[] data, byte[] key) { + try { + return _INSTANCE.doDecryptByPrivateKey(data, key); + } catch (NoSuchAlgorithmException | InvalidKeySpecException | NoSuchPaddingException | InvalidKeyException + | IllegalBlockSizeException | BadPaddingException e) { + throw new EncryptionException(e.getMessage()); + } + + } + + public static byte[] encryptByPrivateKey(byte[] data, String base64KeyVal){ + return encryptByPrivateKey(data,decodeBase64(base64KeyVal)); + } + + public static byte[] encryptByPrivateKey(byte[] data, byte[] key) { + try { + return _INSTANCE.doEncryptByPrivateKey(data, key); + } catch (InvalidKeyException | NoSuchAlgorithmException | InvalidKeySpecException | NoSuchPaddingException + | IllegalBlockSizeException | BadPaddingException e) { + throw new EncryptionException(e.getMessage()); + } + } + + public static byte[] decryptByPublicKey(byte[] data, String base64KeyVal){ + return decryptByPublicKey(data, decodeBase64(base64KeyVal)); + } + + public static byte[] decryptByPublicKey(byte[] data, byte[] key) { + try { + return _INSTANCE.doDecryptByPublicKey(data, key); + } catch (InvalidKeyException | NoSuchAlgorithmException | InvalidKeySpecException | NoSuchPaddingException + | IllegalBlockSizeException | BadPaddingException e) { + throw new EncryptionException(e.getMessage()); + } + } + + public static byte[] encryptByPublicKey(byte[] data, String base64KeyVal){ + return encryptByPublicKey(data, decodeBase64(base64KeyVal)); + } + + public static byte[] encryptByPublicKey(byte[] data, byte[] key) { + try { + return _INSTANCE.doEncryptByPublicKey(data, key); + } catch (InvalidKeyException | NoSuchAlgorithmException | InvalidKeySpecException | NoSuchPaddingException + | IllegalBlockSizeException | BadPaddingException e) { + throw new EncryptionException(e.getMessage()); + } + } + + private byte[] doEncryptByPublicKey(byte[] data, byte[] key) + throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, + IllegalBlockSizeException, BadPaddingException { + initProvider(); + X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(key); + + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + + PublicKey publicKey = keyFactory.generatePublic(x509KeySpec); + + Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); + + cipher.init(Cipher.ENCRYPT_MODE, publicKey); + + return cipher.doFinal(data); + } + + private byte[] doDecryptByPublicKey(byte[] data, byte[] key) + throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, + IllegalBlockSizeException, BadPaddingException { + initProvider(); + X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(key); + + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + + PublicKey publicKey = keyFactory.generatePublic(x509KeySpec); + + Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); + + cipher.init(Cipher.DECRYPT_MODE, publicKey); + + return cipher.doFinal(data); + } + + private byte[] doEncryptByPrivateKey(byte[] data, byte[] key) + throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, + IllegalBlockSizeException, BadPaddingException { + initProvider(); + PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(key); + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + + PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec); + + Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); + + cipher.init(Cipher.ENCRYPT_MODE, privateKey); + + return cipher.doFinal(data); + } + + private byte[] doDecryptByPrivateKey(byte[] data, byte[] key) + throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, + IllegalBlockSizeException, BadPaddingException { + initProvider(); + PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(key); + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + + PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec); + + Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); + + cipher.init(Cipher.DECRYPT_MODE, privateKey); + + return cipher.doFinal(data); + + } + + private RsaKeyPair doInitKey() throws NoSuchAlgorithmException, UnsupportedEncodingException { + initProvider(); + KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); + keyPairGen.initialize(KEY_SIZE); + KeyPair keyPair = keyPairGen.generateKeyPair(); + + RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); + RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); + + RsaKeyPair aKeyPair = RsaKeyPairBuilder + .withPublicKey(encodeBase64String((publicKey.getEncoded()))) + .withPrivateKey(encodeBase64String(privateKey.getEncoded())).build(); + + return aKeyPair; + } + + private void initProvider() { + if (useExternalProvider && Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { + Security.addProvider(new BouncyCastleProvider()); + } + } + + +} diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyDetector.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyDetector.java new file mode 100644 index 000000000..87aecbd1a --- /dev/null +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyDetector.java @@ -0,0 +1,86 @@ +package com.webank.plugins.wecmdb.propenc; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author gavin + * + */ +public class RsaKeyDetector { + private static final Logger log = LoggerFactory.getLogger(RsaKeyDetector.class); + + + private File rsaKeyFile; + + public RsaKeyDetector() { + + } + + public RsaKeyDetector(String rasKeyFilePath) { + if (rasKeyFilePath == null || rasKeyFilePath.trim().length() < 1) { + rsaKeyFile = null; + return; + } + + rsaKeyFile = new File(rasKeyFilePath.trim()); + } + + public RsaKeyPair detectRsaKeyPair() { + return doDetectRsaKeyPair(); + } + + private RsaKeyPair doDetectRsaKeyPair() { + String rsaPrivKeyString = tryFindPrivateKeyFromExternal(); + if (StringUtils.isBlank(rsaPrivKeyString)) { + return null; + } + + return new RsaKeyPair(null, rsaPrivKeyString); + } + + private String tryFindPrivateKeyFromExternal() { + if (!this.rsaKeyFile.exists()) { + log.info("Private key does not exist,filepath={}", this.rsaKeyFile.getAbsolutePath()); + return null; + } + + try (FileInputStream input = new FileInputStream(rsaKeyFile)) { + return readInputStream(input); + } catch (IOException e) { + log.error("errors while reading private key", e); + String msg = String.format("Failed to read private key {%s}.", this.rsaKeyFile.getAbsolutePath()); + throw new EncryptionException(msg); + } + } + + private String readInputStream(InputStream inputStream) throws IOException { + + if (inputStream == null) { + throw new IllegalArgumentException(); + } + + BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, RsaEncryptor.DEF_CHARSET)); + String sLine = null; + StringBuilder content = new StringBuilder(); + while ((sLine = br.readLine()) != null) { + if (sLine.startsWith("-")) { + continue; + } + + content.append(sLine.trim()); + } + + return content.toString(); + } + +} diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyPair.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyPair.java new file mode 100644 index 000000000..9dd576ca0 --- /dev/null +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyPair.java @@ -0,0 +1,27 @@ +package com.webank.plugins.wecmdb.propenc; + +/** + * + * @author gavin + * + */ +public class RsaKeyPair { + + private final String privateKey; + + private final String publicKey; + + RsaKeyPair(String publicKey, String privateKey) { + super(); + this.privateKey = privateKey; + this.publicKey = publicKey; + } + + public String getPrivateKey() { + return privateKey; + } + + public String getPublicKey() { + return publicKey; + } +} diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyPairBuilder.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyPairBuilder.java new file mode 100644 index 000000000..b26b30ee5 --- /dev/null +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyPairBuilder.java @@ -0,0 +1,37 @@ +package com.webank.plugins.wecmdb.propenc; + +/** + * + * @author gavin + * + */ +public class RsaKeyPairBuilder { + + private String privateKey; + private String publicKey; + + public static RsaKeyPairBuilder withPublicKey(String publicKey) { + RsaKeyPairBuilder b = new RsaKeyPairBuilder(); + b.setPublicKey(publicKey); + + return b; + } + + public RsaKeyPairBuilder withPrivateKey(String privateKey) { + this.setPrivateKey(privateKey); + return this; + } + + public RsaKeyPair build() { + return new RsaKeyPair(this.publicKey, this.privateKey); + } + + private void setPrivateKey(String privateKey) { + this.privateKey = privateKey; + } + + private void setPublicKey(String publicKey) { + this.publicKey = publicKey; + } + +} diff --git a/cmdb-plugin/src/main/resources/application.yml b/cmdb-plugin/src/main/resources/application.yml index 960663b68..38958faf7 100644 --- a/cmdb-plugin/src/main/resources/application.yml +++ b/cmdb-plugin/src/main/resources/application.yml @@ -16,6 +16,7 @@ server: plugins: pacakge-name: wecmdb + property-encrypt-key-path:${PROPERTY_ENCRYPT_KEY_PATH:/data/certs/rsa_key} spring: banner: From e013f6970f6157892d2d4dd76221ddd690062e47 Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Thu, 15 Oct 2020 09:38:04 +0800 Subject: [PATCH 08/21] #1119 recommit --- .../java/com/webank/cmdb/service/testQueryReferenceData.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json b/cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json index 51e320b12..c83aec7f6 100644 --- a/cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json +++ b/cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json @@ -1,4 +1,5 @@ { + "filters": [], "paging": false, "dialect": { From eab5c3aee7209e18c04f3c430f7a420b478707c3 Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Thu, 15 Oct 2020 09:48:16 +0800 Subject: [PATCH 09/21] #1119 remove unused tests --- .../cmdb/service/UIWrapperServiceTests.java | 40 ----------------- .../cmdb/service/testQueryReferenceData.json | 43 ------------------- 2 files changed, 83 deletions(-) delete mode 100644 cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java delete mode 100644 cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json diff --git a/cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java b/cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java deleted file mode 100644 index 9460342fa..000000000 --- a/cmdb-core/src/test/java/com/webank/cmdb/service/UIWrapperServiceTests.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.webank.cmdb.service; - -import java.io.File; -import java.io.IOException; - -import org.apache.commons.io.FileUtils; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.webank.cmdb.controller.ui.helper.UIWrapperService; -import com.webank.cmdb.dto.QueryRequest; - -@Ignore -@RunWith(SpringRunner.class) -@SpringBootTest -public class UIWrapperServiceTests { - - String filename = "testQueryReferenceData.json"; - - @Autowired - private UIWrapperService wrapperService; - - @Test - public void testQueryReferenceData() throws IOException { - File inputFile = FileUtils.toFile(UIWrapperServiceTests.class.getResource(filename)); - String inputJson = FileUtils.readFileToString(inputFile); - - System.out.println("inputJson:"+inputJson); - int referenceAttrId = 933; - QueryRequest queryObject = new QueryRequest(); - Object result = wrapperService.queryReferenceCiData(referenceAttrId, queryObject); - - System.out.println("result:"+result); - } - -} diff --git a/cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json b/cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json deleted file mode 100644 index c83aec7f6..000000000 --- a/cmdb-core/src/test/java/com/webank/cmdb/service/testQueryReferenceData.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - - "filters": [], - "paging": false, - "dialect": { - "associatedData": { - "code": "demonginx01_IP3424:10001", - "deploy_package": "0045_0000000007", - "memory": "1", - "deploy_package_url": "", - "r_guid": "0050_0000000015", - "monitor_port": "10001", - "description": "", - "deploy_user_password": "******", - "storage": "20", - "host_resource_instance": "0032_0000000021", - "rw_dir": "", - "start_script": "/data/PRD_TaDEMO_PROXY_NGINX/demo-app-nginx_0.1.1/bin/start.sh", - "monitor_key_name": "IP3424:10001", - "port_conflict": "IP3424:10001", - "state": 40, - "fixed_date": "2020-09-01 17:30:04", - "deploy_script": "/data/PRD_TaDEMO_PROXY_NGINX/demo-app-nginx_0.1.1/bin/deploy.sh", - "deploy_user": "root", - "stop_script": "/data/PRD_TaDEMO_PROXY_NGINX/demo-app-nginx_0.1.1/bin/stop.sh", - "app_log_files": "", - "cpu": "1", - "created_by": "umadmin", - "key_name": "demonginx01_IP3424:10001", - "p_guid": null, - "unit": "0048_0000000020", - "port": "10001", - "rw_file": "", - "variable_values": "port,\u0001backend_server_ip_1,\u0001backend_server_port_1,\u0001backend_server_ip_2,\u0001backend_server_port_2,\u0001context_path\u0001=\u0001,\u0001IP9754,\u000110001,\u0001IP3675,\u000110001,\u0001~*^.+$", - "name": "demonginx01", - "updated_by": null, - "guid": "0050_0000000015", - "created_date": "2020-05-22 16:30:47", - "updated_date": null, - "state_code": "created" - } - } -} \ No newline at end of file From e7000433845bc4dc85f9fd1e5387941484b87846 Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Thu, 15 Oct 2020 10:17:13 +0800 Subject: [PATCH 10/21] #1119 remove unused test --- .../ui/helper/UIWrapperServiceTest.java | 50 ------------------- 1 file changed, 50 deletions(-) delete mode 100644 cmdb-core/src/test/java/com/webank/cmdb/controller/ui/helper/UIWrapperServiceTest.java diff --git a/cmdb-core/src/test/java/com/webank/cmdb/controller/ui/helper/UIWrapperServiceTest.java b/cmdb-core/src/test/java/com/webank/cmdb/controller/ui/helper/UIWrapperServiceTest.java deleted file mode 100644 index 690cc3a7f..000000000 --- a/cmdb-core/src/test/java/com/webank/cmdb/controller/ui/helper/UIWrapperServiceTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.webank.cmdb.controller.ui.helper; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.webank.cmdb.dto.CiData; -import com.webank.cmdb.dto.QueryRequest; -import com.webank.cmdb.dto.QueryResponse; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class UIWrapperServiceTest { - - @Autowired - private UIWrapperService uiWrapperService; - - @Test - public void test_queryCiDataByType() { - Integer ciTypeId = 32; - QueryRequest queryObject = new QueryRequest(); - QueryResponse response = uiWrapperService.queryCiData( ciTypeId, queryObject); - - System.out.println(response.getContents().size()); - } - - @Test - public void test_updateCiData(){ - - Integer ciTypeId = 32; - List> ciDatas = new ArrayList<>(); - Map ciData = new HashMap<>(); - ciData.put("guid", "0032_0000000002"); - ciData.put("description", "test"); - - ciDatas.add(ciData); - - List> result = uiWrapperService.updateCiData( ciTypeId, ciDatas); - - System.out.println(result); - } - -} From e145f243482c239be979328e74cb378f036a3d99 Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Thu, 15 Oct 2020 11:34:16 +0800 Subject: [PATCH 11/21] #1119 change log path --- cmdb-core/src/main/resources/logback-spring.xml | 2 +- cmdb-plugin/src/main/resources/logback-spring.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmdb-core/src/main/resources/logback-spring.xml b/cmdb-core/src/main/resources/logback-spring.xml index c8964e136..4ff4fd1b7 100644 --- a/cmdb-core/src/main/resources/logback-spring.xml +++ b/cmdb-core/src/main/resources/logback-spring.xml @@ -1,7 +1,7 @@ - + diff --git a/cmdb-plugin/src/main/resources/logback-spring.xml b/cmdb-plugin/src/main/resources/logback-spring.xml index 2c2878281..28197fe00 100644 --- a/cmdb-plugin/src/main/resources/logback-spring.xml +++ b/cmdb-plugin/src/main/resources/logback-spring.xml @@ -1,7 +1,7 @@ - + From 73c38de0a99c76cb48507ce5906cfba5c8581619 Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Thu, 15 Oct 2020 11:53:41 +0800 Subject: [PATCH 12/21] #1119 add test log config --- .../src/main/resources/logback-spring.xml | 2 +- .../src/test/resources/logback-spring.xml | 44 +++++++++++++++++++ .../src/main/resources/logback-spring.xml | 2 +- .../src/test/resources/logback-spring.xml | 44 +++++++++++++++++++ 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 cmdb-core/src/test/resources/logback-spring.xml create mode 100644 cmdb-plugin/src/test/resources/logback-spring.xml diff --git a/cmdb-core/src/main/resources/logback-spring.xml b/cmdb-core/src/main/resources/logback-spring.xml index 4ff4fd1b7..c8964e136 100644 --- a/cmdb-core/src/main/resources/logback-spring.xml +++ b/cmdb-core/src/main/resources/logback-spring.xml @@ -1,7 +1,7 @@ - + diff --git a/cmdb-core/src/test/resources/logback-spring.xml b/cmdb-core/src/test/resources/logback-spring.xml new file mode 100644 index 000000000..4ff4fd1b7 --- /dev/null +++ b/cmdb-core/src/test/resources/logback-spring.xml @@ -0,0 +1,44 @@ + + + + + + + + true + + + + + + + %d{yyyy-MM-dd HH:mm:ss} %-5level %-48logger{48} - %msg%n + + + + + + ${logPath}/${logFile}.log + + ${logPath}/${logFile}-%d{yyyyMMdd}.log + + true + 30 + + + + + + UTF-8 + + + + + + + + diff --git a/cmdb-plugin/src/main/resources/logback-spring.xml b/cmdb-plugin/src/main/resources/logback-spring.xml index 28197fe00..2c2878281 100644 --- a/cmdb-plugin/src/main/resources/logback-spring.xml +++ b/cmdb-plugin/src/main/resources/logback-spring.xml @@ -1,7 +1,7 @@ - + diff --git a/cmdb-plugin/src/test/resources/logback-spring.xml b/cmdb-plugin/src/test/resources/logback-spring.xml new file mode 100644 index 000000000..28197fe00 --- /dev/null +++ b/cmdb-plugin/src/test/resources/logback-spring.xml @@ -0,0 +1,44 @@ + + + + + + + + true + + + + + + + %d{yyyy-MM-dd HH:mm:ss} %-5level %-48logger{48} - %msg%n + + + + + + ${logPath}/${logFile}.log + + ${logPath}/${logFile}-%d{yyyyMMdd}.log + + true + 30 + + + + + + UTF-8 + + + + + + + + + From ff45c957acdbb85ff17b3606ec7ec811e4f6fdfe Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Thu, 15 Oct 2020 11:56:17 +0800 Subject: [PATCH 13/21] #1119 rename log config file --- .../resources/{logback-spring.xml => logback-test-spring.xml} | 0 .../resources/{logback-spring.xml => logback-test-spring.xml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename cmdb-core/src/test/resources/{logback-spring.xml => logback-test-spring.xml} (100%) rename cmdb-plugin/src/test/resources/{logback-spring.xml => logback-test-spring.xml} (100%) diff --git a/cmdb-core/src/test/resources/logback-spring.xml b/cmdb-core/src/test/resources/logback-test-spring.xml similarity index 100% rename from cmdb-core/src/test/resources/logback-spring.xml rename to cmdb-core/src/test/resources/logback-test-spring.xml diff --git a/cmdb-plugin/src/test/resources/logback-spring.xml b/cmdb-plugin/src/test/resources/logback-test-spring.xml similarity index 100% rename from cmdb-plugin/src/test/resources/logback-spring.xml rename to cmdb-plugin/src/test/resources/logback-test-spring.xml From d4ba349e9f5f28e4f6ef451fddd2054f9f709ea1 Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Thu, 15 Oct 2020 16:01:31 +0800 Subject: [PATCH 14/21] #1142 fix prop enc issue --- .../src/main/java/com/webank/plugins/wecmdb/Application.java | 5 +++-- .../com/webank/plugins/wecmdb/propenc/RsaKeyDetector.java | 1 + .../webank/plugins/wecmdb/service/WecubeAdapterService.java | 2 -- cmdb-plugin/src/main/resources/application.yml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/Application.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/Application.java index c8f193b63..0b5b941d5 100644 --- a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/Application.java +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/Application.java @@ -14,14 +14,15 @@ import com.webank.cmdb.config.DatabaseConfig; import com.webank.cmdb.config.SpringAppConfig; import com.webank.cmdb.config.SpringWebConfig; +import com.webank.plugins.wecmdb.config.PluginApplicationProperties; import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication @EnableSwagger2 -@EnableConfigurationProperties({ApplicationProperties.class}) +@EnableConfigurationProperties({PluginApplicationProperties.class,ApplicationProperties.class}) @EnableEncryptableProperties -@ComponentScan({ "com.webank.plugins.wecmdb.service", "com.webank.plugins.wecmdb.controller", "com.webank.plugins.wecmdb.mvc", "com.webank.cmdb.config", "com.webank.cmdb.repository" }) +@ComponentScan({ "com.webank.plugins.wecmdb.propenc", "com.webank.plugins.wecmdb.service", "com.webank.plugins.wecmdb.controller", "com.webank.plugins.wecmdb.mvc", "com.webank.cmdb.config", "com.webank.cmdb.repository" }) @Import({ DatabaseConfig.class }) public class Application extends AbstractAnnotationConfigDispatcherServletInitializer { diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyDetector.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyDetector.java index 87aecbd1a..9a997af59 100644 --- a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyDetector.java +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/propenc/RsaKeyDetector.java @@ -27,6 +27,7 @@ public RsaKeyDetector() { } public RsaKeyDetector(String rasKeyFilePath) { + log.info("init {} with {}", RsaKeyDetector.class.getSimpleName(), rasKeyFilePath); if (rasKeyFilePath == null || rasKeyFilePath.trim().length() < 1) { rsaKeyFile = null; return; diff --git a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java index f515d6452..d50b381a7 100644 --- a/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java +++ b/cmdb-plugin/src/main/java/com/webank/plugins/wecmdb/service/WecubeAdapterService.java @@ -82,7 +82,6 @@ public QueryResponse queryCiTypeAttrs(QueryRequest queryObject) { return staticDtoService.query(CiTypeAttrDto.class, queryObject); } - @Transactional public List> confirmBatchCiData(List operateCiDtos, List exceptionHolders) { List> results = new ArrayList<>(); operateCiDtos.forEach(operateCiDto -> { @@ -396,7 +395,6 @@ public List> updateCiData(String entityName, List> updateCiDataByGuid(List operateCiDataUpdateDtos, List exceptionHolders){ List> results = new ArrayList<>(); operateCiDataUpdateDtos.forEach(operateCiDataUpdateDto -> { diff --git a/cmdb-plugin/src/main/resources/application.yml b/cmdb-plugin/src/main/resources/application.yml index ed9980210..0bbe942ad 100644 --- a/cmdb-plugin/src/main/resources/application.yml +++ b/cmdb-plugin/src/main/resources/application.yml @@ -16,7 +16,7 @@ server: plugins: pacakge-name: wecmdb - property-encrypt-key-path:${PROPERTY_ENCRYPT_KEY_PATH:/data/certs/rsa_key} + property-encrypt-key-path: ${PROPERTY_ENCRYPT_KEY_PATH:/data/certs/rsa_key} spring: banner: From 170c1c80608e7031b935a3b00f4d5dcfc7d7f80f Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Fri, 16 Oct 2020 14:18:29 +0800 Subject: [PATCH 15/21] #1142 add volume bindings --- cmdb-plugin/register.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdb-plugin/register.xml b/cmdb-plugin/register.xml index 003916683..81a699589 100644 --- a/cmdb-plugin/register.xml +++ b/cmdb-plugin/register.xml @@ -60,7 +60,7 @@ - + From 2a24b75d02adb8bc0af6234d8eb624ba4126b163 Mon Sep 17 00:00:00 2001 From: gavin2lee Date: Sat, 17 Oct 2020 11:23:47 +0800 Subject: [PATCH 16/21] commented logger appender --- cmdb-plugin/src/main/resources/logback-spring.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmdb-plugin/src/main/resources/logback-spring.xml b/cmdb-plugin/src/main/resources/logback-spring.xml index 2c2878281..561486108 100644 --- a/cmdb-plugin/src/main/resources/logback-spring.xml +++ b/cmdb-plugin/src/main/resources/logback-spring.xml @@ -36,8 +36,9 @@ + From 0c9e88c60d4b9ac98ac311b39b8bb7f79f500218 Mon Sep 17 00:00:00 2001 From: homiexie <624128114@qq.com> Date: Tue, 20 Oct 2020 10:05:56 +0800 Subject: [PATCH 17/21] enhance for ci data --- cmdb-ui/src/pages/designing/ci-data.vue | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmdb-ui/src/pages/designing/ci-data.vue b/cmdb-ui/src/pages/designing/ci-data.vue index ffdb06abc..aef4eca3b 100755 --- a/cmdb-ui/src/pages/designing/ci-data.vue +++ b/cmdb-ui/src/pages/designing/ci-data.vue @@ -1,5 +1,5 @@