mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 05:40:11 +01:00
Add aggregator; improve itest workflow
* Factor JSON evaluation and construction base URLs out of of checker. * Move json path matching to util. * Add csaf_aggregator (as additional command) * Improve itest workflow to checkout the branch where it is running on. resolve #105 resolve #72 Co-authored-by: tschmidtb51 <65305130+tschmidtb51@users.noreply.github.com> Co-authored-by: Bernhard Reiter <bernhard@intevation.de> Co-authored-by: Fadi Abbud <fadi.abbud@intevation.de>
This commit is contained in:
parent
9da0589236
commit
8a1ebe0b7a
30 changed files with 2789 additions and 88 deletions
26
util/json.go
26
util/json.go
|
|
@ -12,6 +12,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/PaesslerAG/gval"
|
||||
|
|
@ -76,6 +77,18 @@ func ReMarshalMatcher(dst interface{}) func(interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
// BoolMatcher stores the matched result in a bool.
|
||||
func BoolMatcher(dst *bool) func(interface{}) error {
|
||||
return func(x interface{}) error {
|
||||
b, ok := x.(bool)
|
||||
if !ok {
|
||||
return errors.New("not a bool")
|
||||
}
|
||||
*dst = b
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// StringMatcher stores the matched result in a string.
|
||||
func StringMatcher(dst *string) func(interface{}) error {
|
||||
return func(x interface{}) error {
|
||||
|
|
@ -111,14 +124,17 @@ func (pe *PathEval) Extract(
|
|||
optional bool,
|
||||
doc interface{},
|
||||
) error {
|
||||
x, err := pe.Eval(expr, doc)
|
||||
if err != nil {
|
||||
if optional {
|
||||
optErr := func(err error) error {
|
||||
if err == nil || optional {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
return fmt.Errorf("extract failed '%s': %v", expr, err)
|
||||
}
|
||||
return action(x)
|
||||
x, err := pe.Eval(expr, doc)
|
||||
if err != nil {
|
||||
return optErr(err)
|
||||
}
|
||||
return optErr(action(x))
|
||||
}
|
||||
|
||||
// Match matches a list of PathEvalMatcher pairs against a document.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue