Extract disabledResult and evidenceEval helpers to reduce boilerplate

Add two shared helpers to source.go and apply them across all sources:
- disabledResult(id, name) replaces the repeated inline SourceResult literal
- evidenceEval(r, severity) replaces the identical Evaluate body in 6 sources
This commit is contained in:
nemunaire 2026-05-15 18:41:45 +08:00
commit 6b1d2e2540
9 changed files with 28 additions and 34 deletions

View file

@ -67,7 +67,7 @@ type urlhausURL struct {
func (s *urlhausSource) Query(ctx context.Context, domain, registered string, opts sdk.CheckerOptions) []SourceResult {
authKey := stringOpt(opts, "urlhaus_auth_key")
if !sdk.GetBoolOption(opts, "enable_urlhaus", true) || registered == "" || authKey == "" {
return []SourceResult{{SourceID: s.ID(), SourceName: s.Name(), Enabled: false}}
return disabledResult(s.ID(), s.Name())
}
res := SourceResult{SourceID: s.ID(), SourceName: s.Name(), Enabled: true}
@ -147,10 +147,7 @@ func (s *urlhausSource) Query(ctx context.Context, domain, registered string, op
}
func (*urlhausSource) Evaluate(r SourceResult) (bool, string) {
if r.Enabled && r.Error == "" && len(r.Evidence) > 0 {
return true, SeverityCrit
}
return false, ""
return evidenceEval(r, SeverityCrit)
}
func (*urlhausSource) Diagnose(res SourceResult) Diagnosis {