mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-12 10:27:57 +08:00
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:
parent
8249f33913
commit
4eb6fdface
2 changed files with 20 additions and 17 deletions
|
@ -71,21 +71,7 @@ type domainRecord struct {
|
|||
|
||||
type recordResponse map[string]domainRecord
|
||||
|
||||
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
|
||||
}
|
||||
var allowedTTLValues = []uint32{}
|
||||
|
||||
func (c *cloudnsProvider) fetchAvailableNameservers() error {
|
||||
c.nameserversNames = nil
|
||||
|
@ -107,6 +93,21 @@ func (c *cloudnsProvider) fetchAvailableNameservers() error {
|
|||
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 {
|
||||
c.domainIndex = map[string]string{}
|
||||
rowsPerPage := 100
|
||||
|
|
|
@ -94,8 +94,10 @@ func (c *cloudnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
|||
// Normalize
|
||||
models.PostProcessRecords(existingRecords)
|
||||
|
||||
// ClouDNS doesn't allow selecting an arbitrary TTL, only a set of predefined values https://asia.cloudns.net/wiki/article/188/
|
||||
// We need to make sure we don't change it every time if it is as close as it's going to get
|
||||
// Get a list of available TTL values.
|
||||
// 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 {
|
||||
record.TTL = fixTTL(record.TTL)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue