From 8c95795b962164dce0fbb9db435ffb96dd27d0ef Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Wed, 16 Aug 2023 08:45:34 +0200 Subject: [PATCH 1/2] Add option to specify download folder * Add an option to downloader to store advisories into a given subfolder. --------- Co-authored-by: JanHoefelmeyer Co-authored-by: Bernhard Reiter --- cmd/csaf_downloader/config.go | 1 + cmd/csaf_downloader/downloader.go | 9 ++++++++- docs/csaf_downloader.md | 8 +++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/csaf_downloader/config.go b/cmd/csaf_downloader/config.go index fdf30996..6c16b375 100644 --- a/cmd/csaf_downloader/config.go +++ b/cmd/csaf_downloader/config.go @@ -29,6 +29,7 @@ type config struct { Rate *float64 `long:"rate" short:"r" description:"The average upper limit of https operations per second (defaults to unlimited)" toml:"rate"` Worker int `long:"worker" short:"w" description:"NUMber of concurrent downloads" value-name:"NUM" toml:"worker"` Range *models.TimeRange `long:"timerange" short:"t" description:"RANGE of time from which advisories to download" value-name:"RANGE" toml:"timerange"` + Folder string `long:"folder" short:"f" description:"Download into a given subFOLDER" value-name:"FOLDER" toml:"folder"` ExtraHeader http.Header `long:"header" short:"H" description:"One or more extra HTTP header fields" toml:"header"` diff --git a/cmd/csaf_downloader/downloader.go b/cmd/csaf_downloader/downloader.go index cabe2fe3..8c5312bc 100644 --- a/cmd/csaf_downloader/downloader.go +++ b/cmd/csaf_downloader/downloader.go @@ -474,8 +474,15 @@ nextAdvisory: initialReleaseDate = initialReleaseDate.UTC() // Write advisory to file + newDir := path.Join(d.directory, lower) + + // Do we have a configured destination folder? + if d.cfg.Folder != "" { + newDir = path.Join(newDir, d.cfg.Folder) + } else { + newDir = path.Join(newDir, strconv.Itoa(initialReleaseDate.Year())) + } - newDir := path.Join(d.directory, lower, strconv.Itoa(initialReleaseDate.Year())) if newDir != lastDir { if err := d.mkdirAll(newDir, 0755); err != nil { errorCh <- err diff --git a/docs/csaf_downloader.md b/docs/csaf_downloader.md index 8874df13..24841ae9 100644 --- a/docs/csaf_downloader.md +++ b/docs/csaf_downloader.md @@ -15,6 +15,7 @@ Application Options: -r, --rate= The average upper limit of https operations per second (defaults to unlimited) -w, --worker=NUM NUMber of concurrent downloads (default: 2) -t, --timerange=RANGE RANGE of time from which advisories to download + -f, --folder=FOLDER Download all into a given subFOLDER -H, --header= One or more extra HTTP header fields --validator=URL URL to validate documents remotely --validatorcache=FILE FILE to cache remote validations @@ -51,11 +52,12 @@ ignoresigcheck = false verbose = false # rate # set to unlimited worker = 2 +# timerange # not set by default +# folder # not set by default # header # not set by default # validator # not set by default # validatorcache # not set by default validatorpreset = ["mandatory"] -# timerange # not set by default ``` The `timerange` parameter enables downloading advisories which last changes falls @@ -86,3 +88,7 @@ into a given intervall. There are three possible notations: spans an interval from 1st January 2019 to the 1st January of 2024. All interval boundaries are inclusive. + +If the `folder` option is given all the advisories are stored in a subfolder +of this name. Otherwise the advisories are each stored in a folder named +by the year they are from. From 083ccc10f1003e3995daf5fcb7ad8f992bd28543 Mon Sep 17 00:00:00 2001 From: JanHoefelmeyer Date: Wed, 16 Aug 2023 09:03:34 +0200 Subject: [PATCH 2/2] fmt --- cmd/csaf_downloader/config.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/csaf_downloader/config.go b/cmd/csaf_downloader/config.go index be9b56fa..8a9bf68a 100644 --- a/cmd/csaf_downloader/config.go +++ b/cmd/csaf_downloader/config.go @@ -33,8 +33,6 @@ type config struct { Folder string `long:"folder" short:"f" description:"Download into a given subFOLDER" value-name:"FOLDER" toml:"folder"` IgnorePattern []string `long:"ignorepattern" short:"i" description:"Dont download files if there URLs match any of the given PATTERNs" value-name:"PATTERN" toml:"ignorepattern"` - - ExtraHeader http.Header `long:"header" short:"H" description:"One or more extra HTTP header fields" toml:"header"` RemoteValidator string `long:"validator" description:"URL to validate documents remotely" value-name:"URL" toml:"validator"`