/
host_certificate.go
74 lines (59 loc) · 1.92 KB
/
host_certificate.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
package analyzer
import (
"path/filepath"
"strings"
"github.com/pkg/errors"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
)
type AnalyzeHostCertificate struct {
hostAnalyzer *troubleshootv1beta2.CertificateAnalyze
}
func (a *AnalyzeHostCertificate) Title() string {
return hostAnalyzerTitleOrDefault(a.hostAnalyzer.AnalyzeMeta, "Certificate Key Pair")
}
func (a *AnalyzeHostCertificate) IsExcluded() (bool, error) {
return isExcluded(a.hostAnalyzer.Exclude)
}
func (a *AnalyzeHostCertificate) Analyze(
getCollectedFileContents func(string) ([]byte, error), findFiles getChildCollectedFileContents,
) ([]*AnalyzeResult, error) {
hostAnalyzer := a.hostAnalyzer
collectorName := hostAnalyzer.CollectorName
if collectorName == "" {
collectorName = "certificate"
}
name := filepath.Join("host-collectors/certificate", collectorName+".json")
contents, err := getCollectedFileContents(name)
if err != nil {
return nil, errors.Wrap(err, "failed to get collected file")
}
status := string(contents)
trimmedStatus := strings.TrimSpace(status)
var coll resultCollector
for _, outcome := range hostAnalyzer.Outcomes {
result := &AnalyzeResult{Title: a.Title()}
if outcome.Fail != nil {
if outcome.Fail.When == "" || outcome.Fail.When == trimmedStatus {
result.IsFail = true
result.Message = outcome.Fail.Message
result.URI = outcome.Fail.URI
coll.push(result)
}
} else if outcome.Warn != nil {
if outcome.Warn.When == "" || outcome.Warn.When == trimmedStatus {
result.IsWarn = true
result.Message = outcome.Warn.Message
result.URI = outcome.Warn.URI
coll.push(result)
}
} else if outcome.Pass != nil {
if outcome.Pass.When == "" || outcome.Pass.When == trimmedStatus {
result.IsPass = true
result.Message = outcome.Pass.Message
result.URI = outcome.Pass.URI
coll.push(result)
}
}
}
return coll.get(a.Title()), nil
}