checker: let CheckRule.Evaluate return per-subject CheckStates
Rules that iterate over multiple elements (certificates, CAA records, nameservers, …) previously had to squash per-element results into a single concatenated message. Evaluate now returns []CheckState and CheckState carries an opaque Subject, so each element gets its own structured state. The server injects a StatusUnknown placeholder when a rule returns nothing, to avoid silently dropping the rule.
This commit is contained in:
parent
7567271536
commit
d847c71a50
3 changed files with 30 additions and 9 deletions
|
|
@ -291,11 +291,19 @@ func (s *Server) handleEvaluate(w http.ResponseWriter, r *http.Request) {
|
|||
continue
|
||||
}
|
||||
}
|
||||
state := rule.Evaluate(r.Context(), obs, req.Options)
|
||||
if state.Code == "" {
|
||||
state.Code = rule.Name()
|
||||
ruleStates := rule.Evaluate(r.Context(), obs, req.Options)
|
||||
if len(ruleStates) == 0 {
|
||||
ruleStates = []CheckState{{
|
||||
Status: StatusUnknown,
|
||||
Message: fmt.Sprintf("rule %q returned no state", rule.Name()),
|
||||
}}
|
||||
}
|
||||
for _, state := range ruleStates {
|
||||
if state.Code == "" {
|
||||
state.Code = rule.Name()
|
||||
}
|
||||
states = append(states, state)
|
||||
}
|
||||
states = append(states, state)
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusOK, ExternalEvaluateResponse{States: states})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue