支持阿里云DNS

This commit is contained in:
刘祥超
2020-11-15 11:57:49 +08:00
parent 2da1ab384c
commit afb414bca3
16 changed files with 500 additions and 41 deletions

View File

@@ -10,7 +10,6 @@ import (
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
)
@@ -294,7 +293,6 @@ func (this *DNSDomainService) SyncDNSDomainData(ctx context.Context, req *pb.Syn
}
allChanges = append(allChanges, changes...)
}
logs.Println("====")
for _, change := range allChanges {
action := change.GetString("action")
record := change.Get("record").(*dnsclients.Record)
@@ -316,7 +314,7 @@ func (this *DNSDomainService) SyncDNSDomainData(ctx context.Context, req *pb.Syn
}
}
logs.Println(action, record.Name, record.Type, record.Value, record.Route) // TODO 仅供调试
//logs.Println(action, record.Name, record.Type, record.Value, record.Route)
}
// 重新更新记录
@@ -352,7 +350,16 @@ func (this *DNSDomainService) FindAllDNSDomainRoutes(ctx context.Context, req *p
if err != nil {
return nil, err
}
return &pb.FindAllDNSDomainRoutesResponse{Routes: routes}, nil
pbRoutes := []*pb.DNSRoute{}
for _, route := range routes {
pbRoutes = append(pbRoutes, &pb.DNSRoute{
Name: route.Name,
Code: route.Code,
})
}
return &pb.FindAllDNSDomainRoutesResponse{Routes: pbRoutes}, nil
}
// 转换域名信息
@@ -396,12 +403,16 @@ func (this *DNSDomainService) convertDomainToPB(domain *models.DNSDomain) (*pb.D
}
// 线路
routes := []string{}
if len(domain.Routes) > 0 && domain.Routes != "null" {
err := json.Unmarshal([]byte(domain.Routes), &routes)
if err != nil {
return nil, err
}
routes, err := domain.DecodeRoutes()
if err != nil {
return nil, err
}
pbRoutes := []*pb.DNSRoute{}
for _, route := range routes {
pbRoutes = append(pbRoutes, &pb.DNSRoute{
Name: route.Name,
Code: route.Code,
})
}
return &pb.DNSDomain{
@@ -414,7 +425,7 @@ func (this *DNSDomainService) convertDomainToPB(domain *models.DNSDomain) (*pb.D
NodesChanged: nodesChanged,
CountServerRecords: int64(countServerRecords),
ServersChanged: serversChanged,
Routes: routes,
Routes: pbRoutes,
}, nil
}

View File

@@ -856,6 +856,11 @@ func (this *NodeService) FindAllEnabledNodesDNSWithClusterId(ctx context.Context
}
dnsDomainId := int64(clusterDNS.DnsDomainId)
routes, err := models.SharedDNSDomainDAO.FindDomainRoutes(dnsDomainId)
if err != nil {
return nil, err
}
nodes, err := models.SharedNodeDAO.FindAllEnabledNodesDNSWithClusterId(req.NodeClusterId)
if err != nil {
return nil, err
@@ -872,11 +877,21 @@ func (this *NodeService) FindAllEnabledNodesDNSWithClusterId(ctx context.Context
return nil, err
}
routeName := ""
for _, r := range routes {
if r.Code == route {
routeName = r.Name
}
}
result = append(result, &pb.NodeDNSInfo{
Id: int64(node.Id),
Name: node.Name,
IpAddr: ipAddr,
Route: route,
Route: &pb.DNSRoute{
Name: routeName,
Code: route,
},
})
}
return &pb.FindAllEnabledNodesDNSWithClusterIdResponse{Nodes: result}, nil
@@ -915,11 +930,17 @@ func (this *NodeService) FindEnabledNodeDNS(ctx context.Context, req *pb.FindEna
}
var route = ""
var routeName = ""
if dnsDomainId > 0 {
route, err = node.DNSRoute(dnsDomainId)
if err != nil {
return nil, err
}
routeName, err = models.SharedDNSDomainDAO.FindDomainRouteName(dnsDomainId, route)
if err != nil {
return nil, err
}
}
ipAddr, err := models.SharedNodeIPAddressDAO.FindFirstNodeIPAddress(int64(node.Id))
@@ -929,10 +950,13 @@ func (this *NodeService) FindEnabledNodeDNS(ctx context.Context, req *pb.FindEna
return &pb.FindEnabledNodeDNSResponse{
Node: &pb.NodeDNSInfo{
Id: int64(node.Id),
Name: node.Name,
IpAddr: ipAddr,
Route: route,
Id: int64(node.Id),
Name: node.Name,
IpAddr: ipAddr,
Route: &pb.DNSRoute{
Name: routeName,
Code: route,
},
ClusterId: clusterId,
DnsDomainId: dnsDomainId,
DnsDomainName: dnsDomainName,

View File

@@ -515,5 +515,6 @@ func (this *NodeClusterService) CheckNodeClusterDNSChanges(ctx context.Context,
if err != nil {
return nil, err
}
return &pb.CheckNodeClusterDNSChangesResponse{IsChanged: len(changes) > 0}, nil
}