forked from quay/claircore
/
parser.go
47 lines (43 loc) · 1.3 KB
/
parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package debian
import (
"context"
"encoding/xml"
"fmt"
"io"
"github.com/quay/goval-parser/oval"
"github.com/quay/zlog"
"go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/label"
"github.com/Panzer1119/claircore"
"github.com/Panzer1119/claircore/pkg/ovalutil"
)
func (u *Updater) Parse(ctx context.Context, r io.ReadCloser) ([]*claircore.Vulnerability, error) {
ctx = baggage.ContextWithValues(ctx,
label.String("component", "debian/Updater.Parse"))
zlog.Info(ctx).Msg("starting parse")
defer r.Close()
root := oval.Root{}
if err := xml.NewDecoder(r).Decode(&root); err != nil {
return nil, fmt.Errorf("debian: unable to decode OVAL document: %w", err)
}
zlog.Debug(ctx).Msg("xml decoded")
protoVulns := func(def oval.Definition) ([]*claircore.Vulnerability, error) {
vs := []*claircore.Vulnerability{}
v := &claircore.Vulnerability{
Updater: u.Name(),
Name: def.Title,
Description: def.Description,
Issued: def.Advisory.Issued.Date,
Links: ovalutil.Links(def),
NormalizedSeverity: claircore.Unknown,
Dist: releaseToDist(u.release),
}
vs = append(vs, v)
return vs, nil
}
vulns, err := ovalutil.DpkgDefsToVulns(ctx, &root, protoVulns)
if err != nil {
return nil, err
}
return vulns, nil
}