Move resolving unbreak filter list IDs to filterlists module

This commit is contained in:
Daniel
2022-08-30 13:54:34 +02:00
parent 8a98f69fca
commit 092b1cd8a0
3 changed files with 39 additions and 16 deletions

View File

@@ -196,8 +196,12 @@ func updateListIndex() error {
listIndexUpdate.Version(),
)
default:
log.Debug("filterlists: index is up to date")
// List is in cache and current, there is nothing to do.
log.Debug("filterlists: index is up to date")
// Update the unbreak filter list IDs on initial load.
updateUnbreakFilterListIDs()
return nil
}
case listIndexUpdate.UpgradeAvailable():
@@ -225,6 +229,9 @@ func updateListIndex() error {
}
log.Debugf("intel/filterlists: updated list index in cache to %s", index.Version)
// Update the unbreak filter list IDs after an update.
updateUnbreakFilterListIDs()
return nil
}
@@ -252,3 +259,30 @@ func ResolveListIDs(ids []string) ([]string, error) {
return resolved, nil
}
var (
unbreakCategoryIDs = []string{"UNBREAK"}
unbreakIDs []string
unbreakIDsLock sync.Mutex
)
// GetUnbreakFilterListIDs returns the resolved list of all unbreak filter lists.
func GetUnbreakFilterListIDs() []string {
unbreakIDsLock.Lock()
defer unbreakIDsLock.Unlock()
return unbreakIDs
}
func updateUnbreakFilterListIDs() {
unbreakIDsLock.Lock()
defer unbreakIDsLock.Unlock()
resolvedIDs, err := ResolveListIDs(unbreakCategoryIDs)
if err != nil {
log.Warningf("filter: failed to resolve unbreak filter list IDs: %s", err)
} else {
unbreakIDs = resolvedIDs
}
}