Add custom TTL support for DNSimple (#477)

* Add custom TTL support for DNSimple

* chore: add changelog entry
This commit is contained in:
James Bowes 2018-02-27 09:26:02 -04:00 committed by Martin Linkhorst
parent 389527785d
commit 8989032e85
3 changed files with 28 additions and 3 deletions

View File

@ -1,3 +1,4 @@
- Add custom TTL support for DNSimple (#477) @jbowes
- Fix docker build and delete vendor files which were not deleted (#473) @njuettner
- DigitalOcean: DigitalOcean creates entries with host in them twice (#459) @njuettner
- Bugfix: Retrive all DNSimple response pages (#468) @jbowes

View File

@ -28,6 +28,8 @@ import (
log "github.com/sirupsen/logrus"
)
const dnsimpleRecordTTL = 3600 // Default TTL of 1 hour if not set (DNSimple's default)
type identityService struct {
service *dnsimple.IdentityService
}
@ -174,7 +176,7 @@ func (p *dnsimpleProvider) Records() (endpoints []*endpoint.Endpoint, _ error) {
default:
continue
}
endpoints = append(endpoints, endpoint.NewEndpoint(record.Name+"."+record.ZoneID, record.Content, record.Type))
endpoints = append(endpoints, endpoint.NewEndpointWithTTL(record.Name+"."+record.ZoneID, record.Content, record.Type, endpoint.TTL(record.TTL)))
}
page++
if page > records.Pagination.TotalPages {
@ -187,12 +189,18 @@ func (p *dnsimpleProvider) Records() (endpoints []*endpoint.Endpoint, _ error) {
// newDnsimpleChange initializes a new change to dns records
func newDnsimpleChange(action string, e *endpoint.Endpoint) *dnsimpleChange {
ttl := dnsimpleRecordTTL
if e.RecordTTL.IsConfigured() {
ttl = int(e.RecordTTL)
}
change := &dnsimpleChange{
Action: action,
ResourceRecordSet: dnsimple.ZoneRecord{
Name: e.DNSName,
Type: e.RecordType,
Content: e.Targets[0],
TTL: ttl,
},
}
return change

View File

@ -74,7 +74,18 @@ func TestDnsimpleServices(t *testing.T) {
Priority: 0,
Type: "A",
}
records := []dnsimple.ZoneRecord{firstRecord, secondRecord}
thirdRecord := dnsimple.ZoneRecord{
ID: 3,
ZoneID: "example.com",
ParentID: 0,
Name: "custom-ttl",
Content: "target",
TTL: 60,
Priority: 0,
Type: "CNAME",
}
records := []dnsimple.ZoneRecord{firstRecord, secondRecord, thirdRecord}
dnsimpleListRecordsResponse = dnsimple.ZoneRecordsResponse{
Response: dnsimple.Response{Pagination: &dnsimple.Pagination{}},
Data: records,
@ -92,6 +103,7 @@ func TestDnsimpleServices(t *testing.T) {
Name: record.Name,
Type: record.Type,
Content: record.Content,
TTL: record.TTL,
}
dnsimpleRecordResponse := dnsimple.ZoneRecordsResponse{
@ -103,6 +115,7 @@ func TestDnsimpleServices(t *testing.T) {
mockDNS.On("CreateRecord", "1", record.ZoneID, simpleRecord).Return(&dnsimple.ZoneRecordResponse{}, nil)
mockDNS.On("DeleteRecord", "1", record.ZoneID, record.ID).Return(&dnsimple.ZoneRecordResponse{}, nil)
mockDNS.On("UpdateRecord", "1", record.ZoneID, record.ID, simpleRecord).Return(&dnsimple.ZoneRecordResponse{}, nil)
mockDNS.On("UpdateRecord", "1", record.ZoneID, record.ID, simpleRecord).Return(&dnsimple.ZoneRecordResponse{}, nil)
}
mockProvider = dnsimpleProvider{client: mockDNS}
@ -138,7 +151,10 @@ func testDnsimpleProviderRecords(t *testing.T) {
}
func testDnsimpleProviderApplyChanges(t *testing.T) {
changes := &plan.Changes{}
changes.Create = []*endpoint.Endpoint{{DNSName: "example.example.com", Targets: endpoint.Targets{"target"}, RecordType: endpoint.RecordTypeCNAME}}
changes.Create = []*endpoint.Endpoint{
{DNSName: "example.example.com", Targets: endpoint.Targets{"target"}, RecordType: endpoint.RecordTypeCNAME},
{DNSName: "custom-ttl.example.com", RecordTTL: 60, Targets: endpoint.Targets{"target"}, RecordType: endpoint.RecordTypeCNAME},
}
changes.Delete = []*endpoint.Endpoint{{DNSName: "example-beta.example.com", Targets: endpoint.Targets{"127.0.0.1"}, RecordType: endpoint.RecordTypeA}}
changes.UpdateNew = []*endpoint.Endpoint{{DNSName: "example.example.com", Targets: endpoint.Targets{"target"}, RecordType: endpoint.RecordTypeCNAME}}