-
Notifications
You must be signed in to change notification settings - Fork 5
/
updateClusterPopup.go
131 lines (115 loc) · 3.68 KB
/
updateClusterPopup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package dns
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
// UpdateClusterPopupAction 修改集群的DNS设置
type UpdateClusterPopupAction struct {
actionutils.ParentAction
}
func (this *UpdateClusterPopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdateClusterPopupAction) RunGet(params struct {
ClusterId int64
}) {
this.Data["clusterId"] = params.ClusterId
dnsInfoResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterDNS(this.AdminContext(), &pb.FindEnabledNodeClusterDNSRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["dnsName"] = dnsInfoResp.Name
this.Data["nodesAutoSync"] = dnsInfoResp.NodesAutoSync
this.Data["serversAutoSync"] = dnsInfoResp.ServersAutoSync
if dnsInfoResp.Domain != nil {
this.Data["domainId"] = dnsInfoResp.Domain.Id
this.Data["domain"] = dnsInfoResp.Domain.Name
} else {
this.Data["domainId"] = 0
this.Data["domain"] = ""
}
if dnsInfoResp.Provider != nil {
this.Data["providerType"] = dnsInfoResp.Provider.Type
this.Data["providerId"] = dnsInfoResp.Provider.Id
} else {
this.Data["providerType"] = ""
this.Data["providerId"] = 0
}
if len(dnsInfoResp.CnameRecords) == 0 {
this.Data["cnameRecords"] = []string{}
} else {
this.Data["cnameRecords"] = dnsInfoResp.CnameRecords
}
this.Data["ttl"] = dnsInfoResp.Ttl
this.Data["cnameAsDomain"] = dnsInfoResp.CnameAsDomain
this.Data["includingLnNodes"] = dnsInfoResp.IncludingLnNodes
// 所有服务商
providerTypesResp, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.AdminContext(), &pb.FindAllDNSProviderTypesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
providerTypeMaps := []maps.Map{}
for _, providerType := range providerTypesResp.ProviderTypes {
providerTypeMaps = append(providerTypeMaps, maps.Map{
"name": providerType.Name,
"code": providerType.Code,
})
}
this.Data["providerTypes"] = providerTypeMaps
this.Show()
}
func (this *UpdateClusterPopupAction) RunPost(params struct {
ClusterId int64
DnsName string
DomainId int64
NodesAutoSync bool
ServersAutoSync bool
CnameRecords []string
Ttl int32
CnameAsDomain bool
IncludingLnNodes bool
Must *actions.Must
CSRF *actionutils.CSRF
}) {
// 日志
defer this.CreateLogInfo(codes.DNS_LogUpdateClusterDNS, params.ClusterId)
params.Must.
Field("dnsName", params.DnsName).
Require("请输入子域名")
if !domainutils.ValidateDomainFormat(params.DnsName) {
this.FailField("dnsName", "子域名格式错误")
}
checkResp, err := this.RPC().NodeClusterRPC().CheckNodeClusterDNSName(this.AdminContext(), &pb.CheckNodeClusterDNSNameRequest{
NodeClusterId: params.ClusterId,
DnsName: params.DnsName,
})
if err != nil {
this.ErrorPage(err)
return
}
if checkResp.IsUsed {
this.FailField("dnsName", "此子域名已经被占用,请修改后重新提交")
}
_, err = this.RPC().NodeClusterRPC().UpdateNodeClusterDNS(this.AdminContext(), &pb.UpdateNodeClusterDNSRequest{
NodeClusterId: params.ClusterId,
DnsName: params.DnsName,
DnsDomainId: params.DomainId,
NodesAutoSync: params.NodesAutoSync,
ServersAutoSync: params.ServersAutoSync,
CnameRecords: params.CnameRecords,
Ttl: params.Ttl,
CnameAsDomain: params.CnameAsDomain,
IncludingLnNodes: params.IncludingLnNodes,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}