Quellcode durchsuchen

feat(cc): 增加 IP 白名单添加和编辑时的理由字段

- 在 CcIpList 结构中添加 Reason 字段- 更新 AddCcWhiteIp 和 EditCcWhiteIp 方法以包含原因参数
- 在调用 CDN 接口时传入原因信息
fusu vor 2 Wochen
Ursprung
Commit
975f1099cd

+ 1 - 0
api/v1/ccIpList.go

@@ -12,6 +12,7 @@ type CcIpList struct {
 	Uid int64 `json:"uid" form:"uid" validate:"required"`
 	HostId int64 `json:"hostId" form:"hostId" validate:"required"`
 	WebId int64 `json:"webId" form:"webId" validate:"required"`
+	Reason string `json:"reason" form:"reason"`
 }
 
 type DelCcIpList struct {

+ 2 - 2
internal/handler/api/waf/cciplist.go

@@ -43,7 +43,7 @@ func (h *CcIpListHandler) AddCcIpList(ctx *gin.Context) {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
 		return
 	}
-	err := h.ccIpListService.AddCcWhiteIp(ctx, req.WebId,req.NewIp)
+	err := h.ccIpListService.AddCcWhiteIp(ctx, req.WebId,req.NewIp,req.Reason)
 	if err != nil {
 		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
 		return
@@ -72,7 +72,7 @@ func (h *CcIpListHandler) EditCcIpList(ctx *gin.Context) {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
 		return
 	}
-	err := h.ccIpListService.EditCcWhiteIp(ctx, req.WebId,req.OldIp,req.NewIp)
+	err := h.ccIpListService.EditCcWhiteIp(ctx, req.WebId,req.OldIp,req.NewIp,req.Reason)
 	if err != nil {
 		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
 		return

+ 6 - 4
internal/service/api/flexCdn/cciplist.go

@@ -12,9 +12,9 @@ import (
 type CcIpListService interface {
 	GetCcIpList(ctx context.Context, webId int64) ([]string, error)
 	AddCcIpListPolicy(ctx context.Context, serverId int64,serverGroupId int64) error
-	AddCcWhiteIp(ctx context.Context, webId int64,ip string) error
+	AddCcWhiteIp(ctx context.Context, webId int64,ip string,reason string) error
 	DelCcWhiteIp(ctx context.Context, webId int64,ips []string) error
-	EditCcWhiteIp(ctx context.Context, webId int64,oldIp string,newIp string) error
+	EditCcWhiteIp(ctx context.Context, webId int64,oldIp string,newIp string,reason string) error
 
 }
 func NewCcIpListService(
@@ -94,7 +94,7 @@ func (s *ccIpListService) AddCcIpListPolicy(ctx context.Context, serverId int64,
 
 
 // 添加白名单
-func (s *ccIpListService) AddCcWhiteIp(ctx context.Context, webId int64,ip string) error {
+func (s *ccIpListService) AddCcWhiteIp(ctx context.Context, webId int64,ip string,reason string) error {
 	serverId, err := s.GetServerId(ctx, webId)
 	if err != nil {
 		return err
@@ -107,6 +107,7 @@ func (s *ccIpListService) AddCcWhiteIp(ctx context.Context, webId int64,ip strin
 	err = s.cdn.AddIpItem(ctx,v1.AddIpItem{
 		IpListId: ipListId,
 		Value: ip,
+		Reason: reason,
 		EventLevel: "notice",
 		SourceCategory: "cc",
 	})
@@ -116,7 +117,7 @@ func (s *ccIpListService) AddCcWhiteIp(ctx context.Context, webId int64,ip strin
 	return nil
 }
 
-func (s *ccIpListService) EditCcWhiteIp(ctx context.Context, webId int64,oldIp string,newIp string) error {
+func (s *ccIpListService) EditCcWhiteIp(ctx context.Context, webId int64,oldIp string,newIp string,reason string) error {
 	serverId, err := s.GetServerId(ctx, webId)
 	if err != nil {
 		return err
@@ -133,6 +134,7 @@ func (s *ccIpListService) EditCcWhiteIp(ctx context.Context, webId int64,oldIp s
 	err = s.cdn.EditIpItem(ctx,v1.AddIpItem{
 		IpItemId: ipItemId,
 		Value: newIp,
+		Reason: reason,
 		EventLevel: "notice",
 		SourceCategory: "cc",
 	})