Merge branch 'feature/join_elk/221031' into 'dev'

add appkey&secret config

See merge request infra/axzo-log-plat!82
This commit is contained in:
彭健 2022-11-04 02:36:41 +00:00
commit 267b445a37
3 changed files with 40 additions and 20 deletions

View File

@ -22,46 +22,49 @@ public class LogSinkELKReqDTO {
@NotNull(message = "服务名不可为空")
private String serviceName;
@ApiModelProperty(value = "url信息", position = 2)
@ApiModelProperty(value = "日志等级(INFO、ERROR、WARNING)", position = 2)
private String level;
@ApiModelProperty(value = "url信息", position = 3)
private String url;
@ApiModelProperty(value = "内容摘要", position = 3)
@ApiModelProperty(value = "内容摘要", position = 4)
private String content;
@ApiModelProperty(value = "操作前数据", position = 4)
@ApiModelProperty(value = "操作前数据", position = 5)
private String operateBefore;
@ApiModelProperty(value = "操作后数据", position = 5)
@ApiModelProperty(value = "操作后数据", position = 6)
private String operateAfter;
@ApiModelProperty(value = "发生时间(时间戳)", required = true, position = 6, example = "1667211066490")
@ApiModelProperty(value = "发生时间(时间戳)", required = true, position = 7, example = "1667211066490")
@NotNull(message = "操作时间不能为空")
private Long operateTime;
@ApiModelProperty(value = "结束时间(时间戳)", position = 7, example = "1667211066490")
@ApiModelProperty(value = "结束时间(时间戳)", position = 8, example = "1667211066490")
private Long operateEndTime;
@ApiModelProperty(value = "工作台Id", position = 8)
@ApiModelProperty(value = "工作台Id", position = 9)
private Long workspaceId;
@ApiModelProperty(value = "设备号", position = 9)
@ApiModelProperty(value = "设备号", position = 10)
private String sn;
@ApiModelProperty(value = "描述信息", position = 10)
@ApiModelProperty(value = "描述信息", position = 11)
private String desc;
@ApiModelProperty(value = "用户信息", position = 11)
@ApiModelProperty(value = "用户信息", position = 12)
private String userInfo;
@ApiModelProperty(value = "重试次数", position = 12)
@ApiModelProperty(value = "重试次数", position = 13)
private int retryNum;
@ApiModelProperty(value = "扩展 map", position = 13)
@ApiModelProperty(value = "扩展 map", position = 14)
private Map<String, String> extValMap;
@ApiModelProperty(value = "扩展字符串", position = 14)
@ApiModelProperty(value = "扩展字符串", position = 15)
private String logExt;
@ApiModelProperty(value = "签名", position = 14)
@ApiModelProperty(value = "签名", position = 16)
private transient String sign;
}

View File

@ -5,6 +5,7 @@ import cn.axzo.log.platform.server.exception.BizException;
import cn.axzo.log.platform.server.service.LogSinkELKService;
import cn.axzo.log.platform.server.utils.JacksonCodecUtil;
import cn.axzo.log.platform.server.utils.SignUtil;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.kafka.clients.producer.Callback;
import org.apache.kafka.clients.producer.KafkaProducer;
@ -15,8 +16,11 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
/***
@ -28,9 +32,7 @@ import java.util.concurrent.ExecutionException;
public class LogSinkELKServiceImpl implements LogSinkELKService {
private final Logger logger = LoggerFactory.getLogger(LogSinkELKServiceImpl.class);
private final String SECRET_KEY = "aEsva0zDHECg47P8SuPzmw==";
@Autowired
private KafkaProducer<String, String> kafkaProducer;
@ -40,6 +42,16 @@ public class LogSinkELKServiceImpl implements LogSinkELKService {
@Value("${log-plat.kafka.send.async:false}")
private Boolean isAsync;
private Map<String, String> appKeyConfigMap = new HashMap<>();
@Value("${log-plat.sign.keysecret.config}")
public void setAppKeyConfigMap(String appKeyConfig) {
Map<String, String> configMap = JSONObject.parseObject(appKeyConfig, Map.class);
if (configMap != null) {
this.appKeyConfigMap = configMap;
}
}
@Override
public void sinkELk(LogSinkELKReqDTO req) throws BizException, ExecutionException, InterruptedException, JsonProcessingException {
//解密 && 转换
@ -55,7 +67,6 @@ public class LogSinkELKServiceImpl implements LogSinkELKService {
/**
* 解密和转换对象
* <p>
* 思来想去还是原汤对原食怎么来的怎么走.
*
* @param req
* @return
@ -63,10 +74,15 @@ public class LogSinkELKServiceImpl implements LogSinkELKService {
*/
private String signAndConvert(LogSinkELKReqDTO req) throws BizException {
try {
//根据 serviceName 获取到 appKey appSecret
String secretKey = appKeyConfigMap.get(req.getServiceName());
if (!StringUtils.hasText(secretKey)) {
throw new BizException("can not find service config");
}
LinkedHashMap<String, String> paramsMap = new LinkedHashMap<>();
paramsMap.put("serviceName", req.getServiceName());
paramsMap.put("operateTime", Long.toString(req.getOperateTime()));
paramsMap.put("secretKey", SECRET_KEY);
paramsMap.put("secretKey", secretKey);
String sign = SignUtil.signParamsMd5(paramsMap);
if (!req.getSign().equals(sign)) {
logger.warn("request sign is illegal,request sign={},server sign={}.", req.getSign(), sign);

View File

@ -33,11 +33,12 @@ public class AESServiceTest {
// testMD5();
LinkedHashMap<String, String> allParams = new LinkedHashMap<>();
allParams.put("serviceName", "panel_facelog");
allParams.put("operateTime", "1667211066490");
allParams.put("operateTime", "1667296795232");
allParams.put("secretKey", "aEsva0zDHECg47P8SuPzmw==");
System.out.println(SignUtil.signParamsMd5(allParams));
}
public static void testSign() {
LinkedHashMap<String, Object> allParams = new LinkedHashMap<>();
allParams.put("serviceName", "panel_facelog");