Skip to content

Commit

Permalink
Add option to specify download folder
Browse files Browse the repository at this point in the history
* Add an option to downloader to store advisories into a given subfolder.

---------

Co-authored-by: JanHoefelmeyer <[email protected]>
Co-authored-by: Bernhard Reiter <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2023
1 parent d42db07 commit 8c95795
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/csaf_downloader/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
9 changes: 8 additions & 1 deletion cmd/csaf_downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion docs/csaf_downloader.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

0 comments on commit 8c95795

Please sign in to comment.