2020-09-15 14:44:11 +08:00
|
|
|
|
package models
|
2020-11-15 21:17:42 +08:00
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"encoding/json"
|
2022-09-15 15:56:50 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
2020-11-15 21:17:42 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
2022-09-15 15:56:50 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
2022-05-18 21:02:53 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
2020-11-15 21:17:42 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-09-20 16:37:48 +08:00
|
|
|
|
// DecodeDNSConfig 解析DNS配置
|
2020-11-15 21:17:42 +08:00
|
|
|
|
func (this *NodeCluster) DecodeDNSConfig() (*dnsconfigs.ClusterDNSConfig, error) {
|
2022-03-21 21:39:36 +08:00
|
|
|
|
if len(this.Dns) == 0 {
|
2020-11-15 21:17:42 +08:00
|
|
|
|
// 一定要返回一个默认的值,防止产生nil
|
|
|
|
|
|
return &dnsconfigs.ClusterDNSConfig{
|
2022-08-25 19:18:30 +08:00
|
|
|
|
NodesAutoSync: false,
|
|
|
|
|
|
ServersAutoSync: false,
|
|
|
|
|
|
CNameAsDomain: true,
|
|
|
|
|
|
IncludingLnNodes: true,
|
2020-11-15 21:17:42 +08:00
|
|
|
|
}, nil
|
|
|
|
|
|
}
|
2022-07-14 09:49:09 +08:00
|
|
|
|
var dnsConfig = &dnsconfigs.ClusterDNSConfig{
|
2022-08-25 19:18:30 +08:00
|
|
|
|
CNameAsDomain: true,
|
|
|
|
|
|
IncludingLnNodes: true,
|
2022-07-14 09:49:09 +08:00
|
|
|
|
}
|
2022-03-22 19:30:30 +08:00
|
|
|
|
err := json.Unmarshal(this.Dns, &dnsConfig)
|
2020-11-15 21:17:42 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
return dnsConfig, nil
|
|
|
|
|
|
}
|
2022-05-18 21:02:53 +08:00
|
|
|
|
|
|
|
|
|
|
// DecodeDDoSProtection 解析DDOS Protection设置
|
|
|
|
|
|
func (this *NodeCluster) DecodeDDoSProtection() *ddosconfigs.ProtectionConfig {
|
|
|
|
|
|
if IsNull(this.DdosProtection) {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var result = &ddosconfigs.ProtectionConfig{}
|
|
|
|
|
|
err := json.Unmarshal(this.DdosProtection, &result)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
// ignore err
|
|
|
|
|
|
}
|
|
|
|
|
|
return result
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// HasDDoSProtection 检查是否有DDOS设置
|
|
|
|
|
|
func (this *NodeCluster) HasDDoSProtection() bool {
|
|
|
|
|
|
var config = this.DecodeDDoSProtection()
|
|
|
|
|
|
if config != nil {
|
|
|
|
|
|
return config.IsOn()
|
|
|
|
|
|
}
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
2022-09-15 15:56:50 +08:00
|
|
|
|
|
|
|
|
|
|
// DecodeClock 解析时钟配置
|
|
|
|
|
|
func (this *NodeCluster) DecodeClock() *nodeconfigs.ClockConfig {
|
|
|
|
|
|
var clock = nodeconfigs.DefaultClockConfig()
|
|
|
|
|
|
if IsNotNull(this.Clock) {
|
|
|
|
|
|
err := json.Unmarshal(this.Clock, clock)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
remotelogs.Error("NodeCluster.DecodeClock()", err.Error())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return clock
|
|
|
|
|
|
}
|