mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Allow configuration of time range and ignore patterns
This commit is contained in:
parent
fe12aaf993
commit
3cf7b73672
3 changed files with 20 additions and 19 deletions
|
|
@ -213,7 +213,7 @@ func (cfg *config) prepareCertificates() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare prepares internal state of a loaded configuration.
|
// GetDownloadConfig Prepare prepares internal state of a loaded configuration.
|
||||||
func (cfg *config) GetDownloadConfig() (*downloader.Config, error) {
|
func (cfg *config) GetDownloadConfig() (*downloader.Config, error) {
|
||||||
for _, prepare := range []func(*config) error{
|
for _, prepare := range []func(*config) error{
|
||||||
(*config).prepareDirectory,
|
(*config).prepareDirectory,
|
||||||
|
|
@ -233,7 +233,7 @@ func (cfg *config) GetDownloadConfig() (*downloader.Config, error) {
|
||||||
ClientPassphrase: cfg.ClientPassphrase,
|
ClientPassphrase: cfg.ClientPassphrase,
|
||||||
Rate: cfg.Rate,
|
Rate: cfg.Rate,
|
||||||
Worker: cfg.Worker,
|
Worker: cfg.Worker,
|
||||||
Range: cfg.Range,
|
Range: (*[2]time.Time)(cfg.Range),
|
||||||
IgnorePattern: cfg.ignorePattern,
|
IgnorePattern: cfg.ignorePattern,
|
||||||
ExtraHeader: cfg.ExtraHeader,
|
ExtraHeader: cfg.ExtraHeader,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"github.com/csaf-poc/csaf_distribution/v3/internal/filter"
|
"time"
|
||||||
"github.com/csaf-poc/csaf_distribution/v3/internal/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ValidationMode specifies the strict the validation is.
|
// ValidationMode specifies the strict the validation is.
|
||||||
|
|
@ -37,8 +36,8 @@ type Config struct {
|
||||||
ClientPassphrase *string
|
ClientPassphrase *string
|
||||||
Rate *float64
|
Rate *float64
|
||||||
Worker int
|
Worker int
|
||||||
Range *models.TimeRange
|
Range *[2]time.Time
|
||||||
IgnorePattern filter.PatternMatcher
|
IgnorePattern []*regexp.Regexp
|
||||||
ExtraHeader http.Header
|
ExtraHeader http.Header
|
||||||
|
|
||||||
RemoteValidator string
|
RemoteValidator string
|
||||||
|
|
@ -82,7 +81,13 @@ func (vm *ValidationMode) UnmarshalFlag(value string) error {
|
||||||
|
|
||||||
// ignoreFile returns true if the given URL should not be downloaded.
|
// ignoreFile returns true if the given URL should not be downloaded.
|
||||||
func (cfg *Config) ignoreURL(u string) bool {
|
func (cfg *Config) ignoreURL(u string) bool {
|
||||||
return cfg.IgnorePattern.Matches(u)
|
for _, expr := range cfg.IgnorePattern {
|
||||||
|
if expr.MatchString(u) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// verbose is considered a log level equal or less debug.
|
// verbose is considered a log level equal or less debug.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/csaf-poc/csaf_distribution/v3/internal/models"
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
@ -25,7 +26,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
|
|
@ -56,11 +56,6 @@ type DownloadedDocument struct {
|
||||||
ValStatus ValidationStatus
|
ValStatus ValidationStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
// failedValidationDir is the name of the sub folder
|
|
||||||
// where advisories are stored that fail validation in
|
|
||||||
// unsafe mode.
|
|
||||||
const failedValidationDir = "failed_validation"
|
|
||||||
|
|
||||||
// NewDownloader constructs a new downloader given the configuration.
|
// NewDownloader constructs a new downloader given the configuration.
|
||||||
func NewDownloader(cfg *Config) (*Downloader, error) {
|
func NewDownloader(cfg *Config) (*Downloader, error) {
|
||||||
var validator csaf.RemoteValidator
|
var validator csaf.RemoteValidator
|
||||||
|
|
@ -179,7 +174,7 @@ func (d *Downloader) enumerate(domain string) error {
|
||||||
loader := csaf.NewProviderMetadataLoader(client)
|
loader := csaf.NewProviderMetadataLoader(client)
|
||||||
lpmd := loader.Enumerate(domain)
|
lpmd := loader.Enumerate(domain)
|
||||||
|
|
||||||
docs := []any{}
|
var docs []any
|
||||||
|
|
||||||
for _, pmd := range lpmd {
|
for _, pmd := range lpmd {
|
||||||
if d.cfg.verbose() {
|
if d.cfg.verbose() {
|
||||||
|
|
@ -249,9 +244,10 @@ func (d *Downloader) download(ctx context.Context, domain string) error {
|
||||||
|
|
||||||
// Do we need time range based filtering?
|
// Do we need time range based filtering?
|
||||||
if d.cfg.Range != nil {
|
if d.cfg.Range != nil {
|
||||||
|
timeRange := models.NewTimeInterval(d.cfg.Range[0], d.cfg.Range[1])
|
||||||
d.cfg.Logger.Debug("Setting up filter to accept advisories within",
|
d.cfg.Logger.Debug("Setting up filter to accept advisories within",
|
||||||
"timerange", d.cfg.Range)
|
"timerange", timeRange)
|
||||||
afp.AgeAccept = d.cfg.Range.Contains
|
afp.AgeAccept = timeRange.Contains
|
||||||
}
|
}
|
||||||
|
|
||||||
return afp.Process(func(label csaf.TLPLabel, files []csaf.AdvisoryFile) error {
|
return afp.Process(func(label csaf.TLPLabel, files []csaf.AdvisoryFile) error {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue