better error message, actually clear unused cached lookups.

This commit is contained in:
Craig Peterson 2017-10-02 12:31:30 -04:00
parent 49038cf51c
commit 373b4e4b83
2 changed files with 7 additions and 3 deletions

View file

@ -71,7 +71,7 @@ func flattenSPFs(cfg *models.DNSConfig) []error {
if err := cache.Save("spfcache.updated.json"); err != nil {
errs = append(errs, err)
} else {
errs = append(errs, Warning{fmt.Errorf("%d spf record lookups are out of date with cache (%s). Wrote changes to dnscache.updated.json. Please rename and commit", len(changed), strings.Join(changed, ","))})
errs = append(errs, Warning{fmt.Errorf("%d spf record lookups are out of date with cache (%s). Wrote changes to spfcache.updated.json. Please rename and commit:\nmv spfcache.updated.json spfcache.json", len(changed), strings.Join(changed, ","))})
}
}
}

View file

@ -125,11 +125,15 @@ func (c *cache) ResolveErrors() (errs []error) {
return
}
func (c *cache) Save(filename string) error {
for _, entry := range c.records {
outRecs := make(map[string]*cacheEntry, len(c.records))
for k, entry := range c.records {
// move resolved data into cached field
// only take those we actually resolved
if entry.resolvedSPF != "" {
entry.SPF = entry.resolvedSPF
outRecs[k] = entry
}
}
dat, _ := json.MarshalIndent(c.records, "", " ")
dat, _ := json.MarshalIndent(outRecs, "", " ")
return ioutil.WriteFile(filename, dat, 0644)
}