-
Notifications
You must be signed in to change notification settings - Fork 69
/
discovery_manifest.go
93 lines (76 loc) · 2.36 KB
/
discovery_manifest.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
package types
import (
"strings"
log "github.com/sirupsen/logrus"
)
// DiscoveryManifest contains the discovered information about the host.
type DiscoveryManifest struct {
Hostname string `json:"hostname"`
KernelArch string `json:"kernelArch"`
KernelVersion string `json:"kernelVersion"`
OS string `json:"os"`
Platform string `json:"platform"`
PlatformFamily string `json:"platformFamily"`
PlatformVersion string `json:"platformVersion"`
IsUnsupported bool `json:"isUnsupported"`
MatchedProcesses []MatchedProcess `json:"processes"`
DiscoveredProcesses []GenericProcess
}
// GenericProcess is an abstracted representation of a process.
type GenericProcess interface {
Name() (string, error)
Cmd() (string, error)
PID() int32
}
type MatchedProcess struct {
GenericProcess
MatchingPattern string
MatchingRecipe OpenInstallationRecipe
}
// AddMatchedProcess adds a discovered process to the underlying manifest.
func (d *DiscoveryManifest) AddMatchedProcess(p MatchedProcess) {
d.MatchedProcesses = append(d.MatchedProcesses, p)
}
func (d *DiscoveryManifest) ConstrainRecipes(allRecipes []OpenInstallationRecipe) []OpenInstallationRecipe {
var recipes []OpenInstallationRecipe
for _, recipe := range allRecipes {
if len(recipe.InstallTargets) == 0 {
log.Warnf("recipe has no InstallTargets: %s", recipe.Name)
}
for _, target := range recipe.InstallTargets {
if target.KernelArch != "" {
if !strings.EqualFold(target.KernelArch, d.KernelArch) {
continue
}
}
if target.KernelVersion != "" {
if !strings.EqualFold(target.KernelVersion, d.KernelVersion) {
continue
}
}
if target.Os != "" {
if !strings.EqualFold(string(target.Os), d.OS) {
continue
}
}
if target.Platform != "" {
if !strings.EqualFold(string(target.Platform), d.Platform) {
continue
}
}
if target.PlatformFamily != "" {
if !strings.EqualFold(string(target.PlatformFamily), d.PlatformFamily) {
continue
}
}
if target.PlatformVersion != "" {
if !strings.EqualFold(target.PlatformVersion, d.PlatformVersion) {
continue
}
}
recipes = append(recipes, recipe)
}
}
log.Debugf("%d recipes found for manifest", len(recipes))
return recipes
}