节点增加DNS解析库类型设置

This commit is contained in:
刘祥超
2022-05-04 16:41:28 +08:00
parent 8a95f49f8f
commit 549f418b69
8 changed files with 174 additions and 13 deletions

View File

@@ -3,8 +3,10 @@
package system
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node/nodeutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
@@ -32,6 +34,22 @@ func (this *IndexAction) RunGet(params struct {
var nodeMap = this.Data["node"].(maps.Map)
nodeMap["maxCPU"] = node.MaxCPU
// DNS
dnsResolverResp, err := this.RPC().NodeRPC().FindNodeDNSResolver(this.AdminContext(), &pb.FindNodeDNSResolverRequest{NodeId: params.NodeId})
if err != nil {
this.ErrorPage(err)
return
}
var dnsResolverConfig = nodeconfigs.DefaultDNSResolverConfig()
if len(dnsResolverResp.DnsResolverJSON) > 0 {
err = json.Unmarshal(dnsResolverResp.DnsResolverJSON, dnsResolverConfig)
if err != nil {
this.ErrorPage(err)
return
}
}
this.Data["dnsResolverConfig"] = dnsResolverConfig
this.Show()
}
@@ -39,6 +57,8 @@ func (this *IndexAction) RunPost(params struct {
NodeId int64
MaxCPU int32
DnsResolverJSON []byte
Must *actions.Must
CSRF *actionutils.CSRF
}) {
@@ -57,5 +77,26 @@ func (this *IndexAction) RunPost(params struct {
return
}
var dnsResolverConfig = nodeconfigs.DefaultDNSResolverConfig()
err = json.Unmarshal(params.DnsResolverJSON, dnsResolverConfig)
if err != nil {
this.ErrorPage(err)
return
}
err = dnsResolverConfig.Init()
if err != nil {
this.Fail("校验DNS解析配置失败" + err.Error())
}
_, err = this.RPC().NodeRPC().UpdateNodeDNSResolver(this.AdminContext(), &pb.UpdateNodeDNSResolverRequest{
NodeId: params.NodeId,
DnsResolverJSON: params.DnsResolverJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}