mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 18:15:42 +01:00
Merge pull request #278 from csaf-poc/aggregator_publishers
Tested multiple times, works as intended.
This commit is contained in:
commit
4f3f7efd5a
3 changed files with 59 additions and 19 deletions
|
|
@ -31,6 +31,7 @@ const (
|
||||||
defaultFolder = "/var/www"
|
defaultFolder = "/var/www"
|
||||||
defaultWeb = "/var/www/html"
|
defaultWeb = "/var/www/html"
|
||||||
defaultDomain = "https://example.com"
|
defaultDomain = "https://example.com"
|
||||||
|
defaultUpdateInterval = "on best effort"
|
||||||
)
|
)
|
||||||
|
|
||||||
type provider struct {
|
type provider struct {
|
||||||
|
|
@ -44,6 +45,9 @@ type provider struct {
|
||||||
// ServiceDocument incidates if we should create a service.json document.
|
// ServiceDocument incidates if we should create a service.json document.
|
||||||
ServiceDocument *bool `toml:"create_service_document"`
|
ServiceDocument *bool `toml:"create_service_document"`
|
||||||
AggregatoryCategory *csaf.AggregatorCategory `toml:"category"`
|
AggregatoryCategory *csaf.AggregatorCategory `toml:"category"`
|
||||||
|
|
||||||
|
// UpdateInterval is as the mandatory `update_interval` if this is a publisher.
|
||||||
|
UpdateInterval *string `toml:"update_interval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
|
|
@ -81,6 +85,10 @@ type config struct {
|
||||||
// ServiceDocument incidates if we should create a service.json document.
|
// ServiceDocument incidates if we should create a service.json document.
|
||||||
ServiceDocument bool `toml:"create_service_document"`
|
ServiceDocument bool `toml:"create_service_document"`
|
||||||
|
|
||||||
|
// UpdateInterval is used for publishers a the mandatory field
|
||||||
|
// 'update_interval'.
|
||||||
|
UpdateInterval *string
|
||||||
|
|
||||||
keyMu sync.Mutex
|
keyMu sync.Mutex
|
||||||
key *crypto.Key
|
key *crypto.Key
|
||||||
keyErr error
|
keyErr error
|
||||||
|
|
@ -96,6 +104,17 @@ 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) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// updateInterval returns the update interval of a publisher.
|
||||||
|
func (p *provider) updateInterval(c *config) string {
|
||||||
|
if p.UpdateInterval != nil {
|
||||||
|
return *p.UpdateInterval
|
||||||
|
}
|
||||||
|
if c.UpdateInterval != nil {
|
||||||
|
return *c.UpdateInterval
|
||||||
|
}
|
||||||
|
return defaultUpdateInterval
|
||||||
|
}
|
||||||
|
|
||||||
// serviceDocument tells if we should generate a service document for a
|
// serviceDocument tells if we should generate a service document for a
|
||||||
// given provider.
|
// given provider.
|
||||||
func (p *provider) serviceDocument(c *config) bool {
|
func (p *provider) serviceDocument(c *config) bool {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -128,8 +129,8 @@ func (p *processor) full() error {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
// Assemble aggregator data structure.
|
// Assemble aggregator data structure.
|
||||||
|
var providers []*csaf.AggregatorCSAFProvider
|
||||||
csafProviders := make([]*csaf.AggregatorCSAFProvider, 0, len(jobs))
|
var publishers []*csaf.AggregatorCSAFPublisher
|
||||||
|
|
||||||
for i := range jobs {
|
for i := range jobs {
|
||||||
j := &jobs[i]
|
j := &jobs[i]
|
||||||
|
|
@ -142,10 +143,21 @@ func (p *processor) full() error {
|
||||||
"error: '%s' does not produce any result.\n", j.provider.Name)
|
"error: '%s' does not produce any result.\n", j.provider.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
csafProviders = append(csafProviders, j.aggregatorProvider)
|
|
||||||
|
// "https://" signals a publisher.
|
||||||
|
if strings.HasPrefix(j.provider.Domain, "https://") {
|
||||||
|
pub := &csaf.AggregatorCSAFPublisher{
|
||||||
|
Metadata: j.aggregatorProvider.Metadata,
|
||||||
|
Mirrors: j.aggregatorProvider.Mirrors,
|
||||||
|
UpdateInterval: j.provider.updateInterval(p.cfg),
|
||||||
|
}
|
||||||
|
publishers = append(publishers, pub)
|
||||||
|
} else {
|
||||||
|
providers = append(providers, j.aggregatorProvider)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(csafProviders) == 0 {
|
if len(providers)+len(publishers) == 0 {
|
||||||
return errors.New("all jobs failed, stopping")
|
return errors.New("all jobs failed, stopping")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,7 +171,8 @@ func (p *processor) full() error {
|
||||||
Aggregator: &p.cfg.Aggregator,
|
Aggregator: &p.cfg.Aggregator,
|
||||||
Version: &version,
|
Version: &version,
|
||||||
CanonicalURL: &canonicalURL,
|
CanonicalURL: &canonicalURL,
|
||||||
CSAFProviders: csafProviders,
|
CSAFProviders: providers,
|
||||||
|
CSAFPublishers: publishers,
|
||||||
LastUpdated: &lastUpdated,
|
LastUpdated: &lastUpdated,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -218,12 +218,20 @@ type AggregatorCSAFProvider struct {
|
||||||
Mirrors []ProviderURL `json:"mirrors,omitempty"` // required
|
Mirrors []ProviderURL `json:"mirrors,omitempty"` // required
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AggregatorCSAFPublisher reflects one publisher in an aggregator.
|
||||||
|
type AggregatorCSAFPublisher struct {
|
||||||
|
Metadata *AggregatorCSAFProviderMetadata `json:"metadata,omitempty"` // required
|
||||||
|
Mirrors []ProviderURL `json:"mirrors,omitempty"` // required
|
||||||
|
UpdateInterval string `json:"update_interval,omitempty"` // required
|
||||||
|
}
|
||||||
|
|
||||||
// Aggregator is the CSAF Aggregator.
|
// Aggregator is the CSAF Aggregator.
|
||||||
type Aggregator struct {
|
type Aggregator struct {
|
||||||
Aggregator *AggregatorInfo `json:"aggregator,omitempty"` // required
|
Aggregator *AggregatorInfo `json:"aggregator,omitempty"` // required
|
||||||
Version *AggregatorVersion `json:"aggregator_version,omitempty"` // required
|
Version *AggregatorVersion `json:"aggregator_version,omitempty"` // required
|
||||||
CanonicalURL *AggregatorURL `json:"canonical_url,omitempty"` // required
|
CanonicalURL *AggregatorURL `json:"canonical_url,omitempty"` // required
|
||||||
CSAFProviders []*AggregatorCSAFProvider `json:"csaf_providers,omitempty"` // required
|
CSAFProviders []*AggregatorCSAFProvider `json:"csaf_providers,omitempty"` // required
|
||||||
|
CSAFPublishers []*AggregatorCSAFPublisher `json:"csaf_publishers,omitempty"`
|
||||||
LastUpdated *TimeStamp `json:"last_updated,omitempty"` // required
|
LastUpdated *TimeStamp `json:"last_updated,omitempty"` // required
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue