【FEATURE】针对nacos增加阿里云MSE的鉴权方式 https://gitee.com/dromara/liteFlow/issues/I8H1LT

This commit is contained in:
韩华锋 2023-11-22 11:37:35 +08:00
parent 412b8a81fe
commit 2d250c4d0e
3 changed files with 62 additions and 12 deletions

View File

@ -60,6 +60,12 @@ public class NacosXmlELParser extends ClassXmlFlowELParser {
if (StrUtil.isBlank(nacosParserVO.getPassword())) {
nacosParserVO.setPassword("");
}
if (StrUtil.isBlank(nacosParserVO.getAccessKey())){
nacosParserVO.setAccessKey("");
}
if (StrUtil.isBlank(nacosParserVO.getSecretKey())){
nacosParserVO.setSecretKey("");
}
helper = new NacosParserHelper(nacosParserVO);
}
catch (Exception e) {

View File

@ -11,7 +11,6 @@ import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.MessageFormat;
import java.util.Properties;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
@ -40,12 +39,8 @@ public class NacosParserHelper {
catch (Exception ignored) {
}
if (this.configService == null) {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, nacosParserVO.getServerAddr());
properties.put(PropertyKeyConst.NAMESPACE, nacosParserVO.getNamespace());
properties.put(PropertyKeyConst.USERNAME, nacosParserVO.getUsername());
properties.put(PropertyKeyConst.PASSWORD, nacosParserVO.getPassword());
this.configService = new NacosConfigService(properties);
Properties properties = getProperties(nacosParserVO);
this.configService = new NacosConfigService(properties);
}
}
catch (Exception e) {
@ -53,6 +48,29 @@ public class NacosParserHelper {
}
}
private static Properties getProperties(NacosParserVO nacosParserVO) {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, nacosParserVO.getServerAddr());
properties.put(PropertyKeyConst.NAMESPACE, nacosParserVO.getNamespace());
if (StrUtil.isNotEmpty(nacosParserVO.getUsername())) {
// 用户名密码模式 填写用户名就必有密码
if (StrUtil.isEmpty(PropertyKeyConst.PASSWORD)){
throw new NacosException("Nacos config password is empty");
}
// 历史版本会使用用户名密码
properties.put(PropertyKeyConst.USERNAME, nacosParserVO.getUsername());
properties.put(PropertyKeyConst.PASSWORD, nacosParserVO.getPassword());
} else if (StrUtil.isNotEmpty(PropertyKeyConst.ACCESS_KEY)){
// 以下为阿里云RAM子账号使用 填写了ak就必有sk
if (StrUtil.isEmpty(PropertyKeyConst.SECRET_KEY)){
throw new NacosException("Nacos config secretKey is empty");
}
properties.put(PropertyKeyConst.ACCESS_KEY, nacosParserVO.getAccessKey());
properties.put(PropertyKeyConst.SECRET_KEY, nacosParserVO.getSecretKey());
}
return properties;
}
public String getContent() {
try {
return configService.getConfig(nacosParserVO.getDataId(), nacosParserVO.getGroup(), 3000L);

View File

@ -16,6 +16,10 @@ public class NacosParserVO {
private String group;
private String accessKey;
private String secretKey;
private String username;
private String password;
@ -68,11 +72,33 @@ public class NacosParserVO {
this.password = password;
}
@Override
public String toString() {
return "NacosParserVO{" + "serverAddr='" + serverAddr + '\'' + ", namespace='" + namespace + '\'' + ", dataId='"
+ dataId + '\'' + ", group='" + group + '\'' + ", username='" + username + '\'' + ", password='"
+ password + '\'' + '}';
public String getAccessKey() {
return accessKey;
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
@Override
public String toString() {
return "NacosParserVO{" +
"serverAddr='" + serverAddr + '\'' +
", namespace='" + namespace + '\'' +
", dataId='" + dataId + '\'' +
", group='" + group + '\'' +
", accessKey='" + accessKey + '\'' +
", secretKey='" + secretKey + '\'' +
", username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}