-
Notifications
You must be signed in to change notification settings - Fork 5
/
cache.go
123 lines (100 loc) · 3.54 KB
/
cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package vmaas
import (
"io"
"net/http"
"time"
"github.com/redhatinsights/vmaas-lib/vmaas/utils"
)
type Cache struct {
Packagename2ID map[string]NameID
ID2Packagename map[NameID]string
// name -> []pkg ordered by e-v-r ordering
Updates map[NameID][]PkgID
// name -> evr -> idx into updates[name]
UpdatesIndex map[NameID]map[EvrID][]int
Evr2ID map[utils.Evr]EvrID
ID2Evr map[EvrID]utils.Evr
ID2Arch map[ArchID]string
Arch2ID map[string]ArchID
ArchCompat map[ArchID]map[ArchID]bool
PackageDetails map[PkgID]PackageDetail
Nevra2PkgID map[Nevra]PkgID
NameID2SrcNameIDs map[NameID]map[NameID]struct{}
RepoIDs []RepoID
RepoDetails map[RepoID]RepoDetail
RepoLabel2IDs map[string][]RepoID
RepoPath2IDs map[string][]RepoID
Label2ContentSetID map[string]ContentSetID
ProductID2RepoIDs map[int][]RepoID
PkgID2RepoIDs map[PkgID][]RepoID
ErratumID2Name map[ErratumID]string
PkgID2ErrataIDs map[PkgID][]ErratumID
ErratumID2RepoIDs map[ErratumID]map[RepoID]bool
CveDetail map[string]CveDetail
CveNames map[int]string
PkgErratum2Module map[PkgErratum][]int
Module2IDs map[ModuleStream][]int
ModuleRequires map[int][]int
DBChange DBChange
ErratumDetails map[string]ErratumDetail
SrcPkgID2PkgID map[PkgID][]PkgID
String map[int]string
// OVAL
PackagenameID2definitionIDs map[NameID][]DefinitionID
RepoID2CpeIDs map[RepoID][]CpeID
ContentSetID2CpeIDs map[ContentSetID][]CpeID
OvaldefinitionDetail map[DefinitionID]DefinitionDetail
OvaldefinitionID2Cves map[DefinitionID][]string
CpeID2OvalDefinitionIDs map[CpeID][]DefinitionID
OvalCriteriaID2DepModuleTestIDs map[CriteriaID][]ModuleTestID
OvalCriteriaID2DepTestIDs map[CriteriaID][]TestID
OvalCriteriaID2DepCriteriaIDs map[CriteriaID][]CriteriaID
OvalCriteriaID2Type map[CriteriaID]int
OvalStateID2Arches map[OvalStateID][]ArchID
OvalModuleTestDetail map[ModuleTestID]OvalModuleTestDetail
OvalTestDetail map[TestID]OvalTestDetail
OvalTestID2States map[TestID][]OvalState
OvalDefinitionID2ErrataIDs map[DefinitionID][]ErratumID
CpeID2Label map[CpeID]CpeLabel
// CSAF
CSAFProductStatus map[int]string
CSAFCVEs map[CpeIDNameID]map[CSAFProduct]CSAFCVEs
CSAFCVEProduct2Errata map[CSAFCVEProduct]string
CSAFProduct2ID map[CSAFProduct]CSAFProductID
}
func ShouldReload(c *Cache, latestDumpEndpoint string) bool {
if c == nil {
return true
}
resp, err := http.Get(latestDumpEndpoint) //nolint:gosec // url is user's input
if err != nil {
utils.LogWarn("err", err.Error(), "Request to latestdump failed")
return false
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
utils.LogWarn("err", err.Error(), "Couldn't read response body")
return false
}
if len(body) == 0 {
utils.LogWarn("No latestdump info, cache is not exported")
return false
}
latest, err := time.Parse(time.RFC3339, string(body))
if err != nil {
utils.LogWarn("err", err.Error(), "Couldn't parse latest timestamp")
return false
}
exported, err := time.Parse(time.RFC3339, c.DBChange.Exported)
if err != nil {
utils.LogWarn("err", err.Error(), "Couldn't parse exported timestamp in cache")
return true
}
if latest.After(exported) {
utils.LogDebug("latest", latest, "exported", exported, "Cache reload needed")
return true
}
utils.LogDebug("latest", latest, "exported", exported, "Cache reload not needed")
return false
}