github.com/quay/claircore@v1.5.28/libvuln/driver/updater.go (about) 1 package driver 2 3 import ( 4 "context" 5 "errors" 6 "io" 7 "net/http" 8 9 "github.com/quay/claircore" 10 ) 11 12 // Updater is an aggregate interface combining the method set of a Fetcher and a Parser 13 // and forces a Name() to be provided 14 type Updater interface { 15 Name() string 16 Fetcher 17 Parser 18 } 19 20 // Parser is an interface which is embedded into the Updater interface. 21 // 22 // Parse should be called with an io.ReadCloser struct where the contents of a security 23 // advisory database can be read and parsed into an array of *claircore.Vulnerability 24 type Parser interface { 25 // Parse should take an io.ReadCloser, read the contents, parse the contents 26 // into a list of claircore.Vulnerability structs and then return 27 // the list. Parse should assume contents are uncompressed and ready for parsing. 28 Parse(ctx context.Context, contents io.ReadCloser) ([]*claircore.Vulnerability, error) 29 } 30 31 // Fetcher is an interface which is embedded into the Updater interface. 32 // 33 // When called the interface should determine if new security advisory data is available. 34 // Fingerprint may be passed into in order for the Fetcher to determine if the contents has changed 35 // 36 // If there is new content Fetcher should return a io.ReadCloser where the new content can be read. 37 // Optionally a fingerprint can be returned which uniquely identifies the new content. 38 // 39 // If the conent has not change an Unchanged error should be returned. 40 type Fetcher interface { 41 Fetch(context.Context, Fingerprint) (io.ReadCloser, Fingerprint, error) 42 } 43 44 // Unchanged is returned by Fetchers when the database has not changed. 45 var Unchanged = errors.New("database contents unchanged") 46 47 // Fingerprint is some identifying information about a vulnerability database. 48 type Fingerprint string 49 50 // ConfigUnmarshaler can be thought of as an Unmarshal function with the byte 51 // slice provided, or a Decode function. 52 // 53 // The function should populate a passed struct with any configuration 54 // information. 55 type ConfigUnmarshaler func(interface{}) error 56 57 // Configurable is an interface that Updaters can implement to opt-in to having 58 // their configuration provided dynamically. 59 type Configurable interface { 60 Configure(context.Context, ConfigUnmarshaler, *http.Client) error 61 } 62 63 // DeltaUpdater is an interface that Updaters can implement to force the manager to call 64 // DeltaParse() in lieu of Parse() with the understanding that the resulting vulnerabilities 65 // represent a delta and not the entire vulnerability database. DeltaParse can also return 66 // a slice of strings that represent the names of deleted vulnerabilities. 67 type DeltaUpdater interface { 68 DeltaParse(ctx context.Context, contents io.ReadCloser) ([]*claircore.Vulnerability, []string, error) 69 }