mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Add time range to checker report.
This commit is contained in:
parent
b6e5af9b49
commit
873eb4879b
5 changed files with 54 additions and 24 deletions
|
|
@ -13,7 +13,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/csaf-poc/csaf_distribution/v2/internal/filter"
|
||||
"github.com/csaf-poc/csaf_distribution/v2/internal/models"
|
||||
|
|
@ -49,7 +48,7 @@ type config struct {
|
|||
Config string `short:"c" long:"config" description:"Path to config TOML file" value-name:"TOML-FILE" toml:"-"`
|
||||
|
||||
clientCerts []tls.Certificate
|
||||
ageAccept func(time.Time) bool
|
||||
ageAccept *models.TimeRange
|
||||
ignorePattern filter.PatternMatcher
|
||||
}
|
||||
|
||||
|
|
@ -156,14 +155,6 @@ func (cfg *config) prepareCertificates() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// acceptYears returns a filter that accepts advisories from the last years.
|
||||
func acceptYears(years uint) func(time.Time) bool {
|
||||
good := time.Now().AddDate(-int(years), 0, 0)
|
||||
return func(t time.Time) bool {
|
||||
return !t.Before(good)
|
||||
}
|
||||
}
|
||||
|
||||
// prepareTimeRangeFilter sets up the filter in which time range
|
||||
// advisory should be considered for checking.
|
||||
func (cfg *config) prepareTimeRangeFilter() error {
|
||||
|
|
@ -172,10 +163,11 @@ func (cfg *config) prepareTimeRangeFilter() error {
|
|||
return errors.New(`"timerange" and "years" are both configured: only one allowed`)
|
||||
|
||||
case cfg.Years != nil:
|
||||
cfg.ageAccept = acceptYears(*cfg.Years)
|
||||
years := models.NYears(*cfg.Years)
|
||||
cfg.ageAccept = &years
|
||||
|
||||
case cfg.Range != nil:
|
||||
cfg.ageAccept = cfg.Range.Contains
|
||||
cfg.ageAccept = cfg.Range
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -241,8 +241,9 @@ func (p *processor) clean() {
|
|||
func (p *processor) run(domains []string) (*Report, error) {
|
||||
|
||||
report := Report{
|
||||
Date: ReportTime{Time: time.Now().UTC()},
|
||||
Version: util.SemVersion,
|
||||
Date: ReportTime{Time: time.Now().UTC()},
|
||||
Version: util.SemVersion,
|
||||
TimeRange: p.cfg.ageAccept,
|
||||
}
|
||||
|
||||
for _, d := range domains {
|
||||
|
|
@ -545,8 +546,8 @@ func (p *processor) rolieFeedEntries(feed string) ([]csaf.AdvisoryFile, error) {
|
|||
rfeed.Entries(func(entry *csaf.Entry) {
|
||||
|
||||
// Filter if we have date checking.
|
||||
if p.cfg.ageAccept != nil {
|
||||
if pub := time.Time(entry.Published); !pub.IsZero() && !p.cfg.ageAccept(pub) {
|
||||
if accept := p.cfg.ageAccept; accept != nil {
|
||||
if pub := time.Time(entry.Published); !pub.IsZero() && !accept.Contains(pub) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -666,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 p.cfg.ageAccept != nil && !p.cfg.ageAccept(
|
||||
if accept := p.cfg.ageAccept; accept != nil && !accept.Contains(
|
||||
time.Date(
|
||||
year, 12, 31, // Assume last day of year.
|
||||
23, 59, 59, 0, // 23:59:59
|
||||
|
|
@ -972,7 +973,7 @@ func (p *processor) checkChanges(base string, mask whereType) error {
|
|||
return nil, nil, err
|
||||
}
|
||||
// Apply date range filtering.
|
||||
if p.cfg.ageAccept != nil && !p.cfg.ageAccept(t) {
|
||||
if accept := p.cfg.ageAccept; accept != nil && !accept.Contains(t) {
|
||||
continue
|
||||
}
|
||||
path := r[pathColumn]
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/csaf-poc/csaf_distribution/v2/csaf"
|
||||
"github.com/csaf-poc/csaf_distribution/v2/internal/models"
|
||||
)
|
||||
|
||||
// MessageType is the kind of the message.
|
||||
|
|
@ -60,9 +61,10 @@ type ReportTime struct{ time.Time }
|
|||
|
||||
// Report is the overall report.
|
||||
type Report struct {
|
||||
Domains []*Domain `json:"domains,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Date ReportTime `json:"date,omitempty"`
|
||||
Domains []*Domain `json:"domains,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Date ReportTime `json:"date,omitempty"`
|
||||
TimeRange *models.TimeRange `json:"timerange,omitempty"`
|
||||
}
|
||||
|
||||
// MarshalText implements the encoding.TextMarshaller interface.
|
||||
|
|
|
|||
|
|
@ -62,8 +62,26 @@
|
|||
{{ end }}
|
||||
|
||||
<footer>
|
||||
Date of run: <time datetime="{{.Date.Format "2006-01-02T15:04:05Z"}}">{{ .Date.Local.Format "Monday, 02 Jan 2006 15:04:05 MST" }}</time>
|
||||
csaf_checker v<span class="version">{{ .Version }}</span>
|
||||
<fieldset>
|
||||
<legend>Runtime</legend>
|
||||
<table>
|
||||
<tr>
|
||||
<td><strong>Date of run:</strong></td>
|
||||
<td><time datetime="{{ .Date.Format "2006-01-02T15:04:05Z"}}">{{ .Date.Local.Format "Monday, 02 Jan 2006 15:04:05 MST" }}</time></td>
|
||||
</tr>
|
||||
{{ if .TimeRange }}{{ with .TimeRange }}
|
||||
<tr>
|
||||
<td><strong>Time range:</strong></td>
|
||||
<td><time datetime="{{ (index . 0).Format "2006-01-02T15:04:05Z"}}">{{ (index . 0).Local.Format "Monday, 02 Jan 2006 15:04:05 MST" }}</time> -
|
||||
<time datetime="{{ (index . 1).Format "2006-01-02T15:04:05Z"}}">{{ (index . 1).Local.Format "Monday, 02 Jan 2006 15:04:05 MST" }}</time></td>
|
||||
</tr>
|
||||
{{ end }}{{ end }}
|
||||
<tr>
|
||||
<td><strong>Version:</strong></td>
|
||||
<td>csaf_checker v<span class="version">{{ .Version }}</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue