mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
BUG: Some DNS zones are downloaded twice (#2120)
Signed-off-by: Amelia Aronsohn <squirrel@wearing.black> Co-authored-by: Tom Limoncelli <tal@whatexit.org> Co-authored-by: Grégoire Henry <hnrgrgr@users.noreply.github.com> Co-authored-by: Amelia Aronsohn <squirrel@wearing.black> Co-authored-by: Kai Schwarz <kschwarz@hexonet.net> Co-authored-by: Asif Nawaz <asif.nawaz@centralnic.com> Co-authored-by: imlonghao <git@imlonghao.com> Co-authored-by: Will Power <1619102+willpower232@users.noreply.github.com>
This commit is contained in:
@@ -19,7 +19,7 @@ var defaultNameServerNames = []string{
|
||||
"ns2.packetframe.com",
|
||||
}
|
||||
|
||||
type zone struct {
|
||||
type zoneInfo struct {
|
||||
ID string `json:"id"`
|
||||
Zone string `json:"zone"`
|
||||
Users []string `json:"users"`
|
||||
@@ -28,7 +28,7 @@ type zone struct {
|
||||
|
||||
type domainResponse struct {
|
||||
Data struct {
|
||||
Zones []zone `json:"zones"`
|
||||
Zones []zoneInfo `json:"zones"`
|
||||
} `json:"data"`
|
||||
Message string `json:"message"`
|
||||
Success bool `json:"success"`
|
||||
@@ -58,7 +58,7 @@ type domainRecord struct {
|
||||
}
|
||||
|
||||
func (api *packetframeProvider) fetchDomainList() error {
|
||||
api.domainIndex = map[string]zone{}
|
||||
api.domainIndex = map[string]zoneInfo{}
|
||||
dr := &domainResponse{}
|
||||
endpoint := "dns/zones"
|
||||
if err := api.get(endpoint, dr); err != nil {
|
||||
|
@@ -19,7 +19,7 @@ type packetframeProvider struct {
|
||||
client *http.Client
|
||||
baseURL *url.URL
|
||||
token string
|
||||
domainIndex map[string]zone
|
||||
domainIndex map[string]zoneInfo
|
||||
}
|
||||
|
||||
// newPacketframe creates the provider.
|
||||
@@ -60,19 +60,28 @@ func (api *packetframeProvider) GetNameservers(domain string) ([]*models.Nameser
|
||||
return models.ToNameservers(defaultNameServerNames)
|
||||
}
|
||||
|
||||
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
|
||||
func (api *packetframeProvider) GetZoneRecords(domain string) (models.Records, error) {
|
||||
|
||||
func (api *packetframeProvider) getZone(domain string) (*zoneInfo, error) {
|
||||
if api.domainIndex == nil {
|
||||
if err := api.fetchDomainList(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
zone, ok := api.domainIndex[domain+"."]
|
||||
z, ok := api.domainIndex[domain+"."]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%q not a zone in Packetframe account", domain)
|
||||
}
|
||||
|
||||
return &z, nil
|
||||
}
|
||||
|
||||
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
|
||||
func (api *packetframeProvider) GetZoneRecords(domain string) (models.Records, error) {
|
||||
|
||||
zone, err := api.getZone(domain)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("no such zone %q in Packetframe account", domain)
|
||||
}
|
||||
|
||||
records, err := api.getRecords(zone.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not load records for domain %q", domain)
|
||||
@@ -91,48 +100,21 @@ func (api *packetframeProvider) GetZoneRecords(domain string) (models.Records, e
|
||||
return existingRecords, nil
|
||||
}
|
||||
|
||||
// GetDomainCorrections returns the corrections for a domain.
|
||||
func (api *packetframeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
||||
dc, err := dc.Copy()
|
||||
// GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records.
|
||||
func (api *packetframeProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) {
|
||||
zone, err := api.getZone(dc.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dc.Punycode()
|
||||
|
||||
if api.domainIndex == nil {
|
||||
if err := api.fetchDomainList(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
zone, ok := api.domainIndex[dc.Name+"."]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no such zone %q in Packetframe account", dc.Name)
|
||||
}
|
||||
|
||||
records, err := api.getRecords(zone.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not load records for domain %q", dc.Name)
|
||||
}
|
||||
|
||||
existingRecords := make([]*models.RecordConfig, len(records))
|
||||
|
||||
for i := range records {
|
||||
existingRecords[i] = toRc(dc, &records[i])
|
||||
}
|
||||
|
||||
// Normalize
|
||||
models.PostProcessRecords(existingRecords)
|
||||
|
||||
var corrections []*models.Correction
|
||||
var create, dels, modify diff.Changeset
|
||||
var differ diff.Differ
|
||||
if !diff2.EnableDiff2 {
|
||||
differ = diff.New(dc)
|
||||
} else {
|
||||
differ = diff.NewCompat(dc)
|
||||
}
|
||||
_, create, dels, modify, err = differ.IncrementalDiff(existingRecords)
|
||||
_, create, dels, modify, err := differ.IncrementalDiff(existingRecords)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user