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:
parent
061b5361ca
commit
6b1d2e2540
9 changed files with 28 additions and 34 deletions
|
|
@ -54,7 +54,7 @@ func (*safeBrowsingSource) Options() SourceOptions {
|
|||
func (s *safeBrowsingSource) Query(ctx context.Context, domain, registered string, opts sdk.CheckerOptions) []SourceResult {
|
||||
apiKey := stringOpt(opts, "google_safe_browsing_api_key")
|
||||
if apiKey == "" {
|
||||
return []SourceResult{{SourceID: s.ID(), SourceName: s.Name(), Enabled: false}}
|
||||
return disabledResult(s.ID(), s.Name())
|
||||
}
|
||||
if registered == "" {
|
||||
return []SourceResult{{SourceID: s.ID(), SourceName: s.Name(), Enabled: true}}
|
||||
|
|
@ -142,10 +142,7 @@ func (s *safeBrowsingSource) Query(ctx context.Context, domain, registered strin
|
|||
}
|
||||
|
||||
func (*safeBrowsingSource) Evaluate(r SourceResult) (bool, string) {
|
||||
if r.Enabled && r.Error == "" && len(r.Evidence) > 0 {
|
||||
return true, SeverityCrit
|
||||
}
|
||||
return false, ""
|
||||
return evidenceEval(r, SeverityCrit)
|
||||
}
|
||||
|
||||
func (*safeBrowsingSource) Diagnose(res SourceResult) Diagnosis {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue