自建DNS增加全局配置

This commit is contained in:
GoEdgeLab
2021-08-05 16:08:01 +08:00
parent 30769f4cd6
commit ec19842bf5
4 changed files with 79 additions and 5 deletions

View File

@@ -22,5 +22,5 @@ const (
UserNodeVersion = "0.0.10" UserNodeVersion = "0.0.10"
AuthorityNodeVersion = "0.0.2" AuthorityNodeVersion = "0.0.2"
MonitorNodeVersion = "0.0.2" MonitorNodeVersion = "0.0.2"
DNSNodeVersion = "0.0.3" DNSNodeVersion = "0.1.0"
) )

View File

@@ -8,6 +8,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/configutils" "github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs" "github.com/iwind/TeaGo/dbs"
@@ -387,15 +388,35 @@ func (this *NSNodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64) (*dnsconfigs.
ClusterId: int64(node.ClusterId), ClusterId: int64(node.ClusterId),
} }
if len(cluster.AccessLog) > 0 { // 访问日志
ref := &dnsconfigs.AccessLogRef{} // 全局配置
err = json.Unmarshal([]byte(cluster.AccessLog), ref) {
globalValue, err := models.SharedSysSettingDAO.ReadSetting(tx, systemconfigs.SettingCodeNSAccessLogSetting)
if err != nil {
return nil, err
}
if len(globalValue) > 0 {
var ref = &dnsconfigs.NSAccessLogRef{}
err = json.Unmarshal(globalValue, ref)
if err != nil { if err != nil {
return nil, err return nil, err
} }
config.AccessLogRef = ref config.AccessLogRef = ref
} }
// 集群配置
if len(cluster.AccessLog) > 0 {
ref := &dnsconfigs.NSAccessLogRef{}
err = json.Unmarshal([]byte(cluster.AccessLog), ref)
if err != nil {
return nil, err
}
if ref.IsPrior {
config.AccessLogRef = ref
}
}
}
return config, nil return config, nil
} }

View File

@@ -4,7 +4,9 @@ import (
"encoding/json" "encoding/json"
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const" teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
"github.com/TeaOSLab/EdgeAPI/internal/errors" "github.com/TeaOSLab/EdgeAPI/internal/errors"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/go-yaml/yaml" "github.com/go-yaml/yaml"
"github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/Tea"
@@ -104,6 +106,12 @@ func (this *SQLExecutor) checkData(db *dbs.DB) error {
return err return err
} }
// 检查自建DNS全局设置
err = this.checkNS(db)
if err != nil {
return err
}
// 更新版本号 // 更新版本号
err = this.updateVersion(db, teaconst.Version) err = this.updateVersion(db, teaconst.Version)
if err != nil { if err != nil {
@@ -396,6 +404,33 @@ func (this *SQLExecutor) checkMetricItems(db *dbs.DB) error {
return nil return nil
} }
// 检查自建DNS全局设置
func (this *SQLExecutor) checkNS(db *dbs.DB) error {
// 访问日志
{
one, err := db.FindOne("SELECT id FROM edgeSysSettings WHERE code=? LIMIT 1", systemconfigs.SettingCodeNSAccessLogSetting)
if err != nil {
return err
}
if len(one) == 0 {
ref := &dnsconfigs.NSAccessLogRef{
IsPrior: false,
IsOn: true,
LogMissingDomains: false,
}
refJSON, err := json.Marshal(ref)
if err != nil {
return err
}
_, err = db.Exec("INSERT edgeSysSettings (code, value) VALUES (?, ?)", systemconfigs.SettingCodeNSAccessLogSetting, refJSON)
if err != nil {
return err
}
}
}
return nil
}
// 更新版本号 // 更新版本号
func (this *SQLExecutor) updateVersion(db *dbs.DB, version string) error { func (this *SQLExecutor) updateVersion(db *dbs.DB, version string) error {
stmt, err := db.Prepare("SELECT COUNT(*) FROM edgeVersions") stmt, err := db.Prepare("SELECT COUNT(*) FROM edgeVersions")

View File

@@ -35,3 +35,21 @@ func TestSQLExecutor_checkMetricItems(t *testing.T) {
} }
t.Log("ok") t.Log("ok")
} }
func TestSQLExecutor_checkNS(t *testing.T) {
executor := NewSQLExecutor(&dbs.DBConfig{
Driver: "mysql",
Prefix: "edge",
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_new?charset=utf8mb4&multiStatements=true",
})
db, err := dbs.NewInstanceFromConfig(executor.dbConfig)
if err != nil {
t.Fatal(err)
}
err = executor.checkNS(db)
if err != nil {
t.Fatal(err)
}
t.Log("ok")
}