github.com/quay/claircore@v1.5.28/test/ovaldebug/main.go (about) 1 // Ovaldebug is a helper for debugging the ovalutil package. 2 package main 3 4 import ( 5 "context" 6 "flag" 7 "fmt" 8 "net/http" 9 "net/url" 10 "os" 11 "path" 12 "strings" 13 14 "github.com/quay/goval-parser/oval" 15 "github.com/rs/zerolog" 16 "github.com/rs/zerolog/log" 17 18 "github.com/quay/claircore" 19 "github.com/quay/claircore/libvuln/driver" 20 "github.com/quay/claircore/pkg/ovalutil" 21 "github.com/quay/claircore/rhel" 22 ) 23 24 func main() { 25 flavor := flag.String("flavor", "rpm", "OVAL flavor") 26 flag.Parse() 27 if flag.NArg() == 0 { 28 fmt.Fprintln(os.Stderr, "missing required argument(s): database URLs") 29 flag.Usage() 30 os.Exit(1) 31 } 32 ctx := context.Background() 33 log.Logger = zerolog.New(zerolog.NewConsoleWriter(func(w *zerolog.ConsoleWriter) { w.Out = os.Stderr })). 34 Level(zerolog.DebugLevel) 35 36 for _, u := range flag.Args() { 37 u, err := url.Parse(u) 38 if err != nil { 39 log.Fatal().Err(err).Send() 40 } 41 ext := strings.TrimPrefix(path.Ext(path.Base(u.Path)), ".") 42 if ext == "xml" { 43 ext = "" 44 } 45 46 cmp, err := ovalutil.ParseCompressor(ext) 47 if err != nil { 48 log.Fatal().Err(err).Send() 49 } 50 f := ovalutil.Fetcher{ 51 Compression: cmp, 52 URL: u, 53 Client: http.DefaultClient, 54 } 55 56 rc, _, err := f.Fetch(ctx, "") 57 if err != nil { 58 log.Fatal().Err(err).Send() 59 } 60 defer rc.Close() 61 62 var vs []*claircore.Vulnerability 63 switch *flavor { 64 case "rpm": 65 var u driver.Updater 66 u, err = rhel.NewUpdater("rhel-test", 8, "file:///dev/null", false) 67 if err != nil { 68 log.Fatal().Err(err).Send() 69 } 70 vs, err = u.Parse(ctx, rc) 71 case "debian": 72 /* 73 u := debian.NewUpdater(debian.Buster) 74 vs, err = u.Parse(ctx, rc) 75 */ 76 case "ubuntu": 77 log.Fatal().Str("flavor", *flavor).Msg("ubuntu unsupported in this tool") 78 case "dpkg": 79 log.Fatal().Str("flavor", *flavor).Msg("unimplemented oval flavor") 80 default: 81 log.Fatal().Str("flavor", *flavor).Msg("unknown oval flavor") 82 } 83 84 if err != nil { 85 log.Info().Err(err).Msg("error during extraction") 86 } 87 _ = vs 88 } 89 } 90 91 var _ ovalutil.ProtoVulnsFunc = pf 92 93 func pf(def oval.Definition) ([]*claircore.Vulnerability, error) { 94 return nil, nil 95 }