dnscontrol/pkg/zonerecs/zonerecords.go
Patrik Kernstock 9aad2926fb
INWX: Fix INWX provider after their unexpected data-type breaking-change (#3855)
Fixes #3854 

Unfortunately I couldn't run the integrationTests properly as INWX
doesn't seem to have properly updated their sandbox environment (it
still presents `int` instead of `string` like production). Hence, the
tests do fail. I don't want to run this against my own production
account, to be frank.

See:
```shell
$ curl -X POST https://api.ote.domrobot.com/xmlrpc/ -H "Content-Type: application/xml" -d '<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
   <methodName>nameserver.info</methodName>
   <params>
      <param>
         <value>
            <struct>
               <member>
                  <name>user</name>
                  <value>
                     <string>[USER]</string>
                  </value>
               </member>
               <member>
                  <name>lang</name>
                  <value>
                     <string>en</string>
                  </value>
               </member>
               <member>
                  <name>pass</name>
                  <value>
                     <string>[PASS]</string>
                  </value>
               </member>
               <member>
                  <name>domain</name>
                  <value>
                     <string>[DOMAIN]</string>
                  </value>
               </member>
            </struct>
         </value>
      </param>
   </params>
</methodCall>' | xmllint --format - | grep -iE "id|roId" -C3
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3968    0  2971  100   997  13375   4488 --:--:-- --:--:-- --:--:-- 17954
            <value>
              <struct>
                <member>
                  <name>roId</name>
                  <value>
                    <int>9677</int>
                  </value>
--
                        <value>
                          <struct>
                            <member>
                              <name>id</name>
                              <value>
                                <int>118057</int>
                              </value>
--
                        <value>
                          <struct>
                            <member>
                              <name>id</name>
                              <value>
                                <int>118060</int>
                              </value>
--
                        <value>
                          <struct>
                            <member>
                              <name>id</name>
                              <value>
                                <int>79610</int>
                              </value>
--
                        <value>
                          <struct>
                            <member>
                              <name>id</name>
                              <value>
                                <int>77243</int>
                              </value>
--
            </value>
          </member>
          <member>
            <name>svTRID</name>
            <value>
              <string>20251127--ote</string>
            </value>
```

Hence, only done manualy tests via `dnscontrol push --domains
<example.com>`:
(tested create, delete and modify)

```text
CONCURRENTLY checking for 0 zone(s)
SERIALLY checking for 1 zone(s)
Serially checking for zone: "example.tld"
CONCURRENTLY gathering records of 0 zone(s)
SERIALLY gathering records of 1 zone(s)
Serially Gathering: "example.tld"
******************** Domain: example.tld
3 corrections (PK-INWX)
#1: - DELETE _test1.example.tld TXT "123" ttl=43200
SUCCESS!
#2: ± MODIFY _test2.example.tld TXT ("1234" ttl=43200) -> ("12345" ttl=43200)
SUCCESS!
#3: + CREATE _test4.example.tld TXT "123" ttl=43200
SUCCESS!
Done. 3 corrections.
```
2025-11-29 12:17:13 -05:00

52 lines
1.6 KiB
Go

package zonerecs
import (
"github.com/StackExchange/dnscontrol/v4/models"
)
// CorrectZoneRecords calls both GetZoneRecords, does any
// post-processing, and then calls GetZoneRecordsCorrections. The
// name sucks because all the good names were taken.
func CorrectZoneRecords(driver models.DNSProvider, dc *models.DomainConfig) ([]*models.Correction, []*models.Correction, int, error) {
existingRecords, err := driver.GetZoneRecords(dc.Name, dc.Metadata)
if err != nil {
return nil, nil, 0, err
}
// downcase
models.Downcase(existingRecords)
models.Downcase(dc.Records)
models.CanonicalizeTargets(existingRecords, dc.Name)
models.CanonicalizeTargets(dc.Records, dc.Name)
// Copy dc so that any correction code that wants to
// modify the records may. For example, if the provider only
// supports certain TTL values, it will adjust the ones in
// dc.Records.
dc, err = dc.Copy()
if err != nil {
return nil, nil, 0, err
}
// punycode
if err := dc.Punycode(); err != nil {
return nil, nil, 0, err
}
// FIXME(tlim) It is a waste to PunyCode every iteration.
// This should be moved to where the JavaScript is processed.
everything, actualChangeCount, err := driver.GetZoneRecordsCorrections(dc, existingRecords)
reports, corrections := splitReportsAndCorrections(everything)
return reports, corrections, actualChangeCount, err
}
func splitReportsAndCorrections(everything []*models.Correction) (reports, corrections []*models.Correction) {
for i := range everything {
if everything[i].F == nil {
reports = append(reports, everything[i])
} else {
corrections = append(corrections, everything[i])
}
}
return reports, corrections
}