diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-24 01:01:24 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-24 01:01:24 -0500 |
commit | 2615a8f217796caa3a0572c25574f63055247edf (patch) | |
tree | 55632a8c51b5c6e621742f14d4eda39b0994c1a2 | |
parent | 5fa2cbc1cd4c2ccbdf8897fcf9b5263ab050fbf6 (diff) | |
download | cvez-2615a8f217796caa3a0572c25574f63055247edf.tar.bz2 cvez-2615a8f217796caa3a0572c25574f63055247edf.zip |
nvdmirror/sync.go: compact source, improve documentation
-rw-r--r-- | nvdmirror/sync.go | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/nvdmirror/sync.go b/nvdmirror/sync.go index 8cdd4c7..dcbf6a9 100644 --- a/nvdmirror/sync.go +++ b/nvdmirror/sync.go @@ -1,7 +1,10 @@ package nvdmirror -// Sync to destination directory based on given sync configuration and -// cache. Returns an array of file names which have been updated in the +// +// Sync NVD data files to destination directory based on given sync +// configuration and cache. +// +// Returns an array of file names which have been updated in the // destination directory. // // This function does the following: @@ -16,24 +19,25 @@ package nvdmirror // 3. Fetch the contents of the changed CVE feeds, CPE match files, and // the CPE dictionary. // -// All HTTP requests are made with the following request headers: +// All HTTP requests are sent with the following headers: +// +// * if-modified-since: The last-modified header from the previous +// successful response, if it was set. // -// * if-modified-since (if the URL was queried previously and the -// previous successful response had a "last-modified" header). -// * if-none-match (if the URL was queried previously and the -// previous successful response had an "etag" header). -// * user-agent +// * if-none-match: The etag header from the last successful response, +// if it was set. +// +// * user-agent: User agent from config, or the default user agent if +// the config value is unspecified. // func Sync(config SyncConfig, cache Cache, dstDir string) []string { // build sync context ctx := newSyncContext(config, cache, dstDir) - // fetch updated meta files - checks := ctx.fetchMetas() - - // get syncable URLs - urls := append(ctx.checkMetas(checks), config.GetCpeDictUrl()) - - // sync urls and return changed files - return ctx.syncUrls(urls) + // fetch meta files, check for updates, append cpe dictionary URL, + // fetch updated files, and then return a list of changed files + return ctx.syncUrls(append( + ctx.checkMetas(ctx.fetchMetas()), + config.GetCpeDictUrl(), + )) } |