Skip to content

Commit

Permalink
Merge pull request #504 from WeBankBlockchain/lab-dev
Browse files Browse the repository at this point in the history
merge 3.1.0 master
  • Loading branch information
CodingCattwo authored Jul 24, 2023
2 parents dc67947 + d7b33ec commit bd17401
Show file tree
Hide file tree
Showing 23 changed files with 626 additions and 119 deletions.
16 changes: 16 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
### v3.1.0(2023-07-20)

**Add**
- 支持合约IDE的Java项目导出功能,并支持struct格式参数,需要使用3.1.0及以上的WeBASE-Web

**Fix**
- 修复WeBASE-APP-SDK应用管理接入时无法通过健全问题;需要对应使用`webase-app-sdk` 1.5.6及以上版本

**兼容性**
- 支持FISCO-BCOS v3.0.0 及以上版本
- WeBASE-Web v3.0.2及以上版本
- WeBASE-Front v3.1.0
- WeBASE-APP-SDK v1.5.6级以上版本

详细了解,请阅读[**技术文档**](https://webasedoc.readthedocs.io/zh_CN/lab/)

### v3.0.2(2023-03-31)

**Fix**
Expand Down
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ List mbg = [
]

List scaffold = [
'com.webank.webase:solscaffold:1.0.2',
'com.webank:SmartDev-Scaffold:1.0.0.1',
'com.webank:solc-gradle-plugin:1.0.1'
'com.webank.webase:solscaffold:3.3.0-SNAPSHOT',
'com.webank:WeBankBlockchain-SmartDev-Scaffold:3.3.0-SNAPSHOT',
'com.webank:solc-gradle-plugin:3.3.0-SNAPSHOT'
]

List swagger = [
Expand All @@ -103,7 +103,7 @@ List commons = [

dependencies {
compile springboot,jaxb,jackson,log4j,scaffold,swagger,commons
compile ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:3.3.0-SNAPSHOT') {
compile ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:3.3.0') {
exclude group: "org.slf4j"
}
runtime "mysql:mysql-connector-java:8.0.28"
Expand All @@ -123,6 +123,7 @@ dependencies {
compileOnly lombok
annotationProcessor lombok

testCompile ("com.webank:webase-app-sdk:1.5.5")
testCompile mbg
testCompileOnly lombok
testAnnotationProcessor lombok
Expand All @@ -140,6 +141,8 @@ configurations {
all*.exclude group: 'jline', module: 'jline'
all*.exclude group: 'com.google.protobuf', module: 'protobuf-java'
all*.exclude group: 'javax.annotation', module: 'javax.annotation-api'
all*.exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'

}

sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@
import java.util.Optional;
import javax.validation.Valid;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.fisco.bcos.sdk.v3.client.Client;
import org.fisco.bcos.sdk.v3.client.protocol.response.BcosGroupNodeInfo.GroupNodeInfo;
import org.fisco.bcos.sdk.v3.config.ConfigOption;
import org.fisco.bcos.sdk.v3.crypto.CryptoSuite;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -231,8 +234,10 @@ public BaseResponse updatePassword(@RequestBody @Valid UpdatePasswordInfo info,
public BaseResponse getBasicInfo(@RequestParam(required = true) String groupId) {
BasicInfo basicInfo = new BasicInfo();
basicInfo.setEncryptType(frontInterfaceService.getCryptoType(groupId));
basicInfo.setSslCryptoType(frontInterfaceService.getSSLCryptoType());
basicInfo.setFiscoBcosVersion(frontInterfaceService.getClientVersion().getVersion());
// 此处每个front的 useSmssl 可能不一致,但是由于获取basicInfo,不指定front的Ip,随机取一个front获取
basicInfo.setSslCryptoType(frontInterfaceService.getUseSmSsl(groupId) ? 1 : 0);
// 此处每个节点的binaryVersion可能不一致,但是由于获取basicInfo,默认取第一个
basicInfo.setFiscoBcosVersion(frontInterfaceService.getOneNodeBinaryVersion(groupId));
basicInfo.setWebaseVersion(versionProperties.getVersion());
log.info("getBasicInfo:{}", JsonTools.toJSONString(basicInfo));
return new BaseResponse(ConstantCode.SUCCESS, basicInfo);
Expand All @@ -241,7 +246,6 @@ public BaseResponse getBasicInfo(@RequestParam(required = true) String groupId)
/**
* get encrypt type.
*/
@Deprecated
@GetMapping("encrypt")
public BaseResponse getEncryptType(@RequestParam(required = true) String groupId) {
int encrypt = frontInterfaceService.getCryptoType(groupId);
Expand Down Expand Up @@ -329,7 +333,7 @@ public BaseResponse getNodeInfo(@RequestParam(required = true) String groupId,
@RequestParam(required = true) String nodeId) throws NodeMgrException {

Instant startTime = Instant.now();
log.info("start addNodeInfo startTime:{} groupId:{}", startTime.toEpochMilli(), groupId);
log.info("start getNodeInfo startTime:{} groupId:{}", startTime.toEpochMilli(), groupId);

// param
NodeParam param = new NodeParam();
Expand All @@ -342,7 +346,7 @@ public BaseResponse getNodeInfo(@RequestParam(required = true) String groupId,
BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS);
baseResponse.setData(tbNode);

log.info("end addNodeInfo useTime:{} result:{}",
log.info("end getNodeInfo useTime:{} result:{}",
Duration.between(startTime, Instant.now()).toMillis(),
JsonTools.toJSONString(baseResponse));
return baseResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.webank.webase.node.mgr.config;

import com.webank.webase.node.mgr.base.annotation.CurrentAccountMethodArgumentResolver;
import com.webank.webase.node.mgr.config.properties.ConstantProperties;
import com.webank.webase.node.mgr.config.security.filter.AccountFilter;
import com.webank.webase.node.mgr.config.security.filter.AppIntegrationFilter;
import com.webank.webase.node.mgr.config.properties.ConstantProperties;
import com.webank.webase.node.mgr.tools.JsonTools;
import java.util.List;
import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand All @@ -18,6 +20,7 @@
* web configuration.
*
*/
@Log4j2
@Data
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
Expand All @@ -29,20 +32,19 @@ public class WebMvcConfig implements WebMvcConfigurer {
private AppIntegrationFilter appIntegrationFilter;
@Autowired
private ConstantProperties constants;

@Bean
public AccountFilter setAccountFilter() {
return new AccountFilter();
}
@Autowired
private AccountFilter accountFilter;

/**
* 注册拦截器
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(appIntegrationFilter).addPathPatterns("/api/**");// 自定义拦截的url路径
registry.addInterceptor(setAccountFilter()).addPathPatterns("/**")
log.info("addInterceptors for /api/**");
registry.addInterceptor(accountFilter).addPathPatterns("/**")
.excludePathPatterns(constants.getPermitUrlArray());
log.info("addInterceptors for {}", JsonTools.toJSONString(constants.getPermitUrlArray()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public class ConstantProperties {
private long execAddNodeTimeout = 40 * 1000L;

private String[] permitUrlArray = new String[]{"/account/login", "/account/pictureCheckCode",
"/login","/user/privateKey/**", "/encrypt", "/version" };
"/login","/user/privateKey/**", "/encrypt", "/version", "/api/**" };
private String dockerRepository= "fiscoorg/fisco-webase";
// private String imageTagUpdateUrl = "https://registry.hub.docker.com/v1/repositories/%s/tags";
private String dockerRegistryMirror = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* Copyright 2014-2020 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package com.webank.webase.node.mgr.contract.scaffold;

import com.webank.webase.node.mgr.base.code.ConstantCode;
import com.webank.webase.node.mgr.base.controller.BaseController;
import com.webank.webase.node.mgr.base.entity.BaseResponse;
import com.webank.webase.node.mgr.base.exception.NodeMgrException;
import com.webank.webase.node.mgr.config.properties.ConstantProperties;
import com.webank.webase.node.mgr.contract.scaffold.entity.ReqProject;
import com.webank.webase.node.mgr.contract.scaffold.entity.RspFile;
import com.webank.webase.node.mgr.tools.IPUtil;
import com.webank.webase.node.mgr.tools.NodeMgrTools;
import com.webank.webase.node.mgr.tools.ValidateUtil;
import java.time.Duration;
import java.time.Instant;
import javax.validation.Valid;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* @author marsli
*/
@Log4j2
@RestController
@RequestMapping(value = "scaffold")
public class ScaffoldController extends BaseController {
@Autowired
private ScaffoldService scaffoldService;

@PostMapping("/export")
@PreAuthorize(ConstantProperties.HAS_ROLE_ADMIN_OR_DEVELOPER)
public BaseResponse exportProjectApi(@Valid @RequestBody ReqProject param) {
Instant startTime = Instant.now();
log.info("start exportProjectApi param:{} groupId:{}", startTime.toEpochMilli(),
param);
if (StringUtils.isBlank(param.getChannelIp())) {
param.setChannelIp(IPUtil.LOCAL_IP_127);
}
// check artifact name and group name
if (!NodeMgrTools.startWithLetter(param.getArtifactName())) {
log.error("must start with letter");
throw new NodeMgrException(ConstantCode.PARAM_INVALID_LETTER_DIGIT);
}
// validate group name, ex: org.example
if (!param.getGroup().contains(".")) {
// only org
if (!NodeMgrTools.startWithLetter(param.getGroup())) {
log.error("group must start with letter");
throw new NodeMgrException(ConstantCode.PARAM_INVALID_LETTER_DIGIT);
}
} else {
// include org.xxx
String[] groupNameArray = param.getGroup().split("\\.");
for (String group: groupNameArray) {
// not start or end with dot "."
if (StringUtils.isBlank(group)) {
log.error("group must start with letter, and not end with dot");
throw new NodeMgrException(ConstantCode.PARAM_INVALID_LETTER_DIGIT);
}
if (!NodeMgrTools.startWithLetter(group)) {
log.error("group name must start with letter");
throw new NodeMgrException(ConstantCode.PARAM_INVALID_LETTER_DIGIT);
}
}
}
RspFile rspFile = scaffoldService.exportProject(param);
log.info("end exportProjectApi useTime:{} result:{}",
Duration.between(startTime, Instant.now()).toMillis(), rspFile);
return new BaseResponse(ConstantCode.SUCCESS, rspFile);
}


@GetMapping("/check")
public BaseResponse checkChannelPort(@RequestParam("nodeIp") String nodeIp,
@RequestParam("channelPort") int channelPort) {
Instant startTime = Instant.now();
log.info("start checkChannelPort startTime:{}, nodeIp:{} channelPort:{}",
startTime.toEpochMilli(), nodeIp, channelPort);
if(!ValidateUtil.ipv4Valid(nodeIp)) {
log.error("not valid nodeIp:{}", nodeIp);
throw new NodeMgrException(ConstantCode.IP_FORMAT_ERROR);
}
Boolean result = scaffoldService.telnetChannelPort(nodeIp, channelPort);

log.info("end exportProjectApi useTime:{} result:{}",
Duration.between(startTime, Instant.now()).toMillis(), result);
return new BaseResponse(ConstantCode.SUCCESS, result);
}
}
Loading

0 comments on commit bd17401

Please sign in to comment.