forked from content-services/content-sources-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_constraints.go
109 lines (98 loc) · 2.26 KB
/
value_constraints.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
package config
const (
StatusValid = "Valid" // Repository introspected successfully
StatusUnavailable = "Unavailable" // Repository introspected at least once, but now errors
StatusInvalid = "Invalid" // Repository has never introspected due to error
StatusPending = "Pending" // Repository not introspected yet.
)
const (
ContentTypeRpm = "rpm"
)
const (
OriginExternal = "external"
OriginRedHat = "red_hat"
)
const ANY_VERSION = "any"
const El7 = "7"
const El8 = "8"
const El9 = "9"
const FailedIntrospectionsLimit = 20
type DistributionVersion struct {
Name string `json:"name"` // Human-readable form of the version
Label string `json:"label"` // Static label of the version
}
type DistributionArch struct {
Name string `json:"name"` // Human-readable form of the architecture
Label string `json:"label"` // Static label of the architecture
}
var DistributionVersions = [...]DistributionVersion{
{
Name: "Any",
Label: ANY_VERSION,
},
{
Name: "el7",
Label: El7,
}, {
Name: "el8",
Label: El8,
}, {
Name: "el9",
Label: El9,
},
}
const ANY_ARCH = "any"
const X8664 = "x86_64"
const S390x = "s390x"
const PPC64LE = "ppc64le"
const AARCH64 = "aarch64"
var DistributionArches = [...]DistributionArch{
{
Name: "Any",
Label: ANY_ARCH,
},
{
Name: "aarch64",
Label: AARCH64,
},
{
Name: "ppc64le",
Label: PPC64LE,
},
{
Name: "s390x",
Label: S390x,
},
{
Name: "x86_64",
Label: X8664,
},
}
// ValidDistributionVersionLabels Given a list of labels, return true
// if every item of the list is a valid distribution version. If at least one
// is not valid, returns false and the first invalid version
func ValidDistributionVersionLabels(labels []string) (bool, string) {
for j := 0; j < len(labels); j++ {
found := false
for i := 0; i < len(DistributionVersions); i++ {
if DistributionVersions[i].Label == labels[j] {
found = true
break
}
}
if !found {
return false, labels[j]
}
}
return true, ""
}
// ValidArchLabel Given a label, verifies that the label is a valid distribution
// architecture label
func ValidArchLabel(label string) bool {
for i := 0; i < len(DistributionArches); i++ {
if DistributionArches[i].Label == label {
return true
}
}
return false
}