mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Aggregator: Add time range filtering
This commit is contained in:
parent
42709a8554
commit
d49049c3af
4 changed files with 26 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/csaf-poc/csaf_distribution/v2/csaf"
|
||||
"github.com/csaf-poc/csaf_distribution/v2/internal/certs"
|
||||
"github.com/csaf-poc/csaf_distribution/v2/internal/filter"
|
||||
"github.com/csaf-poc/csaf_distribution/v2/internal/models"
|
||||
"github.com/csaf-poc/csaf_distribution/v2/internal/options"
|
||||
"github.com/csaf-poc/csaf_distribution/v2/util"
|
||||
"golang.org/x/time/rate"
|
||||
|
|
@ -61,6 +62,8 @@ type provider struct {
|
|||
ClientKey *string `toml:"client_key"`
|
||||
ClientPassphrase *string `toml:"client_passphrase"`
|
||||
|
||||
Range *models.TimeRange `toml:"timerange"`
|
||||
|
||||
clientCerts []tls.Certificate
|
||||
ignorePattern filter.PatternMatcher
|
||||
}
|
||||
|
|
@ -88,6 +91,8 @@ type config struct {
|
|||
ClientKey *string `toml:"client_key"`
|
||||
ClientPassphrase *string `toml:"client_passphrase"`
|
||||
|
||||
Range *models.TimeRange `long:"timerange" short:"t" description:"RANGE of time from which advisories to download" value-name:"RANGE" toml:"timerange"`
|
||||
|
||||
// LockFile tries to lock to a given file.
|
||||
LockFile *string `toml:"lock_file"`
|
||||
|
||||
|
|
@ -156,6 +161,20 @@ func (c *config) tooOldForInterims() func(time.Time) bool {
|
|||
return func(t time.Time) bool { return t.Before(from) }
|
||||
}
|
||||
|
||||
// ageAccept returns a function which checks if a given time
|
||||
// is in the accepted download interval of the provider or
|
||||
// the global config.
|
||||
func (p *provider) ageAccept(c *config) func(time.Time) bool {
|
||||
switch {
|
||||
case p.Range != nil:
|
||||
return p.Range.Contains
|
||||
case c.Range != nil:
|
||||
return c.Range.Contains
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ignoreFile returns true if the given URL should not be downloaded.
|
||||
func (p *provider) ignoreURL(u string, c *config) bool {
|
||||
return p.ignorePattern.Matches(u) || c.ignorePattern.Matches(u)
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ func (w *worker) mirrorInternal() (*csaf.AggregatorCSAFProvider, error) {
|
|||
w.metadataProvider,
|
||||
base)
|
||||
|
||||
afp.AgeAccept = w.provider.ageAccept(w.processor.cfg)
|
||||
|
||||
if err := afp.Process(w.mirrorFiles); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -494,6 +496,7 @@ func (w *worker) mirrorFiles(tlpLabel csaf.TLPLabel, files []csaf.AdvisoryFile)
|
|||
yearDirs := make(map[int]string)
|
||||
|
||||
for _, file := range files {
|
||||
|
||||
u, err := url.Parse(file.URL())
|
||||
if err != nil {
|
||||
log.Printf("error: %s\n", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue