集群可以设置默认的WAF策略、缓存策略

This commit is contained in:
刘祥超
2020-12-17 15:51:02 +08:00
parent d52c83f906
commit 1766ed67fc
12 changed files with 337 additions and 231 deletions

View File

@@ -102,7 +102,7 @@ func (this *NodeClusterDAO) FindAllEnableClusters() (result []*NodeCluster, err
}
// 创建集群
func (this *NodeClusterDAO) CreateCluster(adminId int64, name string, grantId int64, installDir string, dnsDomainId int64, dnsName string) (clusterId int64, err error) {
func (this *NodeClusterDAO) CreateCluster(adminId int64, name string, grantId int64, installDir string, dnsDomainId int64, dnsName string, cachePolicyId int64, httpFirewallPolicyId int64) (clusterId int64, err error) {
uniqueId, err := this.genUniqueId()
if err != nil {
return 0, err
@@ -133,6 +133,12 @@ func (this *NodeClusterDAO) CreateCluster(adminId int64, name string, grantId in
}
op.Dns = dnsJSON
// 缓存策略
op.CachePolicyId = cachePolicyId
// WAF策略
op.HttpFirewallPolicyId = httpFirewallPolicyId
op.UseAllAPINodes = 1
op.ApiNodes = "[]"
op.UniqueId = uniqueId
@@ -565,6 +571,62 @@ func (this *NodeClusterDAO) UpdateClusterTOA(clusterId int64, toaJSON []byte) er
return err
}
// 计算使用某个缓存策略的集群数量
func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPCachePolicyId(httpCachePolicyId int64) (int64, error) {
return this.Query().
State(NodeClusterStateEnabled).
Attr("cachePolicyId", httpCachePolicyId).
Count()
}
// 查找使用缓存策略的所有集群
func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPCachePolicyId(httpCachePolicyId int64) (result []*NodeCluster, err error) {
_, err = this.Query().
State(NodeClusterStateEnabled).
Attr("cachePolicyId", httpCachePolicyId).
DescPk().
Slice(&result).
FindAll()
return
}
// 计算使用某个WAF策略的集群数量
func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPFirewallPolicyId(httpFirewallPolicyId int64) (int64, error) {
return this.Query().
State(NodeClusterStateEnabled).
Attr("httpFirewallPolicyId", httpFirewallPolicyId).
Count()
}
// 查找使用WAF策略的所有集群
func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPFirewallPolicyId(httpFirewallPolicyId int64) (result []*NodeCluster, err error) {
_, err = this.Query().
State(NodeClusterStateEnabled).
Attr("httpFirewallPolicyId", httpFirewallPolicyId).
DescPk().
Slice(&result).
FindAll()
return
}
// 设置集群的缓存策略
func (this *NodeClusterDAO) UpdateNodeClusterHTTPCachePolicyId(clusterId int64, httpCachePolicyId int64) error {
_, err := this.Query().
Pk(clusterId).
Set("cachePolicyId", httpCachePolicyId).
Update()
return err
}
// 设置集群的WAF策略
func (this *NodeClusterDAO) UpdateNodeClusterHTTPFirewallPolicyId(clusterId int64, httpFirewallPolicyId int64) error {
_, err := this.Query().
Pk(clusterId).
Set("httpFirewallPolicyId", httpFirewallPolicyId).
Update()
return err
}
// 生成唯一ID
func (this *NodeClusterDAO) genUniqueId() (string, error) {
for {