github.com/quay/claircore@v1.5.28/suse/suse.go (about) 1 package suse 2 3 import ( 4 "fmt" 5 "net/url" 6 7 "github.com/quay/claircore/libvuln/driver" 8 "github.com/quay/claircore/pkg/ovalutil" 9 ) 10 11 var upstreamBase *url.URL 12 13 func init() { 14 //doc:url updater 15 const base = `https://support.novell.com/security/oval/` 16 var err error 17 upstreamBase, err = url.Parse(base) 18 if err != nil { 19 panic("static url somehow didn't parse") 20 } 21 } 22 23 // Updater implements driver.Updater for SUSE. 24 type Updater struct { 25 release Release 26 ovalutil.Fetcher // promoted Fetch method 27 } 28 29 var ( 30 _ driver.Updater = (*Updater)(nil) 31 _ driver.Fetcher = (*Updater)(nil) 32 _ driver.Configurable = (*Updater)(nil) 33 ) 34 35 // NewUpdater configures an updater to fetch the specified Release. 36 func NewUpdater(r Release, opts ...Option) (*Updater, error) { 37 u := &Updater{ 38 release: r, 39 } 40 for _, o := range opts { 41 if err := o(u); err != nil { 42 return nil, err 43 } 44 } 45 if u.Fetcher.URL == nil { 46 var err error 47 u.Fetcher.URL, err = upstreamBase.Parse(string(u.release) + ".xml") 48 if err != nil { 49 return nil, err 50 } 51 } 52 return u, nil 53 } 54 55 // Option configures an Updater. 56 type Option func(*Updater) error 57 58 // WithURL overrides the default URL to fetch an OVAL database. 59 func WithURL(uri, compression string) Option { 60 c, cerr := ovalutil.ParseCompressor(compression) 61 u, uerr := url.Parse(uri) 62 return func(up *Updater) error { 63 // Return any errors from the outer function. 64 switch { 65 case cerr != nil: 66 return cerr 67 case uerr != nil: 68 return uerr 69 } 70 up.Fetcher.Compression = c 71 up.Fetcher.URL = u 72 return nil 73 } 74 } 75 76 // Name satisfies driver.Updater. 77 func (u *Updater) Name() string { 78 return fmt.Sprintf(`suse-updater-%s`, u.release) 79 }