Skip to content

Commit

Permalink
fix(fetcher/redhat): fetch oval v1
Browse files Browse the repository at this point in the history
  • Loading branch information
MaineK00n committed Jul 14, 2023
1 parent 4facec5 commit f0a4743
Showing 1 changed file with 49 additions and 13 deletions.
62 changes: 49 additions & 13 deletions fetcher/redhat/redhat.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package redhat

import (
"archive/tar"
"compress/gzip"
"fmt"
"io"
"net/http"
"strconv"

"github.com/inconshreveable/log15"
Expand All @@ -25,24 +29,56 @@ func FetchFiles(versions []string) (map[string][]util.FetchResult, error) {
continue
}

reqs := []util.FetchRequest{{
Target: v,
URL: fmt.Sprintf("https://www.redhat.com/security/data/oval/com.redhat.rhsa-RHEL%s.xml.bz2", v),
MIMEType: util.MIMETypeBzip2,
}}
resp, err := http.Get("https://access.redhat.com/security/data/archive/oval_v1_20230706.tar.gz")
if err != nil {
return nil, xerrors.Errorf("Failed to get oval v1. err: %w", err)
}
if resp.StatusCode != http.StatusOK {
return nil, xerrors.Errorf("Failed to get oval v1. err: bad status %d", resp.StatusCode)
}
defer resp.Body.Close()

gr, err := gzip.NewReader(resp.Body)
if err != nil {
return nil, xerrors.Errorf("Failed to create gzip reader. err: %w", err)
}
defer gr.Close()

tr := tar.NewReader(gr)
for {
hdr, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
return nil, xerrors.Errorf("Failed to next tar reader. err: %w", err)
}

if hdr.Name == fmt.Sprintf("com.redhat.rhsa-RHEL%s.xml", v) {
bs, err := io.ReadAll(tr)
if err != nil {
return nil, xerrors.Errorf("Failed to read all com.redhat.rhsa-RHEL%s.xml. err: %w", v, err)
}
results[v] = append(results[v], util.FetchResult{
Target: v,
URL: fmt.Sprintf("https://www.redhat.com/security/data/oval/com.redhat.rhsa-RHEL%s.xml.bz2", v),
Body: bs,
})
}

}

if n != 5 {
reqs = append(reqs, util.FetchRequest{
rs, err := util.FetchFeedFiles([]util.FetchRequest{{
Target: v,
URL: fmt.Sprintf("https://access.redhat.com/security/data/oval/v2/RHEL%s/rhel-%s.oval.xml.bz2", v, v),
MIMEType: util.MIMETypeBzip2,
})
}

rs, err := util.FetchFeedFiles(reqs)
if err != nil {
return nil, xerrors.Errorf("Failed to fetch. err: %w", err)
}})
if err != nil {
return nil, xerrors.Errorf("Failed to fetch. err: %w", err)
}
results[v] = append(results[v], rs...)
}
results[v] = append(results[v], rs...)
}
if len(results) == 0 {
return nil, xerrors.New("There are no versions to fetch")
Expand Down

0 comments on commit f0a4743

Please sign in to comment.