1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

CLOUDNS: Fetch permitted TTL values from API #1078 (#1102)

The TTL values permitted may be different for each account and for each domain. Therefore we perform this query once per domain.

* Fetch ClouDNS allowed TTL values from API (Fix #1078)
* Add get available TTL values comment
This commit is contained in:
2021-03-22 22:47:29 +09:00
committed by GitHub
parent 8249f33913
commit 4eb6fdface
2 changed files with 20 additions and 17 deletions

View File

@ -71,21 +71,7 @@ type domainRecord struct {
type recordResponse map[string]domainRecord type recordResponse map[string]domainRecord
var allowedTTLValues = []uint32{ var allowedTTLValues = []uint32{}
60, // 1 minute
300, // 5 minutes
900, // 15 minutes
1800, // 30 minutes
3600, // 1 hour
21600, // 6 hours
43200, // 12 hours
86400, // 1 day
172800, // 2 days
259200, // 3 days
604800, // 1 week
1209600, // 2 weeks
2419200, // 4 weeks
}
func (c *cloudnsProvider) fetchAvailableNameservers() error { func (c *cloudnsProvider) fetchAvailableNameservers() error {
c.nameserversNames = nil c.nameserversNames = nil
@ -107,6 +93,21 @@ func (c *cloudnsProvider) fetchAvailableNameservers() error {
return nil return nil
} }
func (c *cloudnsProvider) fetchAvailableTTLValues(domain string) error {
allowedTTLValues = nil
params := requestParams{
"domain-name": domain,
}
var bodyString, err = c.get("/dns/get-available-ttl.json", params)
if err != nil {
return fmt.Errorf("failed fetching available TTL values list from ClouDNS: %s", err)
}
json.Unmarshal(bodyString, &allowedTTLValues)
return nil
}
func (c *cloudnsProvider) fetchDomainList() error { func (c *cloudnsProvider) fetchDomainList() error {
c.domainIndex = map[string]string{} c.domainIndex = map[string]string{}
rowsPerPage := 100 rowsPerPage := 100

View File

@ -94,8 +94,10 @@ func (c *cloudnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
// Normalize // Normalize
models.PostProcessRecords(existingRecords) models.PostProcessRecords(existingRecords)
// ClouDNS doesn't allow selecting an arbitrary TTL, only a set of predefined values https://asia.cloudns.net/wiki/article/188/ // Get a list of available TTL values.
// We need to make sure we don't change it every time if it is as close as it's going to get // The TTL list needs to be obtained for each domain, so get it first here.
c.fetchAvailableTTLValues(dc.Name)
// ClouDNS can only be specified from a specific TTL list, so change the TTL in advance.
for _, record := range dc.Records { for _, record := range dc.Records {
record.TTL = fixTTL(record.TTL) record.TTL = fixTTL(record.TTL)
} }