-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathscore.go
64 lines (55 loc) · 1.23 KB
/
score.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
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1
package policy
import (
"fmt"
"strings"
)
const (
ScoreType_Unknown uint32 = 0
ScoreType_Result uint32 = 1 << iota
ScoreType_Error
ScoreType_Skip
ScoreType_Unscored
ScoreType_OutOfScope
ScoreType_Disabled
)
// TypeLabel prints the score's type in a human-readable way
func (s *Score) TypeLabel() string {
switch s.Type {
case ScoreType_Unknown:
return "unknown"
case ScoreType_Result:
return "result"
case ScoreType_Error:
return "error"
case ScoreType_Skip:
return "skip"
case ScoreType_Unscored:
return "unscored"
case ScoreType_OutOfScope:
return "out of scope"
case ScoreType_Disabled:
return "disabled"
default:
return "unknown type"
}
}
func (s *Score) HumanStatus() string {
if s == nil {
return "N/A"
}
return fmt.Sprintf("%d (completion: %d%%)", s.Value, s.Completion())
}
// Completion of the score based on its data and scoring completion
func (s *Score) Completion() uint32 {
return (s.DataCompletion + s.ScoreCompletion) / 2
}
// MessageLine prints the message as a single line
func (s *Score) MessageLine() string {
if s == nil {
return ""
}
res := strings.TrimSpace(s.Message)
return strings.ReplaceAll(res, "\n", " ")
}