1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Extend structured logging usage in aggregator (#622)

* Extend structured logging usage in aggregator

* Use structured logging in advisories processor

* Remove unnecessary inner function

* Format

* Feat: Add verbose flag to example aggregator toml (in comment)

---------

Co-authored-by: JanHoefelmeyer <jan.hoefelmeyer@intevation.de>
This commit is contained in:
Paul Schwabauer 2025-03-19 09:04:19 +01:00 committed by GitHub
parent cf4cf7c6c1
commit 5709b14650
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 36 additions and 30 deletions

View file

@ -264,8 +264,14 @@ func (c *config) privateOpenPGPKey() (*crypto.Key, error) {
return c.key, c.keyErr
}
func (c *config) httpClient(p *provider) util.Client {
// httpLog does structured logging in a [util.LoggingClient].
func httpLog(method, url string) {
slog.Debug("http",
"method", method,
"url", url)
}
func (c *config) httpClient(p *provider) util.Client {
hClient := http.Client{}
var tlsConfig tls.Config
@ -310,7 +316,10 @@ func (c *config) httpClient(p *provider) util.Client {
}
if c.Verbose {
client = &util.LoggingClient{Client: client}
client = &util.LoggingClient{
Client: client,
Log: httpLog,
}
}
if p.Rate == nil && c.Rate == nil {
@ -331,7 +340,6 @@ func (c *config) httpClient(p *provider) util.Client {
}
func (c *config) checkProviders() error {
if !c.AllowSingleProvider && len(c.Providers) < 2 {
return errors.New("need at least two providers")
}
@ -471,7 +479,6 @@ func (c *config) prepareCertificates() error {
// prepare prepares internal state of a loaded configuration.
func (c *config) prepare() error {
if len(c.Providers) == 0 {
return errors.New("no providers given in configuration")
}

View file

@ -462,8 +462,9 @@ func (w *worker) extractCategories(label string, advisory any) error {
expr := cat[len(exprPrefix):]
// Compile first to check that the expression is okay.
if _, err := w.expr.Compile(expr); err != nil {
fmt.Printf("Compiling category expression %q failed: %v\n",
expr, err)
slog.Error("Compiling category expression failed",
"expr", expr,
"err", err)
continue
}
// Ignore errors here as they result from not matching.
@ -588,12 +589,10 @@ func (w *worker) mirrorFiles(tlpLabel csaf.TLPLabel, files []csaf.AdvisoryFile)
if err := os.MkdirAll(yearDir, 0755); err != nil {
return err
}
//log.Printf("created %s\n", yearDir)
yearDirs[year] = yearDir
}
fname := filepath.Join(yearDir, filename)
//log.Printf("write: %s\n", fname)
data := content.Bytes()
if err := writeFileHashes(
fname, filename,