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

This commit is contained in:
GoEdgeLab
2020-12-17 15:51:02 +08:00
parent 728c82711c
commit 4ba539c687
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 {

View File

@@ -2,47 +2,53 @@ package models
// 节点集群
type NodeCluster struct {
Id uint32 `field:"id"` // ID
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
Name string `field:"name"` // 名称
UseAllAPINodes uint8 `field:"useAllAPINodes"` // 是否使用所有API节点
ApiNodes string `field:"apiNodes"` // 使用的API节点
InstallDir string `field:"installDir"` // 安装目录
Order uint32 `field:"order"` // 排序
CreatedAt uint64 `field:"createdAt"` // 创建时间
GrantId uint32 `field:"grantId"` // 默认认证方式
State uint8 `field:"state"` // 状态
AutoRegister uint8 `field:"autoRegister"` // 是否开启自动注册
UniqueId string `field:"uniqueId"` // 唯一ID
Secret string `field:"secret"` // 密钥
HealthCheck string `field:"healthCheck"` // 健康检查
DnsName string `field:"dnsName"` // DNS名称
DnsDomainId uint32 `field:"dnsDomainId"` // 域名ID
Dns string `field:"dns"` // DNS配置
Toa string `field:"toa"` // TOA配置
Id uint32 `field:"id"` // ID
AdminId uint32 `field:"adminId"` // 管理员ID
UserId uint32 `field:"userId"` // 用户ID
Name string `field:"name"` // 名称
UseAllAPINodes uint8 `field:"useAllAPINodes"` // 是否使用所有API节点
ApiNodes string `field:"apiNodes"` // 使用的API节点
InstallDir string `field:"installDir"` // 安装目录
Order uint32 `field:"order"` // 排序
CreatedAt uint64 `field:"createdAt"` // 创建时间
GrantId uint32 `field:"grantId"` // 默认认证方式
State uint8 `field:"state"` // 状态
AutoRegister uint8 `field:"autoRegister"` // 是否开启自动注册
UniqueId string `field:"uniqueId"` // 唯一ID
Secret string `field:"secret"` // 密钥
HealthCheck string `field:"healthCheck"` // 健康检查
DnsName string `field:"dnsName"` // DNS名称
DnsDomainId uint32 `field:"dnsDomainId"` // 域名ID
Dns string `field:"dns"` // DNS配置
Toa string `field:"toa"` // TOA配置
CachePolicyId uint32 `field:"cachePolicyId"` // 缓存策略ID
HttpFirewallPolicyId uint32 `field:"httpFirewallPolicyId"` // WAF策略ID
AccessLog string `field:"accessLog"` // 访问日志设置
}
type NodeClusterOperator struct {
Id interface{} // ID
AdminId interface{} // 管理员ID
UserId interface{} // 用户ID
Name interface{} // 名称
UseAllAPINodes interface{} // 是否使用所有API节点
ApiNodes interface{} // 使用的API节点
InstallDir interface{} // 安装目录
Order interface{} // 排序
CreatedAt interface{} // 创建时间
GrantId interface{} // 默认认证方式
State interface{} // 状态
AutoRegister interface{} // 是否开启自动注册
UniqueId interface{} // 唯一ID
Secret interface{} // 密钥
HealthCheck interface{} // 健康检查
DnsName interface{} // DNS名称
DnsDomainId interface{} // 域名ID
Dns interface{} // DNS配置
Toa interface{} // TOA配置
Id interface{} // ID
AdminId interface{} // 管理员ID
UserId interface{} // 用户ID
Name interface{} // 名称
UseAllAPINodes interface{} // 是否使用所有API节点
ApiNodes interface{} // 使用的API节点
InstallDir interface{} // 安装目录
Order interface{} // 排序
CreatedAt interface{} // 创建时间
GrantId interface{} // 默认认证方式
State interface{} // 状态
AutoRegister interface{} // 是否开启自动注册
UniqueId interface{} // 唯一ID
Secret interface{} // 密钥
HealthCheck interface{} // 健康检查
DnsName interface{} // DNS名称
DnsDomainId interface{} // 域名ID
Dns interface{} // DNS配置
Toa interface{} // TOA配置
CachePolicyId interface{} // 缓存策略ID
HttpFirewallPolicyId interface{} // WAF策略ID
AccessLog interface{} // 访问日志设置
}
func NewNodeClusterOperator() *NodeClusterOperator {

View File

@@ -85,7 +85,7 @@ func (this *UserDAO) FindUserFullname(userId int64) (string, error) {
}
// 创建用户
func (this *UserDAO) CreateUser(username string, password string, fullname string, mobile string, tel string, email string, remark string, source string) (int64, error) {
func (this *UserDAO) CreateUser(username string, password string, fullname string, mobile string, tel string, email string, remark string, source string, clusterId int64) (int64, error) {
op := NewUserOperator()
op.Username = username
op.Password = stringutil.Md5(password)
@@ -95,6 +95,7 @@ func (this *UserDAO) CreateUser(username string, password string, fullname strin
op.Email = email
op.Remark = remark
op.Source = source
op.ClusterId = clusterId
op.IsOn = true
op.State = UserStateEnabled
@@ -106,7 +107,7 @@ func (this *UserDAO) CreateUser(username string, password string, fullname strin
}
// 修改用户
func (this *UserDAO) UpdateUser(userId int64, username string, password string, fullname string, mobile string, tel string, email string, remark string, isOn bool) error {
func (this *UserDAO) UpdateUser(userId int64, username string, password string, fullname string, mobile string, tel string, email string, remark string, isOn bool, clusterId int64) error {
if userId <= 0 {
return errors.New("invalid userId")
}
@@ -122,6 +123,7 @@ func (this *UserDAO) UpdateUser(userId int64, username string, password string,
op.Email = email
op.Remark = remark
op.IsOn = isOn
op.ClusterId = clusterId
err := this.Save(op)
return err
}

View File

@@ -16,6 +16,7 @@ type User struct {
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
State uint8 `field:"state"` // 状态
Source string `field:"source"` // 来源
ClusterId uint32 `field:"clusterId"` // 集群ID
}
type UserOperator struct {
@@ -33,6 +34,7 @@ type UserOperator struct {
UpdatedAt interface{} // 修改时间
State interface{} // 状态
Source interface{} // 来源
ClusterId interface{} // 集群ID
}
func NewUserOperator() *UserOperator {