github.com/quay/claircore@v1.5.28/rhel/rhel.go (about) 1 // Package rhel implements the machinery for processing layers and security data 2 // from the Red Hat ecosystem. 3 // 4 // See the various exported types for details on the heuristics employed. 5 // 6 // In addition, containers themselves are recognized via the 7 // [github.com/quay/claircore/rhel/rhcc] package. 8 package rhel // import "github.com/quay/claircore/rhel" 9 10 import ( 11 "context" 12 "net/http" 13 "net/url" 14 15 "github.com/quay/zlog" 16 17 "github.com/quay/claircore" 18 "github.com/quay/claircore/libvuln/driver" 19 "github.com/quay/claircore/pkg/ovalutil" 20 ) 21 22 var ( 23 _ driver.Updater = (*Updater)(nil) 24 _ driver.Configurable = (*Updater)(nil) 25 ) 26 27 // Updater fetches and parses RHEL-flavored OVAL databases. 28 type Updater struct { 29 ovalutil.Fetcher // fetch method promoted via embed 30 dist *claircore.Distribution 31 name string 32 ignoreUnpatched bool 33 } 34 35 // UpdaterConfig is the configuration expected for any given updater. 36 // 37 // See also [ovalutil.FetcherConfig]. 38 type UpdaterConfig struct { 39 ovalutil.FetcherConfig 40 Release int64 `json:"release" yaml:"release"` 41 } 42 43 // NewUpdater returns an Updater. 44 func NewUpdater(name string, release int, uri string, ignoreUnpatched bool) (*Updater, error) { 45 u := &Updater{ 46 name: name, 47 dist: mkRelease(int64(release)), 48 ignoreUnpatched: ignoreUnpatched, 49 } 50 var err error 51 u.Fetcher.URL, err = url.Parse(uri) 52 if err != nil { 53 return nil, err 54 } 55 return u, nil 56 } 57 58 // Configure implements [driver.Configurable]. 59 func (u *Updater) Configure(ctx context.Context, cf driver.ConfigUnmarshaler, c *http.Client) error { 60 ctx = zlog.ContextWithValues(ctx, "component", "rhel/Updater.Configure") 61 var cfg UpdaterConfig 62 if err := cf(&cfg); err != nil { 63 return err 64 } 65 if cfg.Release != 0 { 66 u.dist = mkRelease(cfg.Release) 67 } 68 69 return u.Fetcher.Configure(ctx, cf, c) 70 } 71 72 // Name implements [driver.Updater]. 73 func (u *Updater) Name() string { return u.name }