diff --git a/internal/const/const.go b/internal/const/const.go index 2c8b21f8..5b193728 100644 --- a/internal/const/const.go +++ b/internal/const/const.go @@ -22,5 +22,5 @@ const ( UserNodeVersion = "0.0.10" AuthorityNodeVersion = "0.0.2" MonitorNodeVersion = "0.0.2" - DNSNodeVersion = "0.1.0" + DNSNodeVersion = "0.2.0" ) diff --git a/internal/db/models/ns_cluster_dao.go b/internal/db/models/ns_cluster_dao.go index b4193b42..8467acd2 100644 --- a/internal/db/models/ns_cluster_dao.go +++ b/internal/db/models/ns_cluster_dao.go @@ -169,6 +169,30 @@ func (this *NSClusterDAO) FindClusterGrantId(tx *dbs.Tx, clusterId int64) (int64 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 通知更改 func (this *NSClusterDAO) NotifyUpdate(tx *dbs.Tx, clusterId int64) error { return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleDNS, clusterId, NSNodeTaskTypeConfigChanged) diff --git a/internal/db/models/ns_cluster_model.go b/internal/db/models/ns_cluster_model.go index 6881f535..5484d2fc 100644 --- a/internal/db/models/ns_cluster_model.go +++ b/internal/db/models/ns_cluster_model.go @@ -9,6 +9,7 @@ type NSCluster struct { State uint8 `field:"state"` // 状态 AccessLog string `field:"accessLog"` // 访问日志配置 GrantId uint32 `field:"grantId"` // 授权ID + Recursion string `field:"recursion"` // 递归DNS设置 } type NSClusterOperator struct { @@ -19,6 +20,7 @@ type NSClusterOperator struct { State interface{} // 状态 AccessLog interface{} // 访问日志配置 GrantId interface{} // 授权ID + Recursion interface{} // 递归DNS设置 } func NewNSClusterOperator() *NSClusterOperator { diff --git a/internal/db/models/ns_node_dao.go b/internal/db/models/ns_node_dao.go index 98b6a1cf..df0146be 100644 --- a/internal/db/models/ns_node_dao.go +++ b/internal/db/models/ns_node_dao.go @@ -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 } diff --git a/internal/rpc/services/nameservers/service_ns_cluster.go b/internal/rpc/services/nameservers/service_ns_cluster.go index b07a99f2..7b8a7960 100644 --- a/internal/rpc/services/nameservers/service_ns_cluster.go +++ b/internal/rpc/services/nameservers/service_ns_cluster.go @@ -4,8 +4,10 @@ package nameservers import ( "context" + "encoding/json" "github.com/TeaOSLab/EdgeAPI/internal/db/models" "github.com/TeaOSLab/EdgeAPI/internal/rpc/services" + "github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "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 } + +// 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 +}