mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-27 01:50:31 +08:00
自建DNS支持递归查询
This commit is contained in:
@@ -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.1.0"
|
DNSNodeVersion = "0.2.0"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -169,6 +169,30 @@ func (this *NSClusterDAO) FindClusterGrantId(tx *dbs.Tx, clusterId int64) (int64
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateRecursion 设置递归DNS
|
||||||
|
func (this *NSClusterDAO) UpdateRecursion(tx *dbs.Tx, clusterId int64, recursionJSON []byte) error {
|
||||||
|
err := this.Query(tx).
|
||||||
|
Pk(clusterId).
|
||||||
|
Set("recursion", recursionJSON).
|
||||||
|
UpdateQuickly()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return this.NotifyUpdate(tx, clusterId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindClusterRecursion 读取递归DNS配置
|
||||||
|
func (this *NSClusterDAO) FindClusterRecursion(tx *dbs.Tx, clusterId int64) ([]byte, error) {
|
||||||
|
recursion, err := this.Query(tx).
|
||||||
|
Result("recursion").
|
||||||
|
Pk(clusterId).
|
||||||
|
FindStringCol("")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return []byte(recursion), nil
|
||||||
|
}
|
||||||
|
|
||||||
// NotifyUpdate 通知更改
|
// NotifyUpdate 通知更改
|
||||||
func (this *NSClusterDAO) NotifyUpdate(tx *dbs.Tx, clusterId int64) error {
|
func (this *NSClusterDAO) NotifyUpdate(tx *dbs.Tx, clusterId int64) error {
|
||||||
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleDNS, clusterId, NSNodeTaskTypeConfigChanged)
|
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleDNS, clusterId, NSNodeTaskTypeConfigChanged)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ type NSCluster struct {
|
|||||||
State uint8 `field:"state"` // 状态
|
State uint8 `field:"state"` // 状态
|
||||||
AccessLog string `field:"accessLog"` // 访问日志配置
|
AccessLog string `field:"accessLog"` // 访问日志配置
|
||||||
GrantId uint32 `field:"grantId"` // 授权ID
|
GrantId uint32 `field:"grantId"` // 授权ID
|
||||||
|
Recursion string `field:"recursion"` // 递归DNS设置
|
||||||
}
|
}
|
||||||
|
|
||||||
type NSClusterOperator struct {
|
type NSClusterOperator struct {
|
||||||
@@ -19,6 +20,7 @@ type NSClusterOperator struct {
|
|||||||
State interface{} // 状态
|
State interface{} // 状态
|
||||||
AccessLog interface{} // 访问日志配置
|
AccessLog interface{} // 访问日志配置
|
||||||
GrantId interface{} // 授权ID
|
GrantId interface{} // 授权ID
|
||||||
|
Recursion interface{} // 递归DNS设置
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNSClusterOperator() *NSClusterOperator {
|
func NewNSClusterOperator() *NSClusterOperator {
|
||||||
|
|||||||
@@ -417,6 +417,20 @@ func (this *NSNodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64) (*dnsconfigs.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 递归DNS配置
|
||||||
|
recursionJSON, err := SharedNSClusterDAO.FindClusterRecursion(tx, int64(node.ClusterId))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(recursionJSON) > 0 {
|
||||||
|
var recursionConfig = &dnsconfigs.RecursionConfig{}
|
||||||
|
err = json.Unmarshal(recursionJSON, recursionConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.RecursionConfig = recursionConfig
|
||||||
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ package nameservers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/rpc/services"
|
"github.com/TeaOSLab/EdgeAPI/internal/rpc/services"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
)
|
)
|
||||||
@@ -175,3 +177,42 @@ func (this *NSClusterService) FindAllEnabledNSClusters(ctx context.Context, req
|
|||||||
}
|
}
|
||||||
return &pb.FindAllEnabledNSClustersResponse{NsClusters: pbClusters}, nil
|
return &pb.FindAllEnabledNSClustersResponse{NsClusters: pbClusters}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateNSClusterRecursionConfig 设置递归DNS配置
|
||||||
|
func (this *NSClusterService) UpdateNSClusterRecursionConfig(ctx context.Context, req *pb.UpdateNSClusterRecursionConfigRequest) (*pb.RPCSuccess, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验配置
|
||||||
|
var config = &dnsconfigs.RecursionConfig{}
|
||||||
|
err = json.Unmarshal(req.RecursionJSON, config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
err = models.SharedNSClusterDAO.UpdateRecursion(tx, req.NsClusterId, req.RecursionJSON)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindNSClusterRecursionConfig 读取递归DNS配置
|
||||||
|
func (this *NSClusterService) FindNSClusterRecursionConfig(ctx context.Context, req *pb.FindNSClusterRecursionConfigRequest) (*pb.FindNSClusterRecursionConfigResponse, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
recursion, err := models.SharedNSClusterDAO.FindClusterRecursion(tx, req.NsClusterId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &pb.FindNSClusterRecursionConfigResponse{
|
||||||
|
RecursionJSON: recursion,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user