mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Add time interval filtering to downloader.
This commit is contained in:
parent
0e297fc616
commit
de0599ebe3
4 changed files with 36 additions and 12 deletions
|
|
@ -10,7 +10,9 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"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/internal/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -27,6 +29,7 @@ type config struct {
|
||||||
Verbose bool `long:"verbose" short:"v" description:"Verbose output" toml:"verbose"`
|
Verbose bool `long:"verbose" short:"v" description:"Verbose output" toml:"verbose"`
|
||||||
Rate *float64 `long:"rate" short:"r" description:"The average upper limit of https operations per second (defaults to unlimited)" toml:"rate"`
|
Rate *float64 `long:"rate" short:"r" description:"The average upper limit of https operations per second (defaults to unlimited)" toml:"rate"`
|
||||||
Worker int `long:"worker" short:"w" description:"NUMber of concurrent downloads" value-name:"NUM" toml:"worker"`
|
Worker int `long:"worker" short:"w" description:"NUMber of concurrent downloads" value-name:"NUM" toml:"worker"`
|
||||||
|
Range *models.TimeRange `long:"timerange" short:"t" description:"RANGE of time from which advisories to download" value-name:"RANGE" toml:"timerange"`
|
||||||
|
|
||||||
ExtraHeader http.Header `long:"header" short:"H" description:"One or more extra HTTP header fields" toml:"header"`
|
ExtraHeader http.Header `long:"header" short:"H" description:"One or more extra HTTP header fields" toml:"header"`
|
||||||
|
|
||||||
|
|
@ -35,6 +38,8 @@ type config struct {
|
||||||
RemoteValidatorPresets []string `long:"validatorpreset" description:"One or more PRESETS to validate remotely" value-name:"PRESETS" toml:"validatorpreset"`
|
RemoteValidatorPresets []string `long:"validatorpreset" description:"One or more PRESETS to validate remotely" value-name:"PRESETS" toml:"validatorpreset"`
|
||||||
|
|
||||||
Config string `short:"c" long:"config" description:"Path to config TOML file" value-name:"TOML-FILE" toml:"-"`
|
Config string `short:"c" long:"config" description:"Path to config TOML file" value-name:"TOML-FILE" toml:"-"`
|
||||||
|
|
||||||
|
ageAccept func(time.Time) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// configPaths are the potential file locations of the config file.
|
// configPaths are the potential file locations of the config file.
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,11 @@ func (d *downloader) download(ctx context.Context, domain string) error {
|
||||||
base,
|
base,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
|
// Do we need time range based filtering?
|
||||||
|
if d.cfg.Range != nil {
|
||||||
|
afp.AgeAccept = d.cfg.Range.Contains
|
||||||
|
}
|
||||||
|
|
||||||
return afp.Process(func(label csaf.TLPLabel, files []csaf.AdvisoryFile) error {
|
return afp.Process(func(label csaf.TLPLabel, files []csaf.AdvisoryFile) error {
|
||||||
return d.downloadFiles(ctx, label, files)
|
return d.downloadFiles(ctx, label, files)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/csaf-poc/csaf_distribution/v2/util"
|
"github.com/csaf-poc/csaf_distribution/v2/util"
|
||||||
)
|
)
|
||||||
|
|
@ -71,6 +72,7 @@ func (haf HashedAdvisoryFile) SignURL() string { return haf.name(3, ".asc") }
|
||||||
// AdvisoryFileProcessor implements the extraction of
|
// AdvisoryFileProcessor implements the extraction of
|
||||||
// advisory file names from a given provider metadata.
|
// advisory file names from a given provider metadata.
|
||||||
type AdvisoryFileProcessor struct {
|
type AdvisoryFileProcessor struct {
|
||||||
|
AgeAccept func(time.Time) bool
|
||||||
client util.Client
|
client util.Client
|
||||||
expr *util.PathEval
|
expr *util.PathEval
|
||||||
doc any
|
doc any
|
||||||
|
|
@ -287,6 +289,13 @@ func (afp *AdvisoryFileProcessor) processROLIE(
|
||||||
|
|
||||||
rfeed.Entries(func(entry *Entry) {
|
rfeed.Entries(func(entry *Entry) {
|
||||||
|
|
||||||
|
// Filter if we have date checking.
|
||||||
|
if afp.AgeAccept != nil {
|
||||||
|
if pub := time.Time(entry.Published); !pub.IsZero() && !afp.AgeAccept(pub) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var self, sha256, sha512, sign string
|
var self, sha256, sha512, sign string
|
||||||
|
|
||||||
for i := range entry.Link {
|
for i := range entry.Link {
|
||||||
|
|
|
||||||
|
|
@ -79,3 +79,8 @@ func (tr *TimeRange) UnmarshalText(text []byte) error {
|
||||||
*tr = NewTimeInterval(start, end)
|
*tr = NewTimeInterval(start, end)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Contains return true if the given time is inside this time interval.
|
||||||
|
func (tr TimeRange) Contains(t time.Time) bool {
|
||||||
|
return !(t.Before(tr[0]) || t.After(tr[1]))
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue