增加UAM(5秒盾)集群设置

This commit is contained in:
GoEdgeLab
2022-07-03 22:10:46 +08:00
parent 0232d915a4
commit efd60b7080
5 changed files with 139 additions and 3 deletions

View File

@@ -918,7 +918,7 @@ func (this *NodeClusterDAO) FindClusterBasicInfo(tx *dbs.Tx, clusterId int64, ca
cluster, err := this.Query(tx).
Pk(clusterId).
State(NodeClusterStateEnabled).
Result("id", "timeZone", "nodeMaxThreads", "cachePolicyId", "httpFirewallPolicyId", "autoOpenPorts", "webp", "isOn", "ddosProtection").
Result("id", "timeZone", "nodeMaxThreads", "cachePolicyId", "httpFirewallPolicyId", "autoOpenPorts", "webp", "uam", "isOn", "ddosProtection").
Find()
if err != nil || cluster == nil {
return nil, err
@@ -988,6 +988,65 @@ func (this *NodeClusterDAO) FindClusterWebPPolicy(tx *dbs.Tx, clusterId int64, c
return policy, nil
}
// UpdateClusterUAMPolicy 修改UAM设置
func (this *NodeClusterDAO) UpdateClusterUAMPolicy(tx *dbs.Tx, clusterId int64, uamPolicy *nodeconfigs.UAMPolicy) error {
if uamPolicy == nil {
err := this.Query(tx).
Pk(clusterId).
Set("uam", dbs.SQL("null")).
UpdateQuickly()
if err != nil {
return err
}
return this.NotifyUpdate(tx, clusterId)
}
uamPolicyJSON, err := json.Marshal(uamPolicy)
if err != nil {
return err
}
err = this.Query(tx).
Pk(clusterId).
Set("uam", uamPolicyJSON).
UpdateQuickly()
if err != nil {
return err
}
return this.NotifyUpdate(tx, clusterId)
}
// FindClusterUAMPolicy 查询设置
func (this *NodeClusterDAO) FindClusterUAMPolicy(tx *dbs.Tx, clusterId int64, cacheMap *utils.CacheMap) (*nodeconfigs.UAMPolicy, error) {
var cacheKey = this.Table + ":FindClusterUAMPolicy:" + types.String(clusterId)
if cacheMap != nil {
cache, ok := cacheMap.Get(cacheKey)
if ok {
return cache.(*nodeconfigs.UAMPolicy), nil
}
}
uamJSON, err := this.Query(tx).
Pk(clusterId).
Result("uam").
FindJSONCol()
if err != nil {
return nil, err
}
if IsNull(uamJSON) {
return nodeconfigs.DefaultUAMPolicy, nil
}
var policy = &nodeconfigs.UAMPolicy{}
err = json.Unmarshal(uamJSON, policy)
if err != nil {
return nil, err
}
return policy, nil
}
// FindClusterDDoSProtection 获取集群的DDoS设置
func (this *NodeClusterDAO) FindClusterDDoSProtection(tx *dbs.Tx, clusterId int64) (*ddosconfigs.ProtectionConfig, error) {
one, err := this.Query(tx).

View File

@@ -34,6 +34,7 @@ type NodeCluster struct {
AutoOpenPorts uint8 `field:"autoOpenPorts"` // 是否自动尝试开放端口
IsPinned bool `field:"isPinned"` // 是否置顶
Webp dbs.JSON `field:"webp"` // WebP设置
Uam dbs.JSON `field:"uam"` // UAM设置
}
type NodeClusterOperator struct {
@@ -67,6 +68,7 @@ type NodeClusterOperator struct {
AutoOpenPorts interface{} // 是否自动尝试开放端口
IsPinned interface{} // 是否置顶
Webp interface{} // WebP设置
Uam interface{} // UAM设置
}
func NewNodeClusterOperator() *NodeClusterOperator {

View File

@@ -1018,6 +1018,7 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils
clusterIds = append(clusterIds, node.DecodeSecondaryClusterIds()...)
var clusterIndex = 0
config.WebPImagePolicies = map[int64]*nodeconfigs.WebPImagePolicy{}
config.UAMPolicies = map[int64]*nodeconfigs.UAMPolicy{}
var allowIPMaps = map[string]bool{}
for _, clusterId := range clusterIds {
nodeCluster, err := SharedNodeClusterDAO.FindClusterBasicInfo(tx, clusterId, cacheMap)
@@ -1091,6 +1092,16 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils
config.WebPImagePolicies[clusterId] = webpPolicy
}
// UAM
if IsNotNull(nodeCluster.Uam) {
var uamPolicy = &nodeconfigs.UAMPolicy{}
err = json.Unmarshal(nodeCluster.Uam, uamPolicy)
if err != nil {
return nil, err
}
config.UAMPolicies[clusterId] = uamPolicy
}
clusterIndex++
}

View File

@@ -1040,6 +1040,18 @@ func (this *NodeClusterService) FindEnabledNodeClusterConfigInfo(ctx context.Con
result.WebpIsOn = nodeconfigs.DefaultWebPImagePolicy.IsOn
}
// UAM
if models.IsNotNull(cluster.Uam) {
var uamPolicy = &nodeconfigs.UAMPolicy{}
err = json.Unmarshal(cluster.Uam, uamPolicy)
if err != nil {
return nil, err
}
result.UamIsOn = uamPolicy.IsOn
} else {
result.UamIsOn = nodeconfigs.DefaultUAMPolicy.IsOn
}
// system service
if models.IsNotNull(cluster.SystemServices) {
var servicesMap = map[string]maps.Map{}
@@ -1104,13 +1116,18 @@ func (this *NodeClusterService) UpdateNodeClusterWebPPolicy(ctx context.Context,
return nil, err
}
var tx = this.NullTx()
var webpPolicy = &nodeconfigs.WebPImagePolicy{}
err = json.Unmarshal(req.WebpPolicyJSON, webpPolicy)
if err != nil {
return nil, err
}
err = webpPolicy.Init()
if err != nil {
return nil, errors.New("validate webp policy failed: " + err.Error())
}
var tx = this.NullTx()
err = models.SharedNodeClusterDAO.UpdateClusterWebPPolicy(tx, req.NodeClusterId, webpPolicy)
if err != nil {
return nil, err
@@ -1118,6 +1135,53 @@ func (this *NodeClusterService) UpdateNodeClusterWebPPolicy(ctx context.Context,
return this.Success()
}
// FindEnabledNodeClusterUAMPolicy 读取集群UAM策略
func (this *NodeClusterService) FindEnabledNodeClusterUAMPolicy(ctx context.Context, req *pb.FindEnabledNodeClusterUAMPolicyRequest) (*pb.FindEnabledNodeClusterUAMPolicyResponse, error) {
_, _, err := this.ValidateAdminAndUser(ctx, 0, 0)
if err != nil {
return nil, err
}
var tx = this.NullTx()
uamPolicy, err := models.SharedNodeClusterDAO.FindClusterUAMPolicy(tx, req.NodeClusterId, nil)
if err != nil {
return nil, err
}
uamPolicyJSON, err := json.Marshal(uamPolicy)
if err != nil {
return nil, err
}
return &pb.FindEnabledNodeClusterUAMPolicyResponse{
UamPolicyJSON: uamPolicyJSON,
}, nil
}
// UpdateNodeClusterUAMPolicy 设置集群的UAM策略
func (this *NodeClusterService) UpdateNodeClusterUAMPolicy(ctx context.Context, req *pb.UpdateNodeClusterUAMPolicyRequest) (*pb.RPCSuccess, error) {
_, err := this.ValidateAdmin(ctx, 0)
if err != nil {
return nil, err
}
var uamPolicy = &nodeconfigs.UAMPolicy{}
err = json.Unmarshal(req.UamPolicyJSON, uamPolicy)
if err != nil {
return nil, err
}
err = uamPolicy.Init()
if err != nil {
return nil, errors.New("validate uam policy failed: " + err.Error())
}
var tx = this.NullTx()
err = models.SharedNodeClusterDAO.UpdateClusterUAMPolicy(tx, req.NodeClusterId, uamPolicy)
if err != nil {
return nil, err
}
return this.Success()
}
// FindNodeClusterDDoSProtection 获取集群的DDOS设置
func (this *NodeClusterService) FindNodeClusterDDoSProtection(ctx context.Context, req *pb.FindNodeClusterDDoSProtectionRequest) (*pb.FindNodeClusterDDoSProtectionResponse, error) {
_, err := this.ValidateAdmin(ctx, 0)

File diff suppressed because one or more lines are too long