mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 18:10:25 +08:00
增加DNS域名管理
This commit is contained in:
170
internal/db/models/dns_domain_dao.go
Normal file
170
internal/db/models/dns_domain_dao.go
Normal file
@@ -0,0 +1,170 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
const (
|
||||
DNSDomainStateEnabled = 1 // 已启用
|
||||
DNSDomainStateDisabled = 0 // 已禁用
|
||||
)
|
||||
|
||||
type DNSDomainDAO dbs.DAO
|
||||
|
||||
func NewDNSDomainDAO() *DNSDomainDAO {
|
||||
return dbs.NewDAO(&DNSDomainDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeDNSDomains",
|
||||
Model: new(DNSDomain),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*DNSDomainDAO)
|
||||
}
|
||||
|
||||
var SharedDNSDomainDAO *DNSDomainDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedDNSDomainDAO = NewDNSDomainDAO()
|
||||
})
|
||||
}
|
||||
|
||||
// 启用条目
|
||||
func (this *DNSDomainDAO) EnableDNSDomain(id int64) error {
|
||||
_, err := this.Query().
|
||||
Pk(id).
|
||||
Set("state", DNSDomainStateEnabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
func (this *DNSDomainDAO) DisableDNSDomain(id int64) error {
|
||||
_, err := this.Query().
|
||||
Pk(id).
|
||||
Set("state", DNSDomainStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
func (this *DNSDomainDAO) FindEnabledDNSDomain(id int64) (*DNSDomain, error) {
|
||||
result, err := this.Query().
|
||||
Pk(id).
|
||||
Attr("state", DNSDomainStateEnabled).
|
||||
Find()
|
||||
if result == nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.(*DNSDomain), err
|
||||
}
|
||||
|
||||
// 根据主键查找名称
|
||||
func (this *DNSDomainDAO) FindDNSDomainName(id int64) (string, error) {
|
||||
return this.Query().
|
||||
Pk(id).
|
||||
Result("name").
|
||||
FindStringCol("")
|
||||
}
|
||||
|
||||
// 创建域名
|
||||
func (this *DNSDomainDAO) CreateDomain(providerId int64, name string) (int64, error) {
|
||||
op := NewDNSDomainOperator()
|
||||
op.ProviderId = providerId
|
||||
op.Name = name
|
||||
op.State = DNSDomainStateEnabled
|
||||
op.IsOn = true
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
// 修改域名
|
||||
func (this *DNSDomainDAO) UpdateDomain(domainId int64, name string, isOn bool) error {
|
||||
if domainId <= 0 {
|
||||
return errors.New("invalid domainId")
|
||||
}
|
||||
op := NewDNSDomainOperator()
|
||||
op.Id = domainId
|
||||
op.Name = name
|
||||
op.IsOn = isOn
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 查询一个服务商下面的所有域名
|
||||
func (this *DNSDomainDAO) FindAllEnabledDomainsWithProviderId(providerId int64) (result []*DNSDomain, err error) {
|
||||
_, err = this.Query().
|
||||
State(DNSDomainStateEnabled).
|
||||
Attr("providerId", providerId).
|
||||
AscPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
// 计算某个服务商下的域名数量
|
||||
func (this *DNSDomainDAO) CountAllEnabledDomainsWithProviderId(providerId int64) (int64, error) {
|
||||
return this.Query().
|
||||
State(DNSDomainStateEnabled).
|
||||
Attr("providerId", providerId).
|
||||
Count()
|
||||
}
|
||||
|
||||
// 更新域名数据
|
||||
func (this *DNSDomainDAO) UpdateDomainData(domainId int64, data string) error {
|
||||
if domainId <= 0 {
|
||||
return errors.New("invalid domainId")
|
||||
}
|
||||
op := NewDNSDomainOperator()
|
||||
op.Id = domainId
|
||||
op.Data = data
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新服务相关域名
|
||||
func (this *DNSDomainDAO) UpdateServerDomains(domainId int64, serverDomainsJSON []byte) error {
|
||||
if domainId <= 0 {
|
||||
return errors.New("invalid domainId")
|
||||
}
|
||||
op := NewDNSDomainOperator()
|
||||
op.Id = domainId
|
||||
op.ServerDomains = serverDomainsJSON
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新集群相关域名
|
||||
func (this *DNSDomainDAO) UpdateClusterDomains(domainId int64, clusterDomainJSON []byte) error {
|
||||
if domainId <= 0 {
|
||||
return errors.New("invalid domainId")
|
||||
}
|
||||
op := NewDNSDomainOperator()
|
||||
op.Id = domainId
|
||||
op.ClusterDomains = clusterDomainJSON
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新线路
|
||||
func (this *DNSDomainDAO) UpdateRoutes(domainId int64, routesJSON []byte) error {
|
||||
if domainId <= 0 {
|
||||
return errors.New("invalid domainId")
|
||||
}
|
||||
op := NewDNSDomainOperator()
|
||||
op.Id = domainId
|
||||
op.Routes = routesJSON
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
5
internal/db/models/dns_domain_dao_test.go
Normal file
5
internal/db/models/dns_domain_dao_test.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
36
internal/db/models/dns_domain_model.go
Normal file
36
internal/db/models/dns_domain_model.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package models
|
||||
|
||||
// 管理的域名
|
||||
type DNSDomain struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
ProviderId uint32 `field:"providerId"` // 服务商ID
|
||||
IsOn uint8 `field:"isOn"` // 是否可用
|
||||
Name string `field:"name"` // 域名
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
DataUpdatedAt uint64 `field:"dataUpdatedAt"` // 数据更新时间
|
||||
Data string `field:"data"` // 原始数据信息
|
||||
ServerDomains string `field:"serverDomains"` // 服务相关子域名
|
||||
ClusterDomains string `field:"clusterDomains"` // 集群相关域名
|
||||
Routes string `field:"routes"` // 线路数据
|
||||
State uint8 `field:"state"` // 状态
|
||||
}
|
||||
|
||||
type DNSDomainOperator struct {
|
||||
Id interface{} // ID
|
||||
AdminId interface{} // 管理员ID
|
||||
ProviderId interface{} // 服务商ID
|
||||
IsOn interface{} // 是否可用
|
||||
Name interface{} // 域名
|
||||
CreatedAt interface{} // 创建时间
|
||||
DataUpdatedAt interface{} // 数据更新时间
|
||||
Data interface{} // 原始数据信息
|
||||
ServerDomains interface{} // 服务相关子域名
|
||||
ClusterDomains interface{} // 集群相关域名
|
||||
Routes interface{} // 线路数据
|
||||
State interface{} // 状态
|
||||
}
|
||||
|
||||
func NewDNSDomainOperator() *DNSDomainOperator {
|
||||
return &DNSDomainOperator{}
|
||||
}
|
||||
1
internal/db/models/dns_domain_model_ext.go
Normal file
1
internal/db/models/dns_domain_model_ext.go
Normal file
@@ -0,0 +1 @@
|
||||
package models
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -66,18 +65,14 @@ func (this *DNSProviderDAO) FindEnabledDNSProvider(id int64) (*DNSProvider, erro
|
||||
}
|
||||
|
||||
// 创建服务商
|
||||
func (this *DNSProviderDAO) CreateDNSProvider(providerType string, name string, apiParamsJSON []byte, routesJSON []byte) (int64, error) {
|
||||
func (this *DNSProviderDAO) CreateDNSProvider(providerType string, name string, apiParamsJSON []byte) (int64, error) {
|
||||
op := NewDNSProviderOperator()
|
||||
op.Type = providerType
|
||||
op.Name = name
|
||||
if len(apiParamsJSON) > 0 {
|
||||
op.ApiParams = apiParamsJSON
|
||||
}
|
||||
if len(routesJSON) > 0 {
|
||||
op.Routes = routesJSON
|
||||
}
|
||||
op.State = DNSProviderStateEnabled
|
||||
op.DataUpdatedAt = time.Now().Unix()
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -86,7 +81,7 @@ func (this *DNSProviderDAO) CreateDNSProvider(providerType string, name string,
|
||||
}
|
||||
|
||||
// 修改服务商
|
||||
func (this *DNSProviderDAO) UpdateDNSProvider(dnsProviderId int64, name string, apiParamsJSON []byte, routesJSON []byte) error {
|
||||
func (this *DNSProviderDAO) UpdateDNSProvider(dnsProviderId int64, name string, apiParamsJSON []byte) error {
|
||||
if dnsProviderId <= 0 {
|
||||
return errors.New("invalid dnsProviderId")
|
||||
}
|
||||
@@ -100,12 +95,6 @@ func (this *DNSProviderDAO) UpdateDNSProvider(dnsProviderId int64, name string,
|
||||
op.ApiParams = apiParamsJSON
|
||||
}
|
||||
|
||||
// 如果留空则表示不修改
|
||||
if len(routesJSON) > 0 {
|
||||
op.Routes = routesJSON
|
||||
}
|
||||
|
||||
op.DataUpdatedAt = time.Now().Unix()
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -9,7 +9,6 @@ type DNSProvider struct {
|
||||
ApiParams string `field:"apiParams"` // API参数
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
State uint8 `field:"state"` // 状态
|
||||
Routes string `field:"routes"` // 可以使用的线路
|
||||
DataUpdatedAt uint64 `field:"dataUpdatedAt"` // 数据同步时间
|
||||
}
|
||||
|
||||
@@ -21,7 +20,6 @@ type DNSProviderOperator struct {
|
||||
ApiParams interface{} // API参数
|
||||
CreatedAt interface{} // 创建时间
|
||||
State interface{} // 状态
|
||||
Routes interface{} // 可以使用的线路
|
||||
DataUpdatedAt interface{} // 数据同步时间
|
||||
}
|
||||
|
||||
|
||||
@@ -272,7 +272,8 @@ func (this *NodeClusterDAO) FindAllEnabledClustersWithGrantId(grantId int64) (re
|
||||
func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSProviderId(dnsProviderId int64) (int64, error) {
|
||||
return this.Query().
|
||||
State(NodeClusterStateEnabled).
|
||||
Attr("dnsProviderId", dnsProviderId).
|
||||
Where("dnsDomainId IN (SELECT id FROM "+SharedDNSDomainDAO.Table+" WHERE state=1 AND providerId=:providerId)").
|
||||
Param("providerId", dnsProviderId).
|
||||
Count()
|
||||
}
|
||||
|
||||
@@ -280,13 +281,22 @@ func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSProviderId(dnsProvider
|
||||
func (this *NodeClusterDAO) FindAllEnabledClustersWithDNSProviderId(dnsProviderId int64) (result []*NodeCluster, err error) {
|
||||
_, err = this.Query().
|
||||
State(NodeClusterStateEnabled).
|
||||
Attr("dnsProviderId", dnsProviderId).
|
||||
Where("dnsDomainId IN (SELECT id FROM "+SharedDNSDomainDAO.Table+" WHERE state=1 AND providerId=:providerId)").
|
||||
Param("providerId", dnsProviderId).
|
||||
Slice(&result).
|
||||
DescPk().
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
// 计算使用某个DNS域名的集群数量
|
||||
func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSDomainId(dnsDomainId int64) (int64, error) {
|
||||
return this.Query().
|
||||
State(NodeClusterStateEnabled).
|
||||
Attr("dnsDomainId", dnsDomainId).
|
||||
Count()
|
||||
}
|
||||
|
||||
// 查找集群的认证ID
|
||||
func (this *NodeClusterDAO) FindClusterGrantId(clusterId int64) (int64, error) {
|
||||
return this.Query().
|
||||
|
||||
@@ -17,9 +17,8 @@ type NodeCluster struct {
|
||||
UniqueId string `field:"uniqueId"` // 唯一ID
|
||||
Secret string `field:"secret"` // 密钥
|
||||
HealthCheck string `field:"healthCheck"` // 健康检查
|
||||
DnsProviderId uint32 `field:"dnsProviderId"` // 当前使用的DNS供应商
|
||||
DnsName string `field:"dnsName"` // DNS名称
|
||||
DnsDomain string `field:"dnsDomain"` // DNS域
|
||||
DnsDomainId uint32 `field:"dnsDomainId"` // 域名ID
|
||||
}
|
||||
|
||||
type NodeClusterOperator struct {
|
||||
@@ -38,9 +37,8 @@ type NodeClusterOperator struct {
|
||||
UniqueId interface{} // 唯一ID
|
||||
Secret interface{} // 密钥
|
||||
HealthCheck interface{} // 健康检查
|
||||
DnsProviderId interface{} // 当前使用的DNS供应商
|
||||
DnsName interface{} // DNS名称
|
||||
DnsDomain interface{} // DNS域
|
||||
DnsDomainId interface{} // 域名ID
|
||||
}
|
||||
|
||||
func NewNodeClusterOperator() *NodeClusterOperator {
|
||||
|
||||
106
internal/dnsproviders/provider_dnspod.go
Normal file
106
internal/dnsproviders/provider_dnspod.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package dnsproviders
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DNSPodProvider struct {
|
||||
apiId string
|
||||
apiToken string
|
||||
}
|
||||
|
||||
// 认证
|
||||
func (this *DNSPodProvider) Auth(params maps.Map) error {
|
||||
this.apiId = params.GetString("id")
|
||||
this.apiToken = params.GetString("token")
|
||||
|
||||
if len(this.apiId) == 0 {
|
||||
return errors.New("'id' should be not empty")
|
||||
}
|
||||
if len(this.apiToken) == 0 {
|
||||
return errors.New("'token' should not be empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 读取线路数据
|
||||
func (this *DNSPodProvider) GetRoutes(domain string) ([][]string, error) {
|
||||
infoResp, err := this.post("/Domain.info", map[string]string{
|
||||
"domain": domain,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
domainInfo := infoResp.GetMap("domain")
|
||||
grade := domainInfo.GetString("grade")
|
||||
|
||||
linesResp, err := this.post("/Record.Line", map[string]string{
|
||||
"domain": domain,
|
||||
"domain_grade": grade,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lines := linesResp.GetSlice("lines")
|
||||
if len(lines) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
lineStrings := []string{}
|
||||
for _, line := range lines {
|
||||
lineStrings = append(lineStrings, types.String(line))
|
||||
}
|
||||
|
||||
return [][]string{lineStrings}, nil
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
func (this *DNSPodProvider) post(path string, params map[string]string) (maps.Map, error) {
|
||||
apiHost := "https://dnsapi.cn"
|
||||
query := url.Values{
|
||||
"login_token": []string{this.apiId + "," + this.apiToken},
|
||||
"format": []string{"json"},
|
||||
}
|
||||
for p, v := range params {
|
||||
query[p] = []string{v}
|
||||
}
|
||||
req, err := http.NewRequest(http.MethodPost, apiHost+path, strings.NewReader(query.Encode()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Set("User-Agent", "GoEdge Client/1.0.0 (iwind.liu@gmail.com)")
|
||||
|
||||
client := http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
client.CloseIdleConnections()
|
||||
}()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m := maps.Map{}
|
||||
err = json.Unmarshal(body, &m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
status := m.GetMap("status")
|
||||
code := status.GetString("code")
|
||||
if code != "1" {
|
||||
return nil, errors.New("code: " + code + ", message: " + status.GetString("message"))
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
22
internal/dnsproviders/provider_dnspod_test.go
Normal file
22
internal/dnsproviders/provider_dnspod_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package dnsproviders
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDNSPodProvider_GetRoutes(t *testing.T) {
|
||||
provider := &DNSPodProvider{}
|
||||
err := provider.Auth(maps.Map{
|
||||
"id": "191996",
|
||||
"token": "366964e0f8ed4d8990a7f5d4b3cdec60",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
routes, err := provider.GetRoutes("yun4s.cn")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(routes)
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
package dnsproviders
|
||||
|
||||
import "github.com/iwind/TeaGo/maps"
|
||||
|
||||
// DNS操作接口
|
||||
type ProviderInterface interface {
|
||||
// 检查账号
|
||||
// 认证
|
||||
Auth(params maps.Map) error
|
||||
|
||||
// 读取线路数据
|
||||
GetRoutes(domain string) ([][]string, error)
|
||||
}
|
||||
|
||||
@@ -4,15 +4,27 @@ import "github.com/iwind/TeaGo/maps"
|
||||
|
||||
type ProviderType = string
|
||||
|
||||
// 服务商代号
|
||||
const (
|
||||
ProviderTypeDNSPod ProviderType = "dnspod"
|
||||
ProviderTypeAliyun ProviderType = "aliyun"
|
||||
ProviderTypeDNSCom ProviderType = "dnscom"
|
||||
)
|
||||
|
||||
// 所有的服务商类型
|
||||
var AllProviderTypes = []maps.Map{
|
||||
{
|
||||
"name": "DNSPod",
|
||||
"code": ProviderTypeDNSPod,
|
||||
},
|
||||
{
|
||||
"name": "阿里云",
|
||||
"code": ProviderTypeAliyun,
|
||||
},
|
||||
{
|
||||
"name": "帝恩思",
|
||||
"code": ProviderTypeDNSCom,
|
||||
},
|
||||
}
|
||||
|
||||
func FindProviderTypeName(providerType string) string {
|
||||
|
||||
@@ -182,6 +182,7 @@ func (this *APINode) listenRPC(listener net.Listener, tlsConfig *tls.Config) err
|
||||
pb.RegisterIPItemServiceServer(rpcServer, &services.IPItemService{})
|
||||
pb.RegisterLogServiceServer(rpcServer, &services.LogService{})
|
||||
pb.RegisterDNSProviderServiceServer(rpcServer, &services.DNSProviderService{})
|
||||
pb.RegisterDNSDomainServiceServer(rpcServer, &services.DNSDomainService{})
|
||||
err := rpcServer.Serve(listener)
|
||||
if err != nil {
|
||||
return errors.New("[API]start rpc failed: " + err.Error())
|
||||
|
||||
@@ -94,7 +94,7 @@ func (this *APINodeService) FindAllEnabledAPINodes(ctx context.Context, req *pb.
|
||||
}
|
||||
|
||||
// 计算API节点数量
|
||||
func (this *APINodeService) CountAllEnabledAPINodes(ctx context.Context, req *pb.CountAllEnabledAPINodesRequest) (*pb.CountAllEnabledAPINodesResponse, error) {
|
||||
func (this *APINodeService) CountAllEnabledAPINodes(ctx context.Context, req *pb.CountAllEnabledAPINodesRequest) (*pb.RPCCountResponse, error) {
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -105,7 +105,7 @@ func (this *APINodeService) CountAllEnabledAPINodes(ctx context.Context, req *pb
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.CountAllEnabledAPINodesResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页的API节点
|
||||
|
||||
@@ -55,7 +55,7 @@ func (this *DBNodeService) DeleteDBNode(ctx context.Context, req *pb.DeleteDBNod
|
||||
}
|
||||
|
||||
// 计算可用的数据库节点数量
|
||||
func (this *DBNodeService) CountAllEnabledDBNodes(ctx context.Context, req *pb.CountAllEnabledDBNodesRequest) (*pb.CountAllEnabledDBNodesResponse, error) {
|
||||
func (this *DBNodeService) CountAllEnabledDBNodes(ctx context.Context, req *pb.CountAllEnabledDBNodesRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -65,7 +65,7 @@ func (this *DBNodeService) CountAllEnabledDBNodes(ctx context.Context, req *pb.C
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledDBNodesResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页的数据库节点
|
||||
|
||||
98
internal/rpc/services/service_dns_domain.go
Normal file
98
internal/rpc/services/service_dns_domain.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
// DNS域名相关服务
|
||||
type DNSDomainService struct {
|
||||
}
|
||||
|
||||
// 创建域名
|
||||
func (this *DNSDomainService) CreateDNSDomain(ctx context.Context, req *pb.CreateDNSDomainRequest) (*pb.CreateDNSDomainResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
domainId, err := models.SharedDNSDomainDAO.CreateDomain(req.DnsProviderId, req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CreateDNSDomainResponse{DnsDomainId: domainId}, nil
|
||||
}
|
||||
|
||||
// 修改域名
|
||||
func (this *DNSDomainService) UpdateDNSDomain(ctx context.Context, req *pb.UpdateDNSDomainRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedDNSDomainDAO.UpdateDomain(req.DnsDomainId, req.Name, req.IsOn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rpcutils.RPCUpdateSuccess()
|
||||
}
|
||||
|
||||
// 删除域名
|
||||
func (this *DNSDomainService) DeleteDNSDomain(ctx context.Context, req *pb.DeleteDNSDomainRequest) (*pb.RPCDeleteSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedDNSDomainDAO.DisableDNSDomain(req.DnsDomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rpcutils.RPCDeleteSuccess()
|
||||
}
|
||||
|
||||
// 计算服务商下的域名数量
|
||||
func (this *DNSDomainService) CountAllEnabledDNSDomainsWithDNSProviderId(ctx context.Context, req *pb.CountAllEnabledDNSDomainsWithDNSProviderIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
count, err := models.SharedDNSDomainDAO.CountAllEnabledDomainsWithProviderId(req.DnsProviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出服务商下的所有域名
|
||||
func (this *DNSDomainService) FindAllEnabledDNSDomainsWithDNSProviderId(ctx context.Context, req *pb.FindAllEnabledDNSDomainsWithDNSProviderIdRequest) (*pb.FindAllEnabledDNSDomainsWithDNSProviderIdResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
domains, err := models.SharedDNSDomainDAO.FindAllEnabledDomainsWithProviderId(req.DnsProviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := []*pb.DNSDomain{}
|
||||
for _, domain := range domains {
|
||||
result = append(result, &pb.DNSDomain{
|
||||
Id: int64(domain.Id),
|
||||
Name: domain.Name,
|
||||
IsOn: domain.IsOn == 1,
|
||||
DataUpdatedAt: int64(domain.DataUpdatedAt),
|
||||
})
|
||||
}
|
||||
|
||||
return &pb.FindAllEnabledDNSDomainsWithDNSProviderIdResponse{DnsDomains: result}, nil
|
||||
}
|
||||
@@ -20,7 +20,7 @@ func (this *DNSProviderService) CreateDNSProvider(ctx context.Context, req *pb.C
|
||||
return nil, err
|
||||
}
|
||||
|
||||
providerId, err := models.SharedDNSProviderDAO.CreateDNSProvider(req.Type, req.Name, req.ApiParamsJSON, req.RoutesJSON)
|
||||
providerId, err := models.SharedDNSProviderDAO.CreateDNSProvider(req.Type, req.Name, req.ApiParamsJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func (this *DNSProviderService) UpdateDNSProvider(ctx context.Context, req *pb.U
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedDNSProviderDAO.UpdateDNSProvider(req.DnsProviderId, req.Name, req.ApiParamsJSON, req.RoutesJSON)
|
||||
err = models.SharedDNSProviderDAO.UpdateDNSProvider(req.DnsProviderId, req.Name, req.ApiParamsJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func (this *DNSProviderService) UpdateDNSProvider(ctx context.Context, req *pb.U
|
||||
}
|
||||
|
||||
// 计算服务商数量
|
||||
func (this *DNSProviderService) CountAllEnabledDNSProviders(ctx context.Context, req *pb.CountAllEnabledDNSProvidersRequest) (*pb.CountAllEnabledDNSProvidersResponse, error) {
|
||||
func (this *DNSProviderService) CountAllEnabledDNSProviders(ctx context.Context, req *pb.CountAllEnabledDNSProvidersRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -55,7 +55,7 @@ func (this *DNSProviderService) CountAllEnabledDNSProviders(ctx context.Context,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledDNSProvidersResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页服务商信息
|
||||
@@ -78,7 +78,6 @@ func (this *DNSProviderService) ListEnabledDNSProviders(ctx context.Context, req
|
||||
Type: provider.Type,
|
||||
TypeName: dnsproviders.FindProviderTypeName(provider.Type),
|
||||
ApiParamsJSON: []byte(provider.ApiParams),
|
||||
RoutesJSON: []byte(provider.Routes),
|
||||
DataUpdatedAt: int64(provider.DataUpdatedAt),
|
||||
})
|
||||
}
|
||||
@@ -122,7 +121,6 @@ func (this *DNSProviderService) FindEnabledDNSProvider(ctx context.Context, req
|
||||
Type: provider.Type,
|
||||
TypeName: dnsproviders.FindProviderTypeName(provider.Type),
|
||||
ApiParamsJSON: []byte(provider.ApiParams),
|
||||
RoutesJSON: []byte(provider.Routes),
|
||||
DataUpdatedAt: int64(provider.DataUpdatedAt),
|
||||
}}, nil
|
||||
}
|
||||
@@ -144,3 +142,16 @@ func (this *DNSProviderService) FindAllDNSProviderTypes(ctx context.Context, req
|
||||
}
|
||||
return &pb.FindAllDNSProviderTypesResponse{ProviderTypes: result}, nil
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (this *DNSProviderService) UpdateDNSProviderData(ctx context.Context, req *pb.UpdateDNSProviderDataRequest) (*pb.UpdateDNSProviderDataResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO 需要实现
|
||||
|
||||
return &pb.UpdateDNSProviderDataResponse{IsOk: true}, nil
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func (this *HTTPCachePolicyService) DeleteHTTPCachePolicy(ctx context.Context, r
|
||||
}
|
||||
|
||||
// 计算缓存策略数量
|
||||
func (this *HTTPCachePolicyService) CountAllEnabledHTTPCachePolicies(ctx context.Context, req *pb.CountAllEnabledHTTPCachePoliciesRequest) (*pb.CountAllEnabledHTTPCachePoliciesResponse, error) {
|
||||
func (this *HTTPCachePolicyService) CountAllEnabledHTTPCachePolicies(ctx context.Context, req *pb.CountAllEnabledHTTPCachePoliciesRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -93,7 +93,7 @@ func (this *HTTPCachePolicyService) CountAllEnabledHTTPCachePolicies(ctx context
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledHTTPCachePoliciesResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页的缓存策略
|
||||
|
||||
@@ -268,7 +268,7 @@ func (this *HTTPFirewallPolicyService) UpdateHTTPFirewallInboundConfig(ctx conte
|
||||
}
|
||||
|
||||
// 计算可用的防火墙策略数量
|
||||
func (this *HTTPFirewallPolicyService) CountAllEnabledFirewallPolicies(ctx context.Context, req *pb.CountAllEnabledFirewallPoliciesRequest) (*pb.CountAllEnabledFirewallPoliciesResponse, error) {
|
||||
func (this *HTTPFirewallPolicyService) CountAllEnabledFirewallPolicies(ctx context.Context, req *pb.CountAllEnabledFirewallPoliciesRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -279,7 +279,7 @@ func (this *HTTPFirewallPolicyService) CountAllEnabledFirewallPolicies(ctx conte
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledFirewallPoliciesResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页的防火墙策略
|
||||
|
||||
@@ -60,7 +60,7 @@ func (this *IPItemService) DeleteIPItem(ctx context.Context, req *pb.DeleteIPIte
|
||||
}
|
||||
|
||||
// 计算IP数量
|
||||
func (this *IPItemService) CountIPItemsWithListId(ctx context.Context, req *pb.CountIPItemsWithListIdRequest) (*pb.CountIPItemsWithListIdResponse, error) {
|
||||
func (this *IPItemService) CountIPItemsWithListId(ctx context.Context, req *pb.CountIPItemsWithListIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -71,7 +71,7 @@ func (this *IPItemService) CountIPItemsWithListId(ctx context.Context, req *pb.C
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountIPItemsWithListIdResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页的IP
|
||||
|
||||
@@ -27,7 +27,7 @@ func (this *LogService) CreateLog(ctx context.Context, req *pb.CreateLogRequest)
|
||||
}
|
||||
|
||||
// 计算日志数量
|
||||
func (this *LogService) CountLogs(ctx context.Context, req *pb.CountLogRequest) (*pb.CountLogResponse, error) {
|
||||
func (this *LogService) CountLogs(ctx context.Context, req *pb.CountLogRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -38,7 +38,7 @@ func (this *LogService) CountLogs(ctx context.Context, req *pb.CountLogRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountLogResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页日志
|
||||
|
||||
@@ -12,7 +12,7 @@ type MessageService struct {
|
||||
}
|
||||
|
||||
// 计算未读消息数
|
||||
func (this *MessageService) CountUnreadMessages(ctx context.Context, req *pb.CountUnreadMessagesRequest) (*pb.CountUnreadMessagesResponse, error) {
|
||||
func (this *MessageService) CountUnreadMessages(ctx context.Context, req *pb.CountUnreadMessagesRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -23,7 +23,7 @@ func (this *MessageService) CountUnreadMessages(ctx context.Context, req *pb.Cou
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountUnreadMessagesResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页未读消息
|
||||
|
||||
@@ -81,7 +81,7 @@ func (this *NodeService) RegisterClusterNode(ctx context.Context, req *pb.Regist
|
||||
}
|
||||
|
||||
// 计算节点数量
|
||||
func (this *NodeService) CountAllEnabledNodes(ctx context.Context, req *pb.CountAllEnabledNodesRequest) (*pb.CountAllEnabledNodesResponse, error) {
|
||||
func (this *NodeService) CountAllEnabledNodes(ctx context.Context, req *pb.CountAllEnabledNodesRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -93,11 +93,11 @@ func (this *NodeService) CountAllEnabledNodes(ctx context.Context, req *pb.Count
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.CountAllEnabledNodesResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 计算匹配的节点数量
|
||||
func (this *NodeService) CountAllEnabledNodesMatch(ctx context.Context, req *pb.CountAllEnabledNodesMatchRequest) (*pb.CountAllEnabledNodesMatchResponse, error) {
|
||||
func (this *NodeService) CountAllEnabledNodesMatch(ctx context.Context, req *pb.CountAllEnabledNodesMatchRequest) (*pb.RPCCountResponse, error) {
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -106,7 +106,7 @@ func (this *NodeService) CountAllEnabledNodesMatch(ctx context.Context, req *pb.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledNodesMatchResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页的节点
|
||||
@@ -539,7 +539,7 @@ func (this *NodeService) UpdateNodeConnectedAPINodes(ctx context.Context, req *p
|
||||
}
|
||||
|
||||
// 计算使用某个认证的节点数量
|
||||
func (this *NodeService) CountAllEnabledNodesWithGrantId(ctx context.Context, req *pb.CountAllEnabledNodesWithGrantIdRequest) (*pb.CountAllEnabledNodesWithGrantIdResponse, error) {
|
||||
func (this *NodeService) CountAllEnabledNodesWithGrantId(ctx context.Context, req *pb.CountAllEnabledNodesWithGrantIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -550,7 +550,7 @@ func (this *NodeService) CountAllEnabledNodesWithGrantId(ctx context.Context, re
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledNodesWithGrantIdResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 查找使用某个认证的所有节点
|
||||
@@ -824,7 +824,7 @@ func (this *NodeService) UpdateNodeLogin(ctx context.Context, req *pb.UpdateNode
|
||||
}
|
||||
|
||||
// 计算某个节点分组内的节点数量
|
||||
func (this *NodeService) CountAllEnabledNodesWithGroupId(ctx context.Context, req *pb.CountAllEnabledNodesWithGroupIdRequest) (*pb.CountAllEnabledNodesWithGroupIdResponse, error) {
|
||||
func (this *NodeService) CountAllEnabledNodesWithGroupId(ctx context.Context, req *pb.CountAllEnabledNodesWithGroupIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -835,5 +835,5 @@ func (this *NodeService) CountAllEnabledNodesWithGroupId(ctx context.Context, re
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledNodesWithGroupIdResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ func (this *NodeClusterService) FindAllChangedNodeClusters(ctx context.Context,
|
||||
}
|
||||
|
||||
// 计算所有集群数量
|
||||
func (this *NodeClusterService) CountAllEnabledNodeClusters(ctx context.Context, req *pb.CountAllEnabledNodeClustersRequest) (*pb.CountAllEnabledNodeClustersResponse, error) {
|
||||
func (this *NodeClusterService) CountAllEnabledNodeClusters(ctx context.Context, req *pb.CountAllEnabledNodeClustersRequest) (*pb.RPCCountResponse, error) {
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -217,7 +217,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClusters(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.CountAllEnabledNodeClustersResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页集群
|
||||
@@ -312,7 +312,7 @@ func (this *NodeClusterService) ExecuteNodeClusterHealthCheck(ctx context.Contex
|
||||
}
|
||||
|
||||
// 计算使用某个认证的集群数量
|
||||
func (this *NodeClusterService) CountAllEnabledNodeClustersWithGrantId(ctx context.Context, req *pb.CountAllEnabledNodeClustersWithGrantIdRequest) (*pb.CountAllEnabledNodeClustersWithGrantIdResponse, error) {
|
||||
func (this *NodeClusterService) CountAllEnabledNodeClustersWithGrantId(ctx context.Context, req *pb.CountAllEnabledNodeClustersWithGrantIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -323,7 +323,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClustersWithGrantId(ctx conte
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledNodeClustersWithGrantIdResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 查找使用某个认证的所有集群
|
||||
@@ -367,12 +367,36 @@ func (this *NodeClusterService) FindEnabledNodeClusterDNS(ctx context.Context, r
|
||||
if dnsInfo == nil {
|
||||
return &pb.FindEnabledNodeClusterDNSResponse{
|
||||
Name: "",
|
||||
Domain: "",
|
||||
Domain: nil,
|
||||
Provider: nil,
|
||||
}, nil
|
||||
}
|
||||
if dnsInfo.DnsDomainId == 0 {
|
||||
return &pb.FindEnabledNodeClusterDNSResponse{
|
||||
Name: dnsInfo.DnsName,
|
||||
Domain: nil,
|
||||
Provider: nil,
|
||||
}, nil
|
||||
}
|
||||
|
||||
provider, err := models.SharedDNSProviderDAO.FindEnabledDNSProvider(int64(dnsInfo.DnsProviderId))
|
||||
domain, err := models.SharedDNSDomainDAO.FindEnabledDNSDomain(int64(dnsInfo.DnsDomainId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if domain == nil {
|
||||
return &pb.FindEnabledNodeClusterDNSResponse{
|
||||
Name: dnsInfo.DnsName,
|
||||
Domain: nil,
|
||||
Provider: nil,
|
||||
}, nil
|
||||
}
|
||||
pbDomain := &pb.DNSDomain{
|
||||
Id: int64(domain.Id),
|
||||
Name: domain.Name,
|
||||
IsOn: domain.IsOn == 1,
|
||||
}
|
||||
|
||||
provider, err := models.SharedDNSProviderDAO.FindEnabledDNSProvider(int64(domain.ProviderId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -388,13 +412,13 @@ func (this *NodeClusterService) FindEnabledNodeClusterDNS(ctx context.Context, r
|
||||
|
||||
return &pb.FindEnabledNodeClusterDNSResponse{
|
||||
Name: dnsInfo.DnsName,
|
||||
Domain: dnsInfo.DnsDomain,
|
||||
Domain: pbDomain,
|
||||
Provider: pbProvider,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 计算使用某个DNS服务商的集群数量
|
||||
func (this *NodeClusterService) CountAllEnabledNodeClustersWithDNSProviderId(ctx context.Context, req *pb.CountAllEnabledNodeClustersWithDNSProviderIdRequest) (*pb.CountAllEnabledNodeClustersWithDNSProviderIdResponse, error) {
|
||||
func (this *NodeClusterService) CountAllEnabledNodeClustersWithDNSProviderId(ctx context.Context, req *pb.CountAllEnabledNodeClustersWithDNSProviderIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -405,5 +429,20 @@ func (this *NodeClusterService) CountAllEnabledNodeClustersWithDNSProviderId(ctx
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledNodeClustersWithDNSProviderIdResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 计算使用某个DNS域名的集群数量
|
||||
func (this *NodeClusterService) CountAllEnabledNodeClustersWithDNSDomainId(ctx context.Context, req *pb.CountAllEnabledNodeClustersWithDNSDomainIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
count, err := models.SharedNodeClusterDAO.CountAllEnabledClustersWithDNSDomainId(req.DnsDomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func (this *NodeGrantService) DisableNodeGrant(ctx context.Context, req *pb.Disa
|
||||
return &pb.DisableNodeGrantResponse{}, err
|
||||
}
|
||||
|
||||
func (this *NodeGrantService) CountAllEnabledNodeGrants(ctx context.Context, req *pb.CountAllEnabledNodeGrantsRequest) (*pb.CountAllEnabledNodeGrantsResponse, error) {
|
||||
func (this *NodeGrantService) CountAllEnabledNodeGrants(ctx context.Context, req *pb.CountAllEnabledNodeGrantsRequest) (*pb.RPCCountResponse, error) {
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -59,7 +59,7 @@ func (this *NodeGrantService) CountAllEnabledNodeGrants(ctx context.Context, req
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledNodeGrantsResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
func (this *NodeGrantService) ListEnabledNodeGrants(ctx context.Context, req *pb.ListEnabledNodeGrantsRequest) (*pb.ListEnabledNodeGrantsResponse, error) {
|
||||
|
||||
@@ -28,7 +28,7 @@ func (this *NodeLogService) CreateNodeLogs(ctx context.Context, req *pb.CreateNo
|
||||
}
|
||||
|
||||
// 查询日志数量
|
||||
func (this *NodeLogService) CountNodeLogs(ctx context.Context, req *pb.CountNodeLogsRequest) (*pb.CountNodeLogsResponse, error) {
|
||||
func (this *NodeLogService) CountNodeLogs(ctx context.Context, req *pb.CountNodeLogsRequest) (*pb.RPCCountResponse, error) {
|
||||
_, _, err := rpcutils.ValidateRequest(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -38,7 +38,7 @@ func (this *NodeLogService) CountNodeLogs(ctx context.Context, req *pb.CountNode
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountNodeLogsResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页日志
|
||||
|
||||
@@ -348,7 +348,7 @@ func (this *ServerService) UpdateServerNames(ctx context.Context, req *pb.Update
|
||||
}
|
||||
|
||||
// 计算服务数量
|
||||
func (this *ServerService) CountAllEnabledServersMatch(ctx context.Context, req *pb.CountAllEnabledServersMatchRequest) (*pb.CountAllEnabledServersMatchResponse, error) {
|
||||
func (this *ServerService) CountAllEnabledServersMatch(ctx context.Context, req *pb.CountAllEnabledServersMatchRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -359,7 +359,7 @@ func (this *ServerService) CountAllEnabledServersMatch(ctx context.Context, req
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.CountAllEnabledServersMatchResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 列出单页服务
|
||||
@@ -639,7 +639,7 @@ func (this *ServerService) FindAndInitServerWebConfig(ctx context.Context, req *
|
||||
}
|
||||
|
||||
// 计算使用某个SSL证书的服务数量
|
||||
func (this *ServerService) CountAllEnabledServersWithSSLCertId(ctx context.Context, req *pb.CountAllEnabledServersWithSSLCertIdRequest) (*pb.CountAllEnabledServersWithSSLCertIdResponse, error) {
|
||||
func (this *ServerService) CountAllEnabledServersWithSSLCertId(ctx context.Context, req *pb.CountAllEnabledServersWithSSLCertIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -652,7 +652,7 @@ func (this *ServerService) CountAllEnabledServersWithSSLCertId(ctx context.Conte
|
||||
}
|
||||
|
||||
if len(policyIds) == 0 {
|
||||
return &pb.CountAllEnabledServersWithSSLCertIdResponse{Count: 0}, nil
|
||||
return &pb.RPCCountResponse{Count: 0}, nil
|
||||
}
|
||||
|
||||
count, err := models.SharedServerDAO.CountAllEnabledServersWithSSLPolicyIds(policyIds)
|
||||
@@ -660,7 +660,7 @@ func (this *ServerService) CountAllEnabledServersWithSSLCertId(ctx context.Conte
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.CountAllEnabledServersWithSSLCertIdResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 查找使用某个SSL证书的所有服务
|
||||
@@ -696,7 +696,7 @@ func (this *ServerService) FindAllEnabledServersWithSSLCertId(ctx context.Contex
|
||||
}
|
||||
|
||||
// 计算使用某个缓存策略的服务数量
|
||||
func (this *ServerService) CountAllEnabledServersWithCachePolicyId(ctx context.Context, req *pb.CountAllEnabledServersWithCachePolicyIdRequest) (*pb.CountAllEnabledServersWithCachePolicyIdResponse, error) {
|
||||
func (this *ServerService) CountAllEnabledServersWithCachePolicyId(ctx context.Context, req *pb.CountAllEnabledServersWithCachePolicyIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -708,14 +708,14 @@ func (this *ServerService) CountAllEnabledServersWithCachePolicyId(ctx context.C
|
||||
return nil, err
|
||||
}
|
||||
if len(webIds) == 0 {
|
||||
return &pb.CountAllEnabledServersWithCachePolicyIdResponse{Count: 0}, nil
|
||||
return &pb.RPCCountResponse{Count: 0}, nil
|
||||
}
|
||||
|
||||
countServers, err := models.SharedServerDAO.CountEnabledServersWithWebIds(webIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledServersWithCachePolicyIdResponse{Count: countServers}, nil
|
||||
return &pb.RPCCountResponse{Count: countServers}, nil
|
||||
}
|
||||
|
||||
// 查找使用某个缓存策略的所有服务
|
||||
@@ -752,7 +752,7 @@ func (this *ServerService) FindAllEnabledServersWithCachePolicyId(ctx context.Co
|
||||
}
|
||||
|
||||
// 计算使用某个WAF策略的服务数量
|
||||
func (this *ServerService) CountAllEnabledServersWithHTTPFirewallPolicyId(ctx context.Context, req *pb.CountAllEnabledServersWithHTTPFirewallPolicyIdRequest) (*pb.CountAllEnabledServersWithHTTPFirewallPolicyIdResponse, error) {
|
||||
func (this *ServerService) CountAllEnabledServersWithHTTPFirewallPolicyId(ctx context.Context, req *pb.CountAllEnabledServersWithHTTPFirewallPolicyIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -765,14 +765,14 @@ func (this *ServerService) CountAllEnabledServersWithHTTPFirewallPolicyId(ctx co
|
||||
}
|
||||
|
||||
if len(webIds) == 0 {
|
||||
return &pb.CountAllEnabledServersWithHTTPFirewallPolicyIdResponse{Count: 0}, nil
|
||||
return &pb.RPCCountResponse{Count: 0}, nil
|
||||
}
|
||||
|
||||
countServers, err := models.SharedServerDAO.CountEnabledServersWithWebIds(webIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledServersWithHTTPFirewallPolicyIdResponse{Count: countServers}, nil
|
||||
return &pb.RPCCountResponse{Count: countServers}, nil
|
||||
}
|
||||
|
||||
// 查找使用某个WAF策略的所有服务
|
||||
@@ -810,7 +810,7 @@ func (this *ServerService) FindAllEnabledServersWithHTTPFirewallPolicyId(ctx con
|
||||
}
|
||||
|
||||
// 计算运行在某个集群上的所有服务数量
|
||||
func (this *ServerService) CountAllEnabledServersWithNodeClusterId(ctx context.Context, req *pb.CountAllEnabledServersWithNodeClusterIdRequest) (*pb.CountAllEnabledServersWithNodeClusterIdResponse, error) {
|
||||
func (this *ServerService) CountAllEnabledServersWithNodeClusterId(ctx context.Context, req *pb.CountAllEnabledServersWithNodeClusterIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -821,11 +821,11 @@ func (this *ServerService) CountAllEnabledServersWithNodeClusterId(ctx context.C
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledServersWithNodeClusterIdResponse{Count: count}, nil
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 计算使用某个分组的服务数量
|
||||
func (this *ServerService) CountAllEnabledServersWithGroupId(ctx context.Context, req *pb.CountAllEnabledServersWithGroupIdRequest) (*pb.CountAllEnabledServersWithGroupIdResponse, error) {
|
||||
func (this *ServerService) CountAllEnabledServersWithGroupId(ctx context.Context, req *pb.CountAllEnabledServersWithGroupIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -836,7 +836,7 @@ func (this *ServerService) CountAllEnabledServersWithGroupId(ctx context.Context
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CountAllEnabledServersWithGroupIdResponse{
|
||||
return &pb.RPCCountResponse{
|
||||
Count: count,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func (this *SSLCertService) DeleteSSLCert(ctx context.Context, req *pb.DeleteSSL
|
||||
}
|
||||
|
||||
// 计算匹配的Cert数量
|
||||
func (this *SSLCertService) CountSSLCerts(ctx context.Context, req *pb.CountSSLCertRequest) (*pb.CountSSLCertResponse, error) {
|
||||
func (this *SSLCertService) CountSSLCerts(ctx context.Context, req *pb.CountSSLCertRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -94,7 +94,7 @@ func (this *SSLCertService) CountSSLCerts(ctx context.Context, req *pb.CountSSLC
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.CountSSLCertResponse{
|
||||
return &pb.RPCCountResponse{
|
||||
Count: count,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user