mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
NEW FEATURE: NO_PURGE reports what is not purged (diff2 only) (#2031)
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
package diff
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v3/models"
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/diff2"
|
||||
)
|
||||
@ -62,6 +64,9 @@ func (d *differCompat) IncrementalDiff(existing []*models.RecordConfig) (unchang
|
||||
for _, inst := range instructions {
|
||||
cor := Correlation{d: d.OldDiffer}
|
||||
switch inst.Type {
|
||||
case diff2.REPORT:
|
||||
// Sadly the NewCompat function doesn't have a way to do this.
|
||||
// Purge reports are silently skipped.
|
||||
case diff2.CREATE:
|
||||
cor.Desired = inst.New[0]
|
||||
create = append(create, cor)
|
||||
@ -72,6 +77,8 @@ func (d *differCompat) IncrementalDiff(existing []*models.RecordConfig) (unchang
|
||||
case diff2.DELETE:
|
||||
cor.Existing = inst.Old[0]
|
||||
toDelete = append(toDelete, cor)
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled inst.Type %s", inst.Type))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ const (
|
||||
CREATE // Create a record/recordset/label where none existed before.
|
||||
CHANGE // Change existing record/recordset/label
|
||||
DELETE // Delete existing record/recordset/label
|
||||
REPORT // No change, but boy do I have something to say!
|
||||
)
|
||||
|
||||
type ChangeList []Change
|
||||
@ -48,28 +49,33 @@ General instructions:
|
||||
|
||||
for _, change := range changes {
|
||||
switch change.Type {
|
||||
case diff2.REPORT:
|
||||
corr = &models.Correction{Msg: change.MsgsJoined}
|
||||
case diff2.CREATE:
|
||||
corr = &models.Correction{
|
||||
Msg: change.MsgsJoined,
|
||||
F: func() error {
|
||||
return c.createRecord(FILL IN)
|
||||
return c.createRecord(FILL_IN)
|
||||
},
|
||||
}
|
||||
case diff2.CHANGE:
|
||||
corr = &models.Correction{
|
||||
Msg: change.MsgsJoined,
|
||||
F: func() error {
|
||||
return c.modifyRecord(FILL IN)
|
||||
return c.modifyRecord(FILL_IN)
|
||||
},
|
||||
}
|
||||
case diff2.DELETE:
|
||||
corr = &models.Correction{
|
||||
Msg: change.MsgsJoined,
|
||||
F: func() error {
|
||||
return c.deleteRecord(FILL IN)
|
||||
return c.deleteRecord(FILL_IN)
|
||||
},
|
||||
}
|
||||
default:
|
||||
panic("unhandled change.TYPE %s", change.Type)
|
||||
}
|
||||
|
||||
corrections = append(corrections, corr)
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package diff2
|
||||
|
||||
import "strings"
|
||||
|
||||
func processPurge(instructions ChangeList, nopurge bool) ChangeList {
|
||||
|
||||
if nopurge {
|
||||
@ -9,14 +11,30 @@ func processPurge(instructions ChangeList, nopurge bool) ChangeList {
|
||||
// TODO(tlim): This can probably be done without allocations but it
|
||||
// works and I won't want to prematurely optimize.
|
||||
|
||||
var msgs []string
|
||||
|
||||
newinstructions := make(ChangeList, 0, len(instructions))
|
||||
for _, j := range instructions {
|
||||
if j.Type == DELETE {
|
||||
msgs = append(msgs, j.Msgs...)
|
||||
continue
|
||||
}
|
||||
newinstructions = append(newinstructions, j)
|
||||
}
|
||||
|
||||
// Report what would have been purged
|
||||
if len(msgs) != 0 {
|
||||
for i := range msgs {
|
||||
msgs[i] = "NO_PURGE: Skipping " + msgs[i]
|
||||
}
|
||||
msgs = append([]string{"NO_PURGE Activated! Skipping these actions:"}, msgs...)
|
||||
newinstructions = append(newinstructions, Change{
|
||||
Type: REPORT,
|
||||
Msgs: msgs,
|
||||
MsgsJoined: strings.Join(msgs, "\n"),
|
||||
})
|
||||
}
|
||||
|
||||
return newinstructions
|
||||
|
||||
}
|
||||
|
@ -340,6 +340,9 @@ func (a *azurednsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod
|
||||
for _, inst := range instructions {
|
||||
switch inst.Type {
|
||||
|
||||
case diff2.REPORT:
|
||||
corrections = append(corrections, &models.Correction{Msg: inst.MsgsJoined})
|
||||
|
||||
case diff2.CHANGE, diff2.CREATE:
|
||||
var rrset *adns.RecordSet
|
||||
var recordName string
|
||||
@ -390,6 +393,10 @@ func (a *azurednsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled inst.Type %s", inst.Type))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -361,6 +361,9 @@ func (client *gandiv5Provider) GenerateDomainCorrections(dc *models.DomainConfig
|
||||
for _, inst := range instructions {
|
||||
switch inst.Type {
|
||||
|
||||
case diff2.REPORT:
|
||||
corrections = append(corrections, &models.Correction{Msg: inst.MsgsJoined})
|
||||
|
||||
case diff2.CREATE:
|
||||
// We have to create the label one rtype at a time.
|
||||
natives := recordsToNative(inst.New, dc.Name)
|
||||
@ -420,6 +423,9 @@ func (client *gandiv5Provider) GenerateDomainCorrections(dc *models.DomainConfig
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled inst.Type %s", inst.Type))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -158,6 +158,7 @@ func (c *gcoreProvider) GenerateDomainCorrections(dc *models.DomainConfig, exist
|
||||
// Make delete happen earlier than creates & updates.
|
||||
var corrections []*models.Correction
|
||||
var deletions []*models.Correction
|
||||
var reports []*models.Correction
|
||||
|
||||
if !diff2.EnableDiff2 {
|
||||
|
||||
@ -246,6 +247,8 @@ func (c *gcoreProvider) GenerateDomainCorrections(dc *models.DomainConfig, exist
|
||||
msg := generateChangeMsg(change.Msgs)
|
||||
|
||||
switch change.Type {
|
||||
case diff2.REPORT:
|
||||
corrections = append(corrections, &models.Correction{Msg: change.MsgsJoined})
|
||||
case diff2.CREATE:
|
||||
corrections = append(corrections, &models.Correction{
|
||||
Msg: msg,
|
||||
@ -267,9 +270,13 @@ func (c *gcoreProvider) GenerateDomainCorrections(dc *models.DomainConfig, exist
|
||||
return c.provider.DeleteRRSet(c.ctx, zone, name, typ)
|
||||
},
|
||||
})
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled change.Type %s", change.Type))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return append(deletions, corrections...), nil
|
||||
result := append(reports, deletions...)
|
||||
result = append(result, corrections...)
|
||||
return result, nil
|
||||
}
|
||||
|
@ -259,6 +259,8 @@ func (c *hednsProvider) getDiff2DomainCorrections(dc *models.DomainConfig, zoneI
|
||||
var corrections []*models.Correction
|
||||
for _, change := range changes {
|
||||
switch change.Type {
|
||||
case diff2.REPORT:
|
||||
corrections = append(corrections, &models.Correction{Msg: change.MsgsJoined})
|
||||
case diff2.CREATE:
|
||||
record := change.New[0]
|
||||
corrections = append(corrections, &models.Correction{
|
||||
@ -284,6 +286,8 @@ func (c *hednsProvider) getDiff2DomainCorrections(dc *models.DomainConfig, zoneI
|
||||
return c.deleteZoneRecord(zoneID, recordID)
|
||||
},
|
||||
})
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled change.Type %s", change.Type))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,25 +212,28 @@ func (n *nsone) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correct
|
||||
recs := change.New
|
||||
desc := strings.Join(change.Msgs, "\n")
|
||||
|
||||
if change.Type == diff2.CREATE {
|
||||
switch change.Type {
|
||||
case diff2.REPORT:
|
||||
corrections = append(corrections, &models.Correction{Msg: change.MsgsJoined})
|
||||
case diff2.CREATE:
|
||||
corrections = append(corrections, &models.Correction{
|
||||
Msg: desc,
|
||||
F: func() error { return n.add(recs, dc.Name) },
|
||||
})
|
||||
}
|
||||
if change.Type == diff2.CHANGE {
|
||||
case diff2.CHANGE:
|
||||
corrections = append(corrections, &models.Correction{
|
||||
Msg: desc,
|
||||
F: func() error { return n.modify(recs, dc.Name) },
|
||||
})
|
||||
|
||||
}
|
||||
if change.Type == diff2.DELETE {
|
||||
case diff2.DELETE:
|
||||
corrections = append(corrections, &models.Correction{
|
||||
Msg: desc,
|
||||
F: func() error { return n.remove(key, dc.Name) },
|
||||
})
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled inst.Type %s", change.Type))
|
||||
}
|
||||
|
||||
}
|
||||
return corrections, nil
|
||||
}
|
||||
|
@ -201,6 +201,8 @@ func (c *ovhProvider) getDiff2DomainCorrections(dc *models.DomainConfig, actual
|
||||
|
||||
for _, inst := range instructions {
|
||||
switch inst.Type {
|
||||
case diff2.REPORT:
|
||||
corrections = append(corrections, &models.Correction{Msg: inst.MsgsJoined})
|
||||
case diff2.CHANGE:
|
||||
corrections = append(corrections, &models.Correction{
|
||||
Msg: inst.Msgs[0],
|
||||
@ -217,6 +219,8 @@ func (c *ovhProvider) getDiff2DomainCorrections(dc *models.DomainConfig, actual
|
||||
Msg: inst.Msgs[0],
|
||||
F: c.deleteRecordFunc(rec.ID, dc.Name),
|
||||
})
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled inst.Type %s", inst.Type))
|
||||
}
|
||||
}
|
||||
return corrections, nil
|
||||
|
@ -161,6 +161,8 @@ func (c *porkbunProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||
for _, change := range changes {
|
||||
var corr *models.Correction
|
||||
switch change.Type {
|
||||
case diff2.REPORT:
|
||||
corr = &models.Correction{Msg: change.MsgsJoined}
|
||||
case diff2.CREATE:
|
||||
req, err := toReq(change.New[0])
|
||||
if err != nil {
|
||||
@ -192,6 +194,8 @@ func (c *porkbunProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||
return c.deleteRecord(dc.Name, id)
|
||||
},
|
||||
}
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled change.Type %s", change.Type))
|
||||
}
|
||||
corrections = append(corrections, corr)
|
||||
}
|
||||
|
@ -488,6 +488,9 @@ func (r *route53Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||
|
||||
switch inst.Type {
|
||||
|
||||
case diff2.REPORT:
|
||||
corrections = append(corrections, &models.Correction{Msg: inst.MsgsJoined})
|
||||
|
||||
case diff2.CREATE:
|
||||
fallthrough
|
||||
case diff2.CHANGE:
|
||||
@ -529,6 +532,10 @@ func (r *route53Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||
Action: r53Types.ChangeActionDelete,
|
||||
ResourceRecordSet: &rrset,
|
||||
}
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled inst.Type %s", inst.Type))
|
||||
|
||||
}
|
||||
|
||||
changes = append(changes, chg)
|
||||
|
@ -183,6 +183,8 @@ func (api *vultrProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||
|
||||
for _, change := range changes {
|
||||
switch change.Type {
|
||||
case diff2.REPORT:
|
||||
corrections = append(corrections, &models.Correction{Msg: change.MsgsJoined})
|
||||
case diff2.CREATE:
|
||||
r := toVultrRecord(dc, change.New[0], "0")
|
||||
corrections = append(corrections, &models.Correction{
|
||||
@ -208,6 +210,8 @@ func (api *vultrProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||
return api.client.DomainRecord.Delete(context.Background(), dc.Name, id)
|
||||
},
|
||||
})
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled change.Type %s", change.Type))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user