mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-29 08:00:25 +08:00
集群可以设置默认的WAF策略、缓存策略
This commit is contained in:
@@ -3,7 +3,6 @@ package models
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
)
|
||||
@@ -11,25 +10,60 @@ import (
|
||||
var SharedHTTPCachePolicyDAO = new(HTTPCachePolicyDAO)
|
||||
|
||||
type HTTPCachePolicyDAO struct {
|
||||
BaseDAO
|
||||
}
|
||||
|
||||
// 查找缓存策略配置
|
||||
func (this *HTTPCachePolicyDAO) FindEnabledCachePolicyConfig(ctx context.Context, cachePolicyId int64) (*serverconfigs.HTTPCachePolicy, error) {
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicyConfig(ctx context.Context, cachePolicyId int64) (*serverconfigs.HTTPCachePolicy, error) {
|
||||
resp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(ctx, &pb.FindEnabledHTTPCachePolicyConfigRequest{HttpCachePolicyId: cachePolicyId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := rpcClient.HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(ctx, &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: cachePolicyId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(resp.CachePolicyJSON) == 0 {
|
||||
if len(resp.HttpCachePolicyJSON) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
config := &serverconfigs.HTTPCachePolicy{}
|
||||
err = json.Unmarshal(resp.CachePolicyJSON, config)
|
||||
err = json.Unmarshal(resp.HttpCachePolicyJSON, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// 查找缓存策略信息
|
||||
func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicy(ctx context.Context, cachePolicyId int64) (*pb.HTTPCachePolicy, error) {
|
||||
resp, err := this.RPC().HTTPCachePolicyRPC().FindEnabledHTTPCachePolicy(ctx, &pb.FindEnabledHTTPCachePolicyRequest{
|
||||
HttpCachePolicyId: cachePolicyId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.HttpCachePolicy, nil
|
||||
}
|
||||
|
||||
// 根据服务ID查找缓存策略
|
||||
func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicyWithServerId(ctx context.Context, serverId int64) (*pb.HTTPCachePolicy, error) {
|
||||
serverResp, err := this.RPC().ServerRPC().FindEnabledServer(ctx, &pb.FindEnabledServerRequest{ServerId: serverId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
server := serverResp.Server
|
||||
if server == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if server.Cluster == nil {
|
||||
return nil, nil
|
||||
}
|
||||
clusterId := server.Cluster.Id
|
||||
cluster, err := SharedNodeClusterDAO.FindEnabledNodeCluster(ctx, clusterId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cluster == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if cluster.HttpCachePolicyId == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return SharedHTTPCachePolicyDAO.FindEnabledHTTPCachePolicy(ctx, cluster.HttpCachePolicyId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user