-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tencentcloud: fix subdomain error (#1678)
Co-authored-by: Fernandez Ludovic <[email protected]>
- Loading branch information
Showing
6 changed files
with
110 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ Here is an example bash command using the Aurora DNS provider: | |
|
||
```bash | ||
AURORA_API_KEY=xxxxx \ | ||
AURORA_SECRET_KEY=yyyyyy \ | ||
AURORA_SECRET=yyyyyy \ | ||
lego --email [email protected] --dns auroradns --domains my.example.org run | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,92 @@ | ||
package tencentcloud | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/go-acme/lego/v4/challenge/dns01" | ||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" | ||
errorsdk "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" | ||
dnspod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod/v20210323" | ||
"golang.org/x/net/idna" | ||
) | ||
|
||
type domainData struct { | ||
domain string | ||
subDomain string | ||
} | ||
func (d *DNSProvider) getHostedZone(domain string) (*dnspod.DomainListItem, error) { | ||
request := dnspod.NewDescribeDomainListRequest() | ||
|
||
var domains []*dnspod.DomainListItem | ||
|
||
for { | ||
response, err := d.client.DescribeDomainList(request) | ||
if err != nil { | ||
return nil, fmt.Errorf("API call failed: %w", err) | ||
} | ||
|
||
domains = append(domains, response.Response.DomainList...) | ||
|
||
if uint64(len(domains)) >= *response.Response.DomainCountInfo.AllTotal { | ||
break | ||
} | ||
|
||
func getDomainData(fqdn string) (*domainData, error) { | ||
zone, err := dns01.FindZoneByFqdn(fqdn) | ||
request.Offset = common.Int64Ptr(int64(len(domains))) | ||
} | ||
|
||
authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &domainData{ | ||
domain: dns01.UnFqdn(zone), | ||
subDomain: dns01.UnFqdn(strings.TrimSuffix(fqdn, zone)), | ||
}, nil | ||
} | ||
|
||
func (d *DNSProvider) createRecordData(domainData *domainData, value string) error { | ||
request := dnspod.NewCreateRecordRequest() | ||
request.Domain = common.StringPtr(domainData.domain) | ||
request.SubDomain = common.StringPtr(domainData.subDomain) | ||
request.RecordType = common.StringPtr("TXT") | ||
request.RecordLine = common.StringPtr("默认") | ||
request.Value = common.StringPtr(value) | ||
request.TTL = common.Uint64Ptr(uint64(d.config.TTL)) | ||
var hostedZone *dnspod.DomainListItem | ||
for _, zone := range domains { | ||
if *zone.Name == dns01.UnFqdn(authZone) { | ||
hostedZone = zone | ||
} | ||
} | ||
|
||
_, err := d.client.CreateRecord(request) | ||
if err != nil { | ||
return err | ||
if hostedZone == nil { | ||
return nil, fmt.Errorf("zone %s not found in dnspod for domain %s", authZone, domain) | ||
} | ||
|
||
return nil | ||
return hostedZone, nil | ||
} | ||
|
||
func (d *DNSProvider) listRecordData(domainData *domainData) ([]*dnspod.RecordListItem, error) { | ||
func (d *DNSProvider) findTxtRecords(zone *dnspod.DomainListItem, fqdn string) ([]*dnspod.RecordListItem, error) { | ||
recordName, err := extractRecordName(fqdn, *zone.Name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
request := dnspod.NewDescribeRecordListRequest() | ||
request.Domain = common.StringPtr(domainData.domain) | ||
request.Subdomain = common.StringPtr(domainData.subDomain) | ||
request.Domain = zone.Name | ||
request.DomainId = zone.DomainId | ||
request.Subdomain = common.StringPtr(recordName) | ||
request.RecordType = common.StringPtr("TXT") | ||
request.RecordLine = common.StringPtr("默认") | ||
|
||
response, err := d.client.DescribeRecordList(request) | ||
if err != nil { | ||
var sdkError *errorsdk.TencentCloudSDKError | ||
if errors.As(err, &sdkError) { | ||
if sdkError.Code == dnspod.RESOURCENOTFOUND_NODATAOFRECORD { | ||
return nil, nil | ||
} | ||
} | ||
return nil, err | ||
} | ||
|
||
return response.Response.RecordList, nil | ||
} | ||
|
||
func (d *DNSProvider) deleteRecordData(domainData *domainData, item *dnspod.RecordListItem) error { | ||
request := dnspod.NewDeleteRecordRequest() | ||
request.Domain = common.StringPtr(domainData.domain) | ||
request.RecordId = item.RecordId | ||
|
||
_, err := d.client.DeleteRecord(request) | ||
func extractRecordName(fqdn, zone string) (string, error) { | ||
asciiDomain, err := idna.ToASCII(zone) | ||
if err != nil { | ||
return err | ||
return "", fmt.Errorf("fail to convert punycode: %w", err) | ||
} | ||
|
||
return nil | ||
name := dns01.UnFqdn(fqdn) | ||
if idx := strings.Index(name, "."+asciiDomain); idx != -1 { | ||
return name[:idx], nil | ||
} | ||
return name, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ lego --email [email protected] --dns tencentcloud --domains my.example.org run | |
TENCENTCLOUD_SECRET_ID = "Access key ID" | ||
TENCENTCLOUD_SECRET_KEY = "Access Key secret" | ||
[Configuration.Additional] | ||
TENCENTCLOUD_SESSION_TOKEN = "Access Key token" | ||
TENCENTCLOUD_REGION = "Region" | ||
TENCENTCLOUD_POLLING_INTERVAL = "Time between DNS propagation check" | ||
TENCENTCLOUD_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation" | ||
|