forked from quay/claircore
/
resolvevcn.go
46 lines (38 loc) · 1.1 KB
/
resolvevcn.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
package debian
import (
"regexp"
)
func init() {
busterRegex := regexp.MustCompile("buster")
jessieRegex := regexp.MustCompile("jessie")
stretchRegex := regexp.MustCompile("stretch")
wheezyRegex := regexp.MustCompile("wheezy")
resolvers = []vcnRegexp{
vcnRegexp{Buster, busterRegex},
vcnRegexp{Jessie, jessieRegex},
vcnRegexp{Stretch, stretchRegex},
vcnRegexp{Wheezy, wheezyRegex},
}
}
// global array holding compiled vcnRegexp
var resolvers []vcnRegexp
// vcnREgexp determines if a provided string matches a debian version code name as defined by the os-release file
type vcnRegexp struct {
release Release
regex *regexp.Regexp
}
func (r *vcnRegexp) match(s string) bool {
return r.regex.MatchString(s)
}
// Resolve iterates over each os-release entry and tries to find a release string. if
// found we return the found release in string form. if not found empty string is returned
func ResolveVersionCodeName(osrelease map[string]string) string {
for _, s := range osrelease {
for _, r := range resolvers {
if ok := r.match(s); ok {
return string(r.release)
}
}
}
return ""
}