Class: PgCanary::Rules::Base
- Inherits:
-
Object
- Object
- PgCanary::Rules::Base
- Includes:
- PgQuerySupport
- Defined in:
- lib/pg_canary/rules/base.rb
Overview
Base class for detection rules.
A rule implements #check(query) and returns an array of Detection. Configuration flows in explicitly through the QueryContext (query.config); rules never reach for global state themselves.
Direct Known Subclasses
ArraySearchWithoutGin, CartesianJoin, CorrelatedSubqueryInSelect, CountStarWithoutWhere, DeepOffset, DistinctWithJoin, FunctionOnColumn, HugeInList, ImplicitCast, JsonbSearchWithoutGin, LeadingWildcardLike, NotInSubquery, OrAcrossColumns, OrderByRandom, QueryComplexity, RegexWithoutTrgm, SelectStarWithHeavyColumns, UnindexedJoin, UnindexedOrderByWithLimit, UnindexedWhere, UnionInsteadOfUnionAll
Constant Summary
Constants included from PgQuerySupport
PgQuerySupport::COMPARISON_OPS
Class Method Summary collapse
- .all ⇒ Object
-
.options ⇒ Object
Rule-specific options and their defaults, e.g.
-
.rule_name ⇒ Object
:leading_wildcard_like for LeadingWildcardLike.
Instance Method Summary collapse
Class Method Details
.all ⇒ Object
14 15 16 |
# File 'lib/pg_canary/rules/base.rb', line 14 def all subclasses.sort_by(&:name) end |
.options ⇒ Object
Rule-specific options and their defaults, e.g. { threshold: 1000 }. Declared statically so RuleConfig can generate real accessors.
27 28 29 |
# File 'lib/pg_canary/rules/base.rb', line 27 def {} end |
.rule_name ⇒ Object
:leading_wildcard_like for LeadingWildcardLike
19 20 21 22 23 |
# File 'lib/pg_canary/rules/base.rb', line 19 def rule_name @rule_name ||= name.split("::").last .gsub(/([a-z\d])([A-Z])/, '\1_\2') .downcase.to_sym end |
Instance Method Details
#check(_query) ⇒ Object
32 33 34 |
# File 'lib/pg_canary/rules/base.rb', line 32 def check(_query) raise NotImplementedError, "#{self.class} must implement #check" end |
#default_enabled ⇒ Object
41 42 43 |
# File 'lib/pg_canary/rules/base.rb', line 41 def default_enabled raise NotImplementedError, "#{self.class} must declare #default_enabled (true for Tier 1, false for Tier 2)" end |
#enabled?(config) ⇒ Boolean
36 37 38 39 |
# File 'lib/pg_canary/rules/base.rb', line 36 def enabled?(config) setting = config.rules[self.class.rule_name].enabled setting.nil? ? default_enabled : setting end |