mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-14 08:20:25 +08:00
域名解析支持华为云解析DNS
This commit is contained in:
6
internal/dnsclients/huaweidns/response_base.go
Normal file
6
internal/dnsclients/huaweidns/response_base.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package huaweidns
|
||||||
|
|
||||||
|
type BaseResponse struct {
|
||||||
|
}
|
||||||
10
internal/dnsclients/huaweidns/response_custom_lines.go
Normal file
10
internal/dnsclients/huaweidns/response_custom_lines.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package huaweidns
|
||||||
|
|
||||||
|
type CustomLinesResponse struct {
|
||||||
|
Lines []struct {
|
||||||
|
LineId string `json:"line_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"lines"`
|
||||||
|
}
|
||||||
14
internal/dnsclients/huaweidns/response_record_sets.go
Normal file
14
internal/dnsclients/huaweidns/response_record_sets.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package huaweidns
|
||||||
|
|
||||||
|
type RecordSetsResponse struct {
|
||||||
|
RecordSets []struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Ttl int `json:"ttl"`
|
||||||
|
Line string `json:"line"`
|
||||||
|
Records []string `json:"records"`
|
||||||
|
} `json:"recordsets"`
|
||||||
|
}
|
||||||
17
internal/dnsclients/huaweidns/response_zone_record_sets.go
Normal file
17
internal/dnsclients/huaweidns/response_zone_record_sets.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package huaweidns
|
||||||
|
|
||||||
|
type ZoneRecordSetsResponse struct {
|
||||||
|
RecordSets []struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Ttl int `json:"ttl"`
|
||||||
|
Records []string `json:"records"`
|
||||||
|
Line string `json:"line"`
|
||||||
|
} `json:"recordsets"`
|
||||||
|
Metadata struct {
|
||||||
|
TotalCount int `json:"total_count"`
|
||||||
|
} `json:"metadata"`
|
||||||
|
}
|
||||||
17
internal/dnsclients/huaweidns/response_zones.go
Normal file
17
internal/dnsclients/huaweidns/response_zones.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package huaweidns
|
||||||
|
|
||||||
|
type ZonesResponse struct {
|
||||||
|
Links struct{} `json:"links"`
|
||||||
|
Zones []struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
ZoneType string `json:"zone_type"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
RecordNum int `json:"record_num"`
|
||||||
|
} `json:"zones"`
|
||||||
|
Metadata struct {
|
||||||
|
TotalCount int `json:"total_count"`
|
||||||
|
} `json:"metadata"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package huaweidns
|
||||||
|
|
||||||
|
type ZonesCreateRecordSetResponse struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Line string `json:"line"`
|
||||||
|
Records []string `json:"records"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package huaweidns
|
||||||
|
|
||||||
|
type ZonesDeleteRecordSetResponse struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package huaweidns
|
||||||
|
|
||||||
|
type ZonesUpdateRecordSetResponse struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Line string `json:"line"`
|
||||||
|
Records []string `json:"records"`
|
||||||
|
}
|
||||||
1498
internal/dnsclients/provider_huawei_dns.go
Normal file
1498
internal/dnsclients/provider_huawei_dns.go
Normal file
File diff suppressed because it is too large
Load Diff
132
internal/dnsclients/provider_huawei_dns_test.go
Normal file
132
internal/dnsclients/provider_huawei_dns_test.go
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package dnsclients
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients/dnstypes"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHuaweiDNSProvider_GetRecords(t *testing.T) {
|
||||||
|
provider, err := testHuaweiDNSProvider()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
records, err := provider.GetRecords("yun4s.cn")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
logs.PrintAsJSON(records, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHuaweiDNSProvider_GetRoutes(t *testing.T) {
|
||||||
|
provider, err := testHuaweiDNSProvider()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
routes, err := provider.GetRoutes("yun4s.cn")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(len(routes))
|
||||||
|
logs.PrintAsJSON(routes, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHuaweiDNSProvider_QueryRecord(t *testing.T) {
|
||||||
|
provider, err := testHuaweiDNSProvider()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
record, err := provider.QueryRecord("yun4s.cn", "abc", dnstypes.RecordTypeA)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
logs.PrintAsJSON(record)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHuaweiDNSProvider_AddRecord(t *testing.T) {
|
||||||
|
provider, err := testHuaweiDNSProvider()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
record := &dnstypes.Record{
|
||||||
|
Id: "",
|
||||||
|
Name: "add-record-1",
|
||||||
|
Type: "A",
|
||||||
|
Value: "192.168.2.40",
|
||||||
|
Route: "Beijing",
|
||||||
|
}
|
||||||
|
err = provider.AddRecord("yun4s.cn", record)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
logs.PrintAsJSON(record, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHuaweiDNSProvider_UpdateRecord(t *testing.T) {
|
||||||
|
provider, err := testHuaweiDNSProvider()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
record := &dnstypes.Record{
|
||||||
|
Id: "",
|
||||||
|
Name: "add-record-1",
|
||||||
|
Type: "A",
|
||||||
|
Value: "192.168.2.42",
|
||||||
|
Route: "default_view",
|
||||||
|
}
|
||||||
|
err = provider.UpdateRecord("yun4s.cn", &dnstypes.Record{
|
||||||
|
Id: "8aace3b97ac6e108017b116f3e2e2923@192.168.2.40",
|
||||||
|
}, record)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log("ok")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHuaweiDNSProvider_DeleteRecord(t *testing.T) {
|
||||||
|
provider, err := testHuaweiDNSProvider()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
record, err := provider.QueryRecord("yun4s.cn", "add-record-1", dnstypes.RecordTypeA)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if record == nil {
|
||||||
|
t.Log("not found record")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = provider.DeleteRecord("yun4s.cn", record)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log("ok")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testHuaweiDNSProvider() (ProviderInterface, error) {
|
||||||
|
db, err := dbs.Default()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
one, err := db.FindOne("SELECT * FROM edgeDNSProviders WHERE type='huaweiDNS' ORDER BY id DESC")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
apiParams := maps.Map{}
|
||||||
|
err = json.Unmarshal([]byte(one.GetString("apiParams")), &apiParams)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
provider := &HuaweiDNSProvider{}
|
||||||
|
err = provider.Auth(apiParams)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return provider, nil
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ type ProviderType = string
|
|||||||
const (
|
const (
|
||||||
ProviderTypeDNSPod ProviderType = "dnspod" // DNSPod
|
ProviderTypeDNSPod ProviderType = "dnspod" // DNSPod
|
||||||
ProviderTypeAliDNS ProviderType = "alidns" // 阿里云DNS
|
ProviderTypeAliDNS ProviderType = "alidns" // 阿里云DNS
|
||||||
|
ProviderTypeHuaweiDNS ProviderType = "huaweiDNS" // 华为DNS
|
||||||
ProviderTypeDNSCom ProviderType = "dnscom" // dns.com
|
ProviderTypeDNSCom ProviderType = "dnscom" // dns.com
|
||||||
ProviderTypeCloudFlare ProviderType = "cloudFlare" // CloudFlare DNS
|
ProviderTypeCloudFlare ProviderType = "cloudFlare" // CloudFlare DNS
|
||||||
ProviderTypeLocalEdgeDNS ProviderType = "localEdgeDNS" // 和当前系统集成的EdgeDNS
|
ProviderTypeLocalEdgeDNS ProviderType = "localEdgeDNS" // 和当前系统集成的EdgeDNS
|
||||||
@@ -31,6 +32,11 @@ func FindAllProviderTypes() []maps.Map {
|
|||||||
"code": ProviderTypeDNSPod,
|
"code": ProviderTypeDNSPod,
|
||||||
"description": "DNSPod提供的DNS服务。",
|
"description": "DNSPod提供的DNS服务。",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "华为云DNS",
|
||||||
|
"code": ProviderTypeHuaweiDNS,
|
||||||
|
"description": "华为云解析DNS。",
|
||||||
|
},
|
||||||
/**{
|
/**{
|
||||||
"name": "帝恩思DNS.COM",
|
"name": "帝恩思DNS.COM",
|
||||||
"code": ProviderTypeDNSCom,
|
"code": ProviderTypeDNSCom,
|
||||||
@@ -74,6 +80,8 @@ func FindProvider(providerType ProviderType) ProviderInterface {
|
|||||||
return &DNSPodProvider{}
|
return &DNSPodProvider{}
|
||||||
case ProviderTypeAliDNS:
|
case ProviderTypeAliDNS:
|
||||||
return &AliDNSProvider{}
|
return &AliDNSProvider{}
|
||||||
|
case ProviderTypeHuaweiDNS:
|
||||||
|
return &HuaweiDNSProvider{}
|
||||||
case ProviderTypeCloudFlare:
|
case ProviderTypeCloudFlare:
|
||||||
return &CloudFlareProvider{}
|
return &CloudFlareProvider{}
|
||||||
case ProviderTypeLocalEdgeDNS:
|
case ProviderTypeLocalEdgeDNS:
|
||||||
|
|||||||
Reference in New Issue
Block a user