Skip to content

Commit

Permalink
fix(fedora): support archive version (#240)
Browse files Browse the repository at this point in the history
* fix(fedora): support archive version

* fix(cmd): add log-to-file flag
  • Loading branch information
MaineK00n authored Nov 4, 2022
1 parent 0fc8e77 commit 7ad1e88
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func init() {

RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.oval.yaml)")

RootCmd.PersistentFlags().Bool("log-to-file", false, "output log to file")
_ = viper.BindPFlag("log-to-file", RootCmd.PersistentFlags().Lookup("log-to-file"))

RootCmd.PersistentFlags().String("log-dir", log.GetDefaultLogDir(), "/path/to/log")
_ = viper.BindPFlag("log-dir", RootCmd.PersistentFlags().Lookup("log-dir"))

Expand Down
24 changes: 18 additions & 6 deletions fetcher/fedora/fedora.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/url"
"regexp"
"strconv"
"strings"

"github.com/inconshreveable/log15"
Expand All @@ -21,10 +22,12 @@ const (
archX8664 = "x86_64"
archAarch64 = "aarch64"

fedoraUpdateURL = "https://dl.fedoraproject.org/pub/fedora/linux/updates/%s/Everything/%s/repodata/repomd.xml"
fedoraModuleURL = "https://dl.fedoraproject.org/pub/fedora/linux/updates/%s/Modular/%s/repodata/repomd.xml"
bugZillaURL = "https://bugzilla.redhat.com/show_bug.cgi?ctype=xml&id=%s"
kojiPkgURL = "https://kojipkgs.fedoraproject.org/packages/%s/%s/%s/files/module/modulemd.%s.txt"
pubUpdateURL = "https://dl.fedoraproject.org/pub/fedora/linux/updates/%s/Everything/%s/repodata/repomd.xml"
pubModuleURL = "https://dl.fedoraproject.org/pub/fedora/linux/updates/%s/Modular/%s/repodata/repomd.xml"
archiveUpdateURL = "https://archives.fedoraproject.org/pub/archive/fedora/linux/updates/%s/Everything/%s/repodata/repomd.xml"
archiveModuleURL = "https://archives.fedoraproject.org/pub/archive/fedora/linux/updates/%s/Modular/%s/repodata/repomd.xml"
bugZillaURL = "https://bugzilla.redhat.com/show_bug.cgi?ctype=xml&id=%s"
kojiPkgURL = "https://kojipkgs.fedoraproject.org/packages/%s/%s/%s/files/module/modulemd.%s.txt"
)

// FetchUpdateInfosFedora fetch OVAL from Fedora
Expand Down Expand Up @@ -74,15 +77,24 @@ func FetchUpdateInfosFedora(versions []string) (map[string]*models.Updates, erro

func newFedoraFetchRequests(target []string, arch string) (reqs []util.FetchRequest, moduleReqs []util.FetchRequest) {
for _, v := range target {
var updateURL, moduleURL string
if n, _ := strconv.Atoi(v); n < 34 {
updateURL = archiveUpdateURL
moduleURL = archiveModuleURL
} else {
updateURL = pubUpdateURL
moduleURL = pubModuleURL
}

reqs = append(reqs, util.FetchRequest{
Target: v,
URL: fmt.Sprintf(fedoraUpdateURL, v, arch),
URL: fmt.Sprintf(updateURL, v, arch),
MIMEType: util.MIMETypeXML,
Concurrently: true,
})
moduleReqs = append(moduleReqs, util.FetchRequest{
Target: v,
URL: fmt.Sprintf(fedoraModuleURL, v, arch),
URL: fmt.Sprintf(moduleURL, v, arch),
MIMEType: util.MIMETypeXML,
Concurrently: true,
})
Expand Down

0 comments on commit 7ad1e88

Please sign in to comment.