mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-08 02:20:24 +08:00
DNS支持TSIG
This commit is contained in:
@@ -108,6 +108,7 @@ func (this *NSDomainService) FindEnabledNSDomain(ctx context.Context, req *pb.Fi
|
||||
Id: int64(domain.Id),
|
||||
Name: domain.Name,
|
||||
IsOn: domain.IsOn == 1,
|
||||
TsigJSON: []byte(domain.Tsig),
|
||||
CreatedAt: int64(domain.CreatedAt),
|
||||
NsCluster: &pb.NSCluster{
|
||||
Id: int64(cluster.Id),
|
||||
@@ -179,6 +180,7 @@ func (this *NSDomainService) ListEnabledNSDomains(ctx context.Context, req *pb.L
|
||||
Name: domain.Name,
|
||||
IsOn: domain.IsOn == 1,
|
||||
CreatedAt: int64(domain.CreatedAt),
|
||||
TsigJSON: []byte(domain.Tsig),
|
||||
NsCluster: &pb.NSCluster{
|
||||
Id: int64(cluster.Id),
|
||||
IsOn: cluster.IsOn == 1,
|
||||
@@ -200,7 +202,10 @@ func (this *NSDomainService) ListNSDomainsAfterVersion(ctx context.Context, req
|
||||
|
||||
// 集群ID
|
||||
var tx = this.NullTx()
|
||||
domains, err := nameservers.SharedNSDomainDAO.ListDomainsAfterVersion(tx, req.Version, 2000)
|
||||
if req.Size <= 0 {
|
||||
req.Size = 2000
|
||||
}
|
||||
domains, err := nameservers.SharedNSDomainDAO.ListDomainsAfterVersion(tx, req.Version, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -213,9 +218,40 @@ func (this *NSDomainService) ListNSDomainsAfterVersion(ctx context.Context, req
|
||||
IsOn: domain.IsOn == 1,
|
||||
IsDeleted: domain.State == nameservers.NSDomainStateDisabled,
|
||||
Version: int64(domain.Version),
|
||||
TsigJSON: []byte(domain.Tsig),
|
||||
NsCluster: &pb.NSCluster{Id: int64(domain.ClusterId)},
|
||||
User: nil,
|
||||
})
|
||||
}
|
||||
return &pb.ListNSDomainsAfterVersionResponse{NsDomains: pbDomains}, nil
|
||||
}
|
||||
|
||||
// FindEnabledNSDomainTSIG 查找TSIG配置
|
||||
func (this *NSDomainService) FindEnabledNSDomainTSIG(ctx context.Context, req *pb.FindEnabledNSDomainTSIGRequest) (*pb.FindEnabledNSDomainTSIGResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
tsig, err := nameservers.SharedNSDomainDAO.FindEnabledDomainTSIG(tx, req.NsDomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.FindEnabledNSDomainTSIGResponse{TsigJSON: tsig}, nil
|
||||
}
|
||||
|
||||
// UpdateNSDomainTSIG 修改TSIG配置
|
||||
func (this *NSDomainService) UpdateNSDomainTSIG(ctx context.Context, req *pb.UpdateNSDomainTSIGRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateAdmin(ctx, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
err = nameservers.SharedNSDomainDAO.UpdateDomainTSIG(tx, req.NsDomainId, req.TsigJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
@@ -125,3 +125,46 @@ func (this *NSKeyService) ListEnabledNSKeys(ctx context.Context, req *pb.ListEna
|
||||
}
|
||||
return &pb.ListEnabledNSKeysResponse{NsKeys: pbKeys}, nil
|
||||
}
|
||||
|
||||
// ListNSKeysAfterVersion 根据版本列出一组密钥
|
||||
func (this *NSKeyService) ListNSKeysAfterVersion(ctx context.Context, req *pb.ListNSKeysAfterVersionRequest) (*pb.ListNSKeysAfterVersionResponse, error) {
|
||||
_, err := this.ValidateNSNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
if req.Size <= 0 {
|
||||
req.Size = 2000
|
||||
}
|
||||
keys, err := nameservers.SharedNSKeyDAO.ListKeysAfterVersion(tx, req.Version, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var pbKeys = []*pb.NSKey{}
|
||||
for _, key := range keys {
|
||||
var pbDomain *pb.NSDomain
|
||||
var pbZone *pb.NSZone
|
||||
|
||||
if key.DomainId > 0 {
|
||||
pbDomain = &pb.NSDomain{Id: int64(key.DomainId)}
|
||||
}
|
||||
if key.ZoneId > 0 {
|
||||
pbZone = &pb.NSZone{Id: int64(key.ZoneId)}
|
||||
}
|
||||
|
||||
pbKeys = append(pbKeys, &pb.NSKey{
|
||||
Id: int64(key.Id),
|
||||
IsOn: key.IsOn == 1,
|
||||
Name: "",
|
||||
Algo: key.Algo,
|
||||
Secret: key.Secret,
|
||||
SecretType: key.SecretType,
|
||||
IsDeleted: key.State == nameservers.NSKeyStateDisabled,
|
||||
Version: int64(key.Version),
|
||||
NsDomain: pbDomain,
|
||||
NsZone: pbZone,
|
||||
})
|
||||
}
|
||||
return &pb.ListNSKeysAfterVersionResponse{NsKeys: pbKeys}, nil
|
||||
}
|
||||
|
||||
@@ -193,7 +193,10 @@ func (this *NSRecordService) ListNSRecordsAfterVersion(ctx context.Context, req
|
||||
|
||||
// 集群ID
|
||||
var tx = this.NullTx()
|
||||
records, err := nameservers.SharedNSRecordDAO.ListRecordsAfterVersion(tx, req.Version, 2000)
|
||||
if req.Size <= 0 {
|
||||
req.Size = 2000
|
||||
}
|
||||
records, err := nameservers.SharedNSRecordDAO.ListRecordsAfterVersion(tx, req.Version, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user