Skip to content

Commit

Permalink
Remove the years flag from checker.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-l-teichmann committed Aug 17, 2023
1 parent f4d00cd commit 468e91c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 37 deletions.
22 changes: 1 addition & 21 deletions cmd/csaf_checker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package main

import (
"crypto/tls"
"errors"
"fmt"
"net/http"

Expand Down Expand Up @@ -38,7 +37,6 @@ type config struct {
Version bool `long:"version" description:"Display version of the binary" toml:"-"`
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"`
Years *uint `long:"years" short:"y" description:"Number of years to look back from now" value-name:"YEARS" toml:"years"`
Range *models.TimeRange `long:"timerange" short:"t" description:"RANGE of time from which advisories to download" value-name:"RANGE" toml:"timerange"`
IgnorePattern []string `long:"ignorepattern" short:"i" description:"Do not download files if their URLs match any of the given PATTERNs" value-name:"PATTERN" toml:"ignorepattern"`
ExtraHeader http.Header `long:"header" short:"H" description:"One or more extra HTTP header fields" toml:"header"`
Expand All @@ -49,7 +47,6 @@ type config struct {
Config string `short:"c" long:"config" description:"Path to config TOML file" value-name:"TOML-FILE" toml:"-"`

clientCerts []tls.Certificate
ageAccept *models.TimeRange
ignorePattern filter.PatternMatcher
}

Expand Down Expand Up @@ -125,7 +122,7 @@ func (cfg *config) prepare() error {
return err
}

return cfg.prepareTimeRangeFilter()
return nil
}

// compileIgnorePatterns compiles the configure patterns to be ignored.
Expand All @@ -148,20 +145,3 @@ func (cfg *config) prepareCertificates() error {
cfg.clientCerts = cert
return nil
}

// prepareTimeRangeFilter sets up the filter in which time range
// advisory should be considered for checking.
func (cfg *config) prepareTimeRangeFilter() error {
switch {
case cfg.Years != nil && cfg.Range != nil:
return errors.New(`"timerange" and "years" are both configured: only one allowed`)

case cfg.Years != nil:
years := models.NYears(*cfg.Years)
cfg.ageAccept = &years

case cfg.Range != nil:
cfg.ageAccept = cfg.Range
}
return nil
}
10 changes: 5 additions & 5 deletions cmd/csaf_checker/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (p *processor) run(domains []string) (*Report, error) {
report := Report{
Date: ReportTime{Time: time.Now().UTC()},
Version: util.SemVersion,
TimeRange: p.cfg.ageAccept,
TimeRange: p.cfg.Range,
}

for _, d := range domains {
Expand Down Expand Up @@ -546,7 +546,7 @@ func (p *processor) rolieFeedEntries(feed string) ([]csaf.AdvisoryFile, error) {
rfeed.Entries(func(entry *csaf.Entry) {

// Filter if we have date checking.
if accept := p.cfg.ageAccept; accept != nil {
if accept := p.cfg.Range; accept != nil {
if pub := time.Time(entry.Published); !pub.IsZero() && !accept.Contains(pub) {
return
}
Expand Down Expand Up @@ -667,7 +667,7 @@ func (p *processor) integrity(
if m := yearFromURL.FindStringSubmatch(u); m != nil {
year, _ := strconv.Atoi(m[1])
// Check if we are in checking time interval.
if accept := p.cfg.ageAccept; accept != nil && !accept.Contains(
if accept := p.cfg.Range; accept != nil && !accept.Contains(
time.Date(
year, 12, 31, // Assume last day of year.
23, 59, 59, 0, // 23:59:59
Expand Down Expand Up @@ -973,7 +973,7 @@ func (p *processor) checkChanges(base string, mask whereType) error {
return nil, nil, err
}
// Apply date range filtering.
if accept := p.cfg.ageAccept; accept != nil && !accept.Contains(t) {
if accept := p.cfg.Range; accept != nil && !accept.Contains(t) {
continue
}
path := r[pathColumn]
Expand All @@ -990,7 +990,7 @@ func (p *processor) checkChanges(base string, mask whereType) error {

if len(files) == 0 {
var filtered string
if p.cfg.ageAccept != nil {
if p.cfg.Range != nil {
filtered = " (maybe filtered out by time interval)"
}
p.badChanges.warn("no entries in changes.csv found" + filtered)
Expand Down
6 changes: 2 additions & 4 deletions docs/csaf_checker.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Application Options:
--version Display version of the binary
-v, --verbose Verbose output
-r, --rate= The average upper limit of https operations per second (defaults to unlimited)
-y, --years=YEARS Number of years to look back from now
-t, --timerange=RANGE RANGE of time from which advisories to download
-i, --ignorepattern=PATTERN Do not download files if their URLs match any of the given PATTERNs
-H, --header= One or more extra HTTP header fields
Expand Down Expand Up @@ -51,7 +50,6 @@ insecure = false
# client_passphrase # not set by default
verbose = false
# rate # not set by default
# years # not set by default
# timerange # not set by default
# header # not set by default
# validator # not set by default
Expand All @@ -71,9 +69,9 @@ type 2: error

The checker result is a success if no checks resulted in type 2, and a failure otherwise.

The options `years` and `timerange` allow to only check advisories from a given time interval.
The option `timerange` allows to only check advisories from a given time interval.
It is only allowed to specify one off them.
`years` looks number of years back from now. `timerange` values allow finer controls:
There are following variants:

1. Relative. If the given string follows the rules of being a [Go duration](https://pkg.go.dev/[email protected]#ParseDuration)
the time interval from now minus that duration till now is used.
Expand Down
7 changes: 0 additions & 7 deletions internal/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ func NewTimeInterval(a, b time.Time) TimeRange {
return TimeRange{a, b}
}

// NYears returns a time interval spanning the last years.
func NYears(years uint) TimeRange {
now := time.Now()
start := now.AddDate(-int(years), 0, 0)
return NewTimeInterval(start, now)
}

// guessDate tries to guess an RFC 3339 date time from a given string.
func guessDate(s string) (time.Time, bool) {
for _, layout := range []string{
Expand Down

0 comments on commit 468e91c

Please sign in to comment.