Skip to content

Commit

Permalink
Merge pull request #31 from HuaTru/dev
Browse files Browse the repository at this point in the history
修改dockerfile环境变量默认值 添加日志处理 docker-compose.yml添加注释
  • Loading branch information
smilexizheng authored Mar 20, 2024
2 parents f29986f + a581fe6 commit 4db1d14
Show file tree
Hide file tree
Showing 8 changed files with 503 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ENV COCO_EXPIRATION_TTL=5 \
COCO_BASE_PROXY="" \
COCO_FREQUENCY_TIME=1 \
COCO_FREQUENCY_DEGREE=8 \
COCO_USER_RATE_TIME=5 \
COCO_USER_RATE_TIME=1 \
COCO_USER_FREQUENCY_DEGREE=10 \
COCO_USER_TOKEN_EXPIRE=1 \
COCO_USER_LEVEL=2 \
Expand Down
28 changes: 25 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,53 @@ services:
ports:
- "8181:8181"
environment:
# coco配置
# 请求L站 state 过期时间 分钟
COCO_EXPIRATION_TTL: "5"
# L站 oauth2认证重定向地址
COCO_REDIRECT_URI: ""
# L站 oauth2认证客户端id
COCO_CLIENT_ID: ""
# L站 oauth2认证客户端secret
COCO_CLIENT_SECRET: ""
# L站 oauth2认证地址
COCO_AUTHORIZATION_ENDPOINT: ""
# L站 oauth2认证token地址
COCO_TOKEN_ENDPOINT: ""
# L站 oauth2认证用户信息地址
COCO_USER_ENDPOINT: ""
# 代理节点 完整地址
COCO_BASE_API: ""
# 代理节点
COCO_BASE_PROXY: ""
# ghu 频率秒 1秒8次
COCO_FREQUENCY_TIME: "1"
# ghu频率数
COCO_FREQUENCY_DEGREE: "8"
COCO_USER_RATE_TIME: "5"
# 用户基础频率 1分钟10次
COCO_USER_RATE_TIME: "1"
# 用户基础频率数
COCO_USER_FREQUENCY_DEGREE: "10"
# 用户token 有效期无请求接口 小时
COCO_USER_TOKEN_EXPIRE: "1"
# 允许用户的最低等级等级
COCO_USER_LEVEL: "2"
# 风控参数
# 一个账号 一天能获取多少次Token
RISK_CONTR_GET_TOKEN_NUM: "10"
# 单token 成功请求的最大数量 * 倍率 token失效
RISK_CONTR_TOKEN_MAX_REQ: "500"
# 每天用户最大请求数量 *倍率 限制 10小时 不可登陆
RISK_CONTR_USER_MAX_REQ: "2000"
RISK_CONTR_USER_MAX_TIME: "10"
# 用户最大访问速率
# 10次 该用户访问频率为 基础 * 0.5倍
RISK_CONTR_TOKEN_INVALID_NUM: "10"
# 30次 token失效 2小时不可登陆
RISK_CONTR_REJECT_TIME_NUM: "30"
RISK_CONTR_REJECT_TIME: "2"
# ban 5次 5次不可登陆
RISK_CONTR_BAN_NUM: "5"
volumes:
- ./src/main/resources/redisson-config.yml:/app/conf/redisson-config.yml:rw

redis:
image: redis
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.coco.boot.config.core;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.spi.PropertyDefiner;
import lombok.extern.slf4j.Slf4j;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
* 自定义logbackIp获取.
*
* @author Hua
* @since 2024-03-20 10:20
*/
@Slf4j
public class CustomizedApplicationIP extends ClassicConverter implements PropertyDefiner {
private static String ip;

static {
try {
ip = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
log.error("自定义logbackIp获取异常", e);
}
}

@Override
public String convert(ILoggingEvent event) {
return ip;
}

/**
* 用于更新使用IP
*/
static void updateIp(String eurekaIp) {
ip = eurekaIp;
}

@Override
public String getPropertyValue() {
return ip;
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/coco/boot/config/core/CustomizedRemoteIp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.coco.boot.config.core;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.coco.boot.utils.IpUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
* 自定义logbackIp获取.
* @author Hua
* @since 2024-03-20 10:20
*/
public class CustomizedRemoteIp extends ClassicConverter{
@Override
public String convert(ILoggingEvent event) {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes == null) {
return "127.0.0.1";
}
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
return IpUtils.getIpAddr(request);
}
}
Loading

0 comments on commit 4db1d14

Please sign in to comment.