mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-08 03:00:26 +08:00
增加支持服务CNAME选项/提供重新生成服务CNAME API
This commit is contained in:
@@ -721,6 +721,10 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap maps.M
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
config.Servers = append(config.Servers, serverConfig)
|
config.Servers = append(config.Servers, serverConfig)
|
||||||
|
|
||||||
|
if server.IsOn == 1 && server.SupportCNAME == 1 {
|
||||||
|
config.SupportCNAME = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全局设置
|
// 全局设置
|
||||||
|
|||||||
@@ -472,10 +472,26 @@ func (this *ServerDAO) UpdateServerWeb(tx *dbs.Tx, serverId int64, webId int64)
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateServerDNS 修改DNS设置
|
||||||
|
func (this *ServerDAO) UpdateServerDNS(tx *dbs.Tx, serverId int64, supportCNAME bool) error {
|
||||||
|
if serverId <= 0 {
|
||||||
|
return errors.New("invalid serverId")
|
||||||
|
}
|
||||||
|
var op = NewServerOperator()
|
||||||
|
op.Id = serverId
|
||||||
|
op.SupportCNAME = supportCNAME
|
||||||
|
err := this.Save(tx, op)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.NotifyUpdate(tx, serverId)
|
||||||
|
}
|
||||||
|
|
||||||
// InitServerWeb 初始化Web配置
|
// InitServerWeb 初始化Web配置
|
||||||
func (this *ServerDAO) InitServerWeb(tx *dbs.Tx, serverId int64) (int64, error) {
|
func (this *ServerDAO) InitServerWeb(tx *dbs.Tx, serverId int64) (int64, error) {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return 0, errors.New("serverId should not be smaller than 0")
|
return 0, errors.New("invalid serverId")
|
||||||
}
|
}
|
||||||
|
|
||||||
adminId, userId, err := this.FindServerAdminIdAndUserId(tx, serverId)
|
adminId, userId, err := this.FindServerAdminIdAndUserId(tx, serverId)
|
||||||
@@ -859,6 +875,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, cacheMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CNAME
|
// CNAME
|
||||||
|
config.SupportCNAME = server.SupportCNAME == 1
|
||||||
if server.ClusterId > 0 && len(server.DnsName) > 0 {
|
if server.ClusterId > 0 && len(server.DnsName) > 0 {
|
||||||
clusterDNS, err := SharedNodeClusterDAO.FindClusterDNSInfo(tx, int64(server.ClusterId), cacheMap)
|
clusterDNS, err := SharedNodeClusterDAO.FindClusterDNSInfo(tx, int64(server.ClusterId), cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1236,6 +1253,18 @@ func (this *ServerDAO) FindServerDNSName(tx *dbs.Tx, serverId int64) (string, er
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindServerSupportCNAME 查询服务是否支持CNAME
|
||||||
|
func (this *ServerDAO) FindServerSupportCNAME(tx *dbs.Tx, serverId int64) (bool, error) {
|
||||||
|
supportCNAME, err := this.Query(tx).
|
||||||
|
Pk(serverId).
|
||||||
|
Result("supportCNAME").
|
||||||
|
FindIntCol(0)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return supportCNAME == 1, nil
|
||||||
|
}
|
||||||
|
|
||||||
// FindStatelessServerDNS 查询服务的DNS相关信息,并且不关注状态
|
// FindStatelessServerDNS 查询服务的DNS相关信息,并且不关注状态
|
||||||
func (this *ServerDAO) FindStatelessServerDNS(tx *dbs.Tx, serverId int64) (*Server, error) {
|
func (this *ServerDAO) FindStatelessServerDNS(tx *dbs.Tx, serverId int64) (*Server, error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ type Server struct {
|
|||||||
DnsName string `field:"dnsName"` // DNS名称
|
DnsName string `field:"dnsName"` // DNS名称
|
||||||
TcpPorts string `field:"tcpPorts"` // 所包含TCP端口
|
TcpPorts string `field:"tcpPorts"` // 所包含TCP端口
|
||||||
UdpPorts string `field:"udpPorts"` // 所包含UDP端口
|
UdpPorts string `field:"udpPorts"` // 所包含UDP端口
|
||||||
|
SupportCNAME uint8 `field:"supportCNAME"` // 允许CNAME不在域名名单
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerOperator struct {
|
type ServerOperator struct {
|
||||||
@@ -67,6 +68,7 @@ type ServerOperator struct {
|
|||||||
DnsName interface{} // DNS名称
|
DnsName interface{} // DNS名称
|
||||||
TcpPorts interface{} // 所包含TCP端口
|
TcpPorts interface{} // 所包含TCP端口
|
||||||
UdpPorts interface{} // 所包含UDP端口
|
UdpPorts interface{} // 所包含UDP端口
|
||||||
|
SupportCNAME interface{} // 允许CNAME不在域名名单
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServerOperator() *ServerOperator {
|
func NewServerOperator() *ServerOperator {
|
||||||
|
|||||||
@@ -468,6 +468,37 @@ func (this *ServerService) UpdateServerNamesAuditing(ctx context.Context, req *p
|
|||||||
return this.Success()
|
return this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateServerDNS 修改服务的DNS相关设置
|
||||||
|
func (this *ServerService) UpdateServerDNS(ctx context.Context, req *pb.UpdateServerDNSRequest) (*pb.RPCSuccess, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
err = models.SharedServerDAO.UpdateServerDNS(tx, req.ServerId, req.SupportCNAME)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegenerateServerCNAME 重新生成CNAME
|
||||||
|
func (this *ServerService) RegenerateServerCNAME(ctx context.Context, req *pb.RegenerateServerCNAMERequest) (*pb.RPCSuccess, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
_, err = models.SharedServerDAO.GenerateServerDNSName(tx, req.ServerId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return this.Success()
|
||||||
|
}
|
||||||
|
|
||||||
// CountAllEnabledServersMatch 计算服务数量
|
// CountAllEnabledServersMatch 计算服务数量
|
||||||
func (this *ServerService) CountAllEnabledServersMatch(ctx context.Context, req *pb.CountAllEnabledServersMatchRequest) (*pb.RPCCountResponse, error) {
|
func (this *ServerService) CountAllEnabledServersMatch(ctx context.Context, req *pb.CountAllEnabledServersMatchRequest) (*pb.RPCCountResponse, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
@@ -712,6 +743,7 @@ func (this *ServerService) FindEnabledServer(ctx context.Context, req *pb.FindEn
|
|||||||
Name: server.Name,
|
Name: server.Name,
|
||||||
Description: server.Description,
|
Description: server.Description,
|
||||||
DnsName: server.DnsName,
|
DnsName: server.DnsName,
|
||||||
|
SupportCNAME: server.SupportCNAME == 1,
|
||||||
Config: configJSON,
|
Config: configJSON,
|
||||||
ServerNamesJSON: []byte(server.ServerNames),
|
ServerNamesJSON: []byte(server.ServerNames),
|
||||||
HttpJSON: []byte(server.Http),
|
HttpJSON: []byte(server.Http),
|
||||||
@@ -1065,6 +1097,11 @@ func (this *ServerService) FindEnabledServerDNS(ctx context.Context, req *pb.Fin
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
supportCNAME, err := models.SharedServerDAO.FindServerSupportCNAME(tx, req.ServerId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
clusterId, err := models.SharedServerDAO.FindServerClusterId(tx, req.ServerId)
|
clusterId, err := models.SharedServerDAO.FindServerClusterId(tx, req.ServerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1095,6 +1132,7 @@ func (this *ServerService) FindEnabledServerDNS(ctx context.Context, req *pb.Fin
|
|||||||
return &pb.FindEnabledServerDNSResponse{
|
return &pb.FindEnabledServerDNSResponse{
|
||||||
DnsName: dnsName,
|
DnsName: dnsName,
|
||||||
Domain: pbDomain,
|
Domain: pbDomain,
|
||||||
|
SupportCNAME: supportCNAME,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user