mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 18:15:42 +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/csaf"
|
||||||
"github.com/csaf-poc/csaf_distribution/v2/internal/certs"
|
"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/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/internal/options"
|
||||||
"github.com/csaf-poc/csaf_distribution/v2/util"
|
"github.com/csaf-poc/csaf_distribution/v2/util"
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
|
|
@ -61,6 +62,8 @@ type provider struct {
|
||||||
ClientKey *string `toml:"client_key"`
|
ClientKey *string `toml:"client_key"`
|
||||||
ClientPassphrase *string `toml:"client_passphrase"`
|
ClientPassphrase *string `toml:"client_passphrase"`
|
||||||
|
|
||||||
|
Range *models.TimeRange `toml:"timerange"`
|
||||||
|
|
||||||
clientCerts []tls.Certificate
|
clientCerts []tls.Certificate
|
||||||
ignorePattern filter.PatternMatcher
|
ignorePattern filter.PatternMatcher
|
||||||
}
|
}
|
||||||
|
|
@ -88,6 +91,8 @@ type config struct {
|
||||||
ClientKey *string `toml:"client_key"`
|
ClientKey *string `toml:"client_key"`
|
||||||
ClientPassphrase *string `toml:"client_passphrase"`
|
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 tries to lock to a given file.
|
||||||
LockFile *string `toml:"lock_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) }
|
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.
|
// ignoreFile returns true if the given URL should not be downloaded.
|
||||||
func (p *provider) ignoreURL(u string, c *config) bool {
|
func (p *provider) ignoreURL(u string, c *config) bool {
|
||||||
return p.ignorePattern.Matches(u) || c.ignorePattern.Matches(u)
|
return p.ignorePattern.Matches(u) || c.ignorePattern.Matches(u)
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,8 @@ func (w *worker) mirrorInternal() (*csaf.AggregatorCSAFProvider, error) {
|
||||||
w.metadataProvider,
|
w.metadataProvider,
|
||||||
base)
|
base)
|
||||||
|
|
||||||
|
afp.AgeAccept = w.provider.ageAccept(w.processor.cfg)
|
||||||
|
|
||||||
if err := afp.Process(w.mirrorFiles); err != nil {
|
if err := afp.Process(w.mirrorFiles); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -494,6 +496,7 @@ func (w *worker) mirrorFiles(tlpLabel csaf.TLPLabel, files []csaf.AdvisoryFile)
|
||||||
yearDirs := make(map[int]string)
|
yearDirs := make(map[int]string)
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
|
||||||
u, err := url.Parse(file.URL())
|
u, err := url.Parse(file.URL())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error: %s\n", err)
|
log.Printf("error: %s\n", err)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
csaf_aggregator [OPTIONS]
|
csaf_aggregator [OPTIONS]
|
||||||
|
|
||||||
Application Options:
|
Application Options:
|
||||||
|
-t, --timerange=RANGE RANGE of time from which advisories to download
|
||||||
-i, --interim Perform an interim scan
|
-i, --interim Perform an interim scan
|
||||||
--version Display version of the binary
|
--version Display version of the binary
|
||||||
-c, --config=TOML-FILE Path to config TOML file
|
-c, --config=TOML-FILE Path to config TOML file
|
||||||
|
|
@ -99,6 +100,7 @@ client_cert // path to client certificate to access access-protected
|
||||||
client_key // path to client key to access access-protected advisories
|
client_key // path to client key to access access-protected advisories
|
||||||
client_passphrase // client passphrase to access access-protected advisories
|
client_passphrase // client passphrase to access access-protected advisories
|
||||||
header // adds extra HTTP header fields to the client
|
header // adds extra HTTP header fields to the client
|
||||||
|
timerange // Accepted time range of advisories to handle. See checker doc for details.
|
||||||
```
|
```
|
||||||
|
|
||||||
Next we have two TOML _tables_:
|
Next we have two TOML _tables_:
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ insecure = true
|
||||||
#interim_years =
|
#interim_years =
|
||||||
#passphrase =
|
#passphrase =
|
||||||
#write_indices = false
|
#write_indices = false
|
||||||
|
#timerange =
|
||||||
|
|
||||||
# specification requires at least two providers (default),
|
# specification requires at least two providers (default),
|
||||||
# to override for testing, enable:
|
# to override for testing, enable:
|
||||||
|
|
@ -31,6 +32,7 @@ insecure = true
|
||||||
create_service_document = true
|
create_service_document = true
|
||||||
# rate = 1.5
|
# rate = 1.5
|
||||||
# insecure = true
|
# insecure = true
|
||||||
|
# timerange =
|
||||||
|
|
||||||
[[providers]]
|
[[providers]]
|
||||||
name = "local-dev-provider2"
|
name = "local-dev-provider2"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue