mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
FEATURE: Truncate report of ignored/purged items unless --full (#2203)
Co-authored-by: Tom Limoncelli <tal@whatexit.org>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/v3/models"
|
"github.com/StackExchange/dnscontrol/v3/models"
|
||||||
|
"github.com/StackExchange/dnscontrol/v3/pkg/printer"
|
||||||
"github.com/gobwas/glob"
|
"github.com/gobwas/glob"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -97,6 +98,8 @@ The actual implementation combines this all into one loop:
|
|||||||
Append "foreign list" to "desired".
|
Append "foreign list" to "desired".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const maxReport = 5
|
||||||
|
|
||||||
// handsoff processes the IGNORE_*/UNMANAGED/NO_PURGE/ENSURE_ABSENT features.
|
// handsoff processes the IGNORE_*/UNMANAGED/NO_PURGE/ENSURE_ABSENT features.
|
||||||
func handsoff(
|
func handsoff(
|
||||||
domain string,
|
domain string,
|
||||||
@@ -117,15 +120,11 @@ func handsoff(
|
|||||||
ignorable, foreign := processIgnoreAndNoPurge(domain, existing, desired, absences, unmanagedConfigs, noPurge)
|
ignorable, foreign := processIgnoreAndNoPurge(domain, existing, desired, absences, unmanagedConfigs, noPurge)
|
||||||
if len(foreign) != 0 {
|
if len(foreign) != 0 {
|
||||||
msgs = append(msgs, fmt.Sprintf("INFO: %d records not being deleted because of NO_PURGE:", len(foreign)))
|
msgs = append(msgs, fmt.Sprintf("INFO: %d records not being deleted because of NO_PURGE:", len(foreign)))
|
||||||
for _, r := range foreign {
|
msgs = append(msgs, reportSkips(foreign, !printer.SkinnyReport)...)
|
||||||
msgs = append(msgs, fmt.Sprintf(" %s. %s %s", r.GetLabelFQDN(), r.Type, r.GetTargetRFC1035Quoted()))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if len(ignorable) != 0 {
|
if len(ignorable) != 0 {
|
||||||
msgs = append(msgs, fmt.Sprintf("INFO: %d records not being deleted because of IGNORE*():", len(ignorable)))
|
msgs = append(msgs, fmt.Sprintf("INFO: %d records not being deleted because of IGNORE*():", len(ignorable)))
|
||||||
for _, r := range ignorable {
|
msgs = append(msgs, reportSkips(ignorable, !printer.SkinnyReport)...)
|
||||||
msgs = append(msgs, fmt.Sprintf(" %s %s %s", r.GetLabelFQDN(), r.Type, r.GetTargetRFC1035Quoted()))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for invalid use of IGNORE_*.
|
// Check for invalid use of IGNORE_*.
|
||||||
@@ -147,6 +146,26 @@ func handsoff(
|
|||||||
return desired, msgs, nil
|
return desired, msgs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reportSkips reports records being skipped, if !full only the first maxReport are output.
|
||||||
|
func reportSkips(recs models.Records, full bool) []string {
|
||||||
|
var msgs []string
|
||||||
|
|
||||||
|
shorten := (!full) && (len(recs) > maxReport)
|
||||||
|
last := len(recs)
|
||||||
|
if shorten {
|
||||||
|
last = maxReport
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range recs[:last] {
|
||||||
|
msgs = append(msgs, fmt.Sprintf(" %s. %s %s", r.GetLabelFQDN(), r.Type, r.GetTargetRFC1035Quoted()))
|
||||||
|
}
|
||||||
|
if shorten {
|
||||||
|
msgs = append(msgs, fmt.Sprintf(" ...and %d more... (use --full to show all)", len(recs)-maxReport))
|
||||||
|
}
|
||||||
|
|
||||||
|
return msgs
|
||||||
|
}
|
||||||
|
|
||||||
// processIgnoreAndNoPurge processes the IGNORE_*()/UNMANAGED() and NO_PURGE/ENSURE_ABSENT_REC() features.
|
// processIgnoreAndNoPurge processes the IGNORE_*()/UNMANAGED() and NO_PURGE/ENSURE_ABSENT_REC() features.
|
||||||
func processIgnoreAndNoPurge(domain string, existing, desired, absences models.Records, unmanagedConfigs []*models.UnmanagedConfig, noPurge bool) (models.Records, models.Records) {
|
func processIgnoreAndNoPurge(domain string, existing, desired, absences models.Records, unmanagedConfigs []*models.UnmanagedConfig, noPurge bool) (models.Records, models.Records) {
|
||||||
var ignorable, foreign models.Records
|
var ignorable, foreign models.Records
|
||||||
|
@@ -473,7 +473,7 @@ func (r *route53Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
changes := []r53Types.Change{}
|
changes := []r53Types.Change{}
|
||||||
changeDesc := []string{}
|
changeDesc := []string{} // TODO(tlim): This should be a [][]string so that we aren't joining strings until the last moment.
|
||||||
|
|
||||||
// Amazon Route53 is a "ByRecordSet" API.
|
// Amazon Route53 is a "ByRecordSet" API.
|
||||||
// At each label:rtype pair, we either delete all records or UPSERT the desired records.
|
// At each label:rtype pair, we either delete all records or UPSERT the desired records.
|
||||||
@@ -540,7 +540,7 @@ func (r *route53Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
changes = append(changes, chg)
|
changes = append(changes, chg)
|
||||||
changeDesc = append(changeDesc, inst.Msgs...)
|
changeDesc = append(changeDesc, inst.MsgsJoined)
|
||||||
}
|
}
|
||||||
|
|
||||||
addCorrection := func(msg string, req *r53.ChangeResourceRecordSetsInput) {
|
addCorrection := func(msg string, req *r53.ChangeResourceRecordSetsInput) {
|
||||||
|
Reference in New Issue
Block a user