@@ -14,8 +14,8 @@ import (
1414 "github.com/StackExchange/dnscontrol/v4/pkg/txtutil"
1515)
1616
17- // CNRRecord covers an individual DNS resource record.
18- type CNRRecord struct {
17+ // Record covers an individual DNS resource record.
18+ type Record struct {
1919 // DomainName is the zone that the record belongs to.
2020 DomainName string
2121 // Host is the hostname relative to the zone: e.g. for a record for blog.example.org, domain would be "example.org" and host would be "blog".
@@ -36,7 +36,7 @@ type CNRRecord struct {
3636}
3737
3838// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
39- func (n * CNRClient ) GetZoneRecords (domain string , meta map [string ]string ) (models.Records , error ) {
39+ func (n * Client ) GetZoneRecords (domain string , meta map [string ]string ) (models.Records , error ) {
4040 records , err := n .getRecords (domain )
4141 if err != nil {
4242 return nil , err
@@ -50,7 +50,7 @@ func (n *CNRClient) GetZoneRecords(domain string, meta map[string]string) (model
5050}
5151
5252// GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records.
53- func (n * CNRClient ) GetZoneRecordsCorrections (dc * models.DomainConfig , actual models.Records ) ([]* models.Correction , int , error ) {
53+ func (n * Client ) GetZoneRecordsCorrections (dc * models.DomainConfig , actual models.Records ) ([]* models.Correction , int , error ) {
5454 toReport , create , del , mod , actualChangeCount , err := diff .NewCompat (dc ).IncrementalDiff (actual )
5555 if err != nil {
5656 return nil , 0 , err
@@ -82,7 +82,7 @@ func (n *CNRClient) GetZoneRecordsCorrections(dc *models.DomainConfig, actual mo
8282 changes = true
8383 fmt .Fprintln (buf , d )
8484 key := fmt .Sprintf ("DELRR%d" , delrridx )
85- oldRecordString := n .deleteRecordString (d .Existing .Original .(* CNRRecord ))
85+ oldRecordString := n .deleteRecordString (d .Existing .Original .(* Record ))
8686 params [key ] = oldRecordString
8787 fmt .Fprintf (& builder , "\033 [31m- %s = %s\033 [0m\n " , key , oldRecordString )
8888 delrridx ++
@@ -92,7 +92,7 @@ func (n *CNRClient) GetZoneRecordsCorrections(dc *models.DomainConfig, actual mo
9292 fmt .Fprintln (buf , chng )
9393 // old record deletion
9494 key := fmt .Sprintf ("DELRR%d" , delrridx )
95- oldRecordString := n .deleteRecordString (chng .Existing .Original .(* CNRRecord ))
95+ oldRecordString := n .deleteRecordString (chng .Existing .Original .(* Record ))
9696 params [key ] = oldRecordString
9797 fmt .Fprintf (& builder , "\033 [31m- %s = %s\033 [0m\n " , key , oldRecordString )
9898 delrridx ++
@@ -123,7 +123,7 @@ func (n *CNRClient) GetZoneRecordsCorrections(dc *models.DomainConfig, actual mo
123123 return corrections , actualChangeCount , nil
124124}
125125
126- func toRecord (r * CNRRecord , origin string ) * models.RecordConfig {
126+ func toRecord (r * Record , origin string ) * models.RecordConfig {
127127 rc := & models.RecordConfig {
128128 Type : r .Type ,
129129 TTL : r .TTL ,
@@ -159,7 +159,7 @@ func toRecord(r *CNRRecord, origin string) *models.RecordConfig {
159159}
160160
161161// updateZoneBy updates the zone with the provided changes.
162- func (n * CNRClient ) updateZoneBy (params map [string ]interface {}, domain string ) error {
162+ func (n * Client ) updateZoneBy (params map [string ]interface {}, domain string ) error {
163163 zone := domain
164164 cmd := map [string ]interface {}{
165165 "COMMAND" : "ModifyDNSZone" ,
@@ -170,14 +170,14 @@ func (n *CNRClient) updateZoneBy(params map[string]interface{}, domain string) e
170170 }
171171 r := n .client .Request (cmd )
172172 if ! r .IsSuccess () {
173- return n .GetCNRApiError ("Error while updating zone" , zone , r )
173+ return n .GetAPIError ("Error while updating zone" , zone , r )
174174 }
175175 return nil
176176}
177177
178- // deleteRecordString constructs the record string based on the provided CNRRecord .
179- func (n * CNRClient ) getRecords (domain string ) ([]* CNRRecord , error ) {
180- var records []* CNRRecord
178+ // deleteRecordString constructs the record string based on the provided Record .
179+ func (n * Client ) getRecords (domain string ) ([]* Record , error ) {
180+ var records []* Record
181181
182182 // Command to find out the total numbers of resource records for the zone
183183 // so that the follow-up query can be done with the correct limit
@@ -186,7 +186,8 @@ func (n *CNRClient) getRecords(domain string) ([]*CNRRecord, error) {
186186 "DNSZONE" : domain ,
187187 "ORDERBY" : "type" ,
188188 "FIRST" : "0" ,
189- "LIMIT" : "1" ,
189+ "LIMIT" : "10000" ,
190+ "WIDE" : "1" ,
190191 }
191192 r := n .client .Request (cmd )
192193
@@ -201,29 +202,16 @@ func (n *CNRClient) getRecords(domain string) ([]*CNRRecord, error) {
201202 }
202203 } else {
203204 // Return specific error if the zone does not exist
204- return nil , n .GetCNRApiError ("Use `dnscontrol create-domains` to create not-existing zone" , domain , r )
205+ return nil , n .GetAPIError ("Use `dnscontrol create-domains` to create not-existing zone" , domain , r )
205206 }
206207 }
207208 // Return general error for any other issues
208- return nil , n .GetCNRApiError ("Failed loading resource records for zone" , domain , r )
209+ return nil , n .GetAPIError ("Failed loading resource records for zone" , domain , r )
209210 }
210211 totalRecords := r .GetRecordsTotalCount ()
211212 if totalRecords <= 0 {
212213 return nil , nil
213214 }
214- limitation := 100
215- totalRecords += limitation
216-
217- // finally request all resource records available for the zone
218- cmd ["LIMIT" ] = strconv .Itoa (totalRecords )
219- cmd ["WIDE" ] = "1"
220- r = n .client .Request (cmd )
221-
222- // Check if the request was successful
223- if ! r .IsSuccess () {
224- // Return general error for any other issues
225- return nil , n .GetCNRApiError ("Failed loading resource records for zone" , domain , r )
226- }
227215
228216 // loop over the records array
229217 rrs := r .GetRecords ()
@@ -265,8 +253,8 @@ func (n *CNRClient) getRecords(domain string) ([]*CNRRecord, error) {
265253 fqdn = fmt .Sprintf ("%s.%s." , data ["NAME" ], domain )
266254 }
267255
268- // Initialize a new CNRRecord
269- record := & CNRRecord {
256+ // Initialize a new Record
257+ record := & Record {
270258 DomainName : domain ,
271259 Host : data ["NAME" ],
272260 Fqdn : fqdn ,
@@ -286,7 +274,7 @@ func (n *CNRClient) getRecords(domain string) ([]*CNRRecord, error) {
286274}
287275
288276// Function to create record string from given RecordConfig for the ADDRR# API parameter
289- func (n * CNRClient ) createRecordString (rc * models.RecordConfig , domain string ) (string , error ) {
277+ func (n * Client ) createRecordString (rc * models.RecordConfig , domain string ) (string , error ) {
290278 host := rc .GetLabel ()
291279 answer := ""
292280
@@ -339,8 +327,8 @@ func (n *CNRClient) createRecordString(rc *models.RecordConfig, domain string) (
339327 return str , nil
340328}
341329
342- // deleteRecordString constructs the record string based on the provided CNRRecord .
343- func (n * CNRClient ) deleteRecordString (record * CNRRecord ) string {
330+ // deleteRecordString constructs the record string based on the provided Record .
331+ func (n * Client ) deleteRecordString (record * Record ) string {
344332 // Initialize values slice
345333 values := []string {
346334 record .Host ,
@@ -375,6 +363,7 @@ func isNoPopulate() bool {
375363}
376364
377365// Function to check if debug mode is enabled
378- func (n * CNRClient ) isDebugOn () bool {
379- return n .conf ["debugmode" ] == "1" || n .conf ["debugmode" ] == "2"
366+ func (n * Client ) isDebugOn () bool {
367+ debugMode , exists := n .conf ["debugmode" ]
368+ return exists && (debugMode == "1" || debugMode == "2" )
380369}
0 commit comments