mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
DNS API支持查询多个同名记录/优化ACME申请
This commit is contained in:
@@ -269,6 +269,54 @@ func (this *EdgeDNSAPIProvider) QueryRecord(domain string, name string, recordTy
|
||||
}, nil
|
||||
}
|
||||
|
||||
// QueryRecords 查询多个记录
|
||||
func (this *EdgeDNSAPIProvider) QueryRecords(domain string, name string, recordType dnstypes.RecordType) ([]*dnstypes.Record, error) {
|
||||
var domainResp = &edgeapi.FindDomainWithNameResponse{}
|
||||
err := this.doAPI("/NSDomainService/FindNSDomainWithName", map[string]any{
|
||||
"name": domain,
|
||||
}, domainResp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var domainId = domainResp.Data.NSDomain.Id
|
||||
if domainId == 0 {
|
||||
return nil, errors.New("can not find domain '" + domain + "'")
|
||||
}
|
||||
|
||||
var recordResp = &edgeapi.FindNSRecordsWithNameAndTypeResponse{}
|
||||
err = this.doAPI("/NSRecordService/FindNSRecordsWithNameAndType", map[string]any{
|
||||
"nsDomainId": domainId,
|
||||
"name": name,
|
||||
"type": recordType,
|
||||
}, recordResp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result = []*dnstypes.Record{}
|
||||
for _, record := range recordResp.Data.NSRecords {
|
||||
if record.Id <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var routeCode = this.DefaultRoute()
|
||||
if len(record.NSRoutes) > 0 {
|
||||
routeCode = record.NSRoutes[0].Code
|
||||
}
|
||||
|
||||
result = append(result, &dnstypes.Record{
|
||||
Id: types.String(record.Id),
|
||||
Name: record.Name,
|
||||
Type: record.Type,
|
||||
Value: record.Value,
|
||||
Route: routeCode,
|
||||
TTL: record.TTL,
|
||||
})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// AddRecord 设置记录
|
||||
func (this *EdgeDNSAPIProvider) AddRecord(domain string, newRecord *dnstypes.Record) error {
|
||||
var domainResp = &edgeapi.FindDomainWithNameResponse{}
|
||||
|
||||
Reference in New Issue
Block a user