Class: FiberAudit::Configuration
- Inherits:
-
Object
- Object
- FiberAudit::Configuration
- Defined in:
- lib/fiber_audit/configuration.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- KNOWN_TOP_LEVEL_KEYS =
%w[static rules report runtime].freeze
- KNOWN_STATIC_KEYS =
%w[include exclude suppressions_path].freeze
- KNOWN_REPORT_KEYS =
%w[formats min_severity].freeze
- KNOWN_RULE_KEYS =
%w[enabled severity].freeze
- KNOWN_RUNTIME_KEYS =
%w[redaction sampling overhead watchdog fail_open].freeze
- KNOWN_REDACTION_KEYS =
%w[mode].freeze
- KNOWN_SAMPLING_KEYS =
%w[rate].freeze
- KNOWN_OVERHEAD_KEYS =
%w[ max_events_per_second max_events_per_session max_record_bytes max_session_bytes ].freeze
- KNOWN_WATCHDOG_KEYS =
%w[ enabled heartbeat_interval_ms stall_threshold_ms max_frames ].freeze
- RUNTIME_POLICY_PATHS =
{ 'redaction' => 'runtime.redaction.mode', 'sampling_rate' => 'runtime.sampling.rate', 'max_events_per_second' => 'runtime.overhead.max_events_per_second', 'max_events_per_session' => 'runtime.overhead.max_events_per_session', 'max_record_bytes' => 'runtime.overhead.max_record_bytes', 'max_session_bytes' => 'runtime.overhead.max_session_bytes', 'fail_open' => 'runtime.fail_open' }.freeze
- VALID_FORMATS =
%w[text json].freeze
- DEFAULT_STATIC_INCLUDE =
%w[ app/**/*.rb lib/**/*.rb config/**/*.rb config/initializers/**/*.rb ].freeze
- DEFAULT_STATIC_EXCLUDE =
%w[ vendor/**/* tmp/**/* node_modules/**/* db/schema.rb ].freeze
Instance Attribute Summary collapse
-
#min_severity ⇒ Object
readonly
Returns the value of attribute min_severity.
-
#report_formats ⇒ Object
readonly
Returns the value of attribute report_formats.
-
#rules_config ⇒ Object
readonly
Returns the value of attribute rules_config.
-
#runtime_policy ⇒ Object
readonly
Returns the value of attribute runtime_policy.
-
#runtime_watchdog_policy ⇒ Object
readonly
Returns the value of attribute runtime_watchdog_policy.
-
#static_exclude ⇒ Object
readonly
Returns the value of attribute static_exclude.
-
#static_include ⇒ Object
readonly
Returns the value of attribute static_include.
-
#suppressions_path ⇒ Object
readonly
Returns the value of attribute suppressions_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(static_include: DEFAULT_STATIC_INCLUDE, static_exclude: DEFAULT_STATIC_EXCLUDE, rules_config: {}, report_formats: %w[text],, min_severity: :low, suppressions_path: nil, runtime_policy: Runtime::Policy.new, runtime_watchdog_policy: Runtime::WatchdogPolicy.new) ⇒ Configuration
constructor
A new instance of Configuration.
- #rule_enabled?(rule_id) ⇒ Boolean
-
#severity_override(rule_id) ⇒ Object
Returns the overridden severity for a rule as a validated Symbol, or nil when no override is configured.
Constructor Details
#initialize(static_include: DEFAULT_STATIC_INCLUDE, static_exclude: DEFAULT_STATIC_EXCLUDE, rules_config: {}, report_formats: %w[text],, min_severity: :low, suppressions_path: nil, runtime_policy: Runtime::Policy.new, runtime_watchdog_policy: Runtime::WatchdogPolicy.new) ⇒ Configuration
Returns a new instance of Configuration.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fiber_audit/configuration.rb', line 55 def initialize( static_include: DEFAULT_STATIC_INCLUDE, static_exclude: DEFAULT_STATIC_EXCLUDE, rules_config: {}, report_formats: %w[text], min_severity: :low, suppressions_path: nil, runtime_policy: Runtime::Policy.new, runtime_watchdog_policy: Runtime::WatchdogPolicy.new ) validate_types!( static_include, static_exclude, rules_config, report_formats, min_severity, suppressions_path, runtime_policy, runtime_watchdog_policy ) @static_include = static_include @static_exclude = static_exclude @rules_config = rules_config @report_formats = report_formats @min_severity = coerce_severity(min_severity, 'report.min_severity') @suppressions_path = suppressions_path @runtime_policy = runtime_policy @runtime_watchdog_policy = runtime_watchdog_policy end |
Instance Attribute Details
#min_severity ⇒ Object (readonly)
Returns the value of attribute min_severity.
51 52 53 |
# File 'lib/fiber_audit/configuration.rb', line 51 def min_severity @min_severity end |
#report_formats ⇒ Object (readonly)
Returns the value of attribute report_formats.
51 52 53 |
# File 'lib/fiber_audit/configuration.rb', line 51 def report_formats @report_formats end |
#rules_config ⇒ Object (readonly)
Returns the value of attribute rules_config.
51 52 53 |
# File 'lib/fiber_audit/configuration.rb', line 51 def rules_config @rules_config end |
#runtime_policy ⇒ Object (readonly)
Returns the value of attribute runtime_policy.
51 52 53 |
# File 'lib/fiber_audit/configuration.rb', line 51 def runtime_policy @runtime_policy end |
#runtime_watchdog_policy ⇒ Object (readonly)
Returns the value of attribute runtime_watchdog_policy.
51 52 53 |
# File 'lib/fiber_audit/configuration.rb', line 51 def runtime_watchdog_policy @runtime_watchdog_policy end |
#static_exclude ⇒ Object (readonly)
Returns the value of attribute static_exclude.
51 52 53 |
# File 'lib/fiber_audit/configuration.rb', line 51 def static_exclude @static_exclude end |
#static_include ⇒ Object (readonly)
Returns the value of attribute static_include.
51 52 53 |
# File 'lib/fiber_audit/configuration.rb', line 51 def static_include @static_include end |
#suppressions_path ⇒ Object (readonly)
Returns the value of attribute suppressions_path.
51 52 53 |
# File 'lib/fiber_audit/configuration.rb', line 51 def suppressions_path @suppressions_path end |
Class Method Details
.load(path = nil) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/fiber_audit/configuration.rb', line 97 def load(path = nil) return new unless path && File.exist?(path) yaml = YAML.safe_load_file(path) || {} validate_yaml_structure!(yaml) static = yaml['static'] || {} rules = yaml['rules'] || {} report = yaml['report'] || {} runtime = yaml['runtime'] || {} new( static_include: static['include'] || DEFAULT_STATIC_INCLUDE, static_exclude: static['exclude'] || DEFAULT_STATIC_EXCLUDE, rules_config: rules, report_formats: report['formats'] || %w[text], min_severity: report.fetch('min_severity', :low), suppressions_path: static['suppressions_path'], runtime_policy: runtime_policy_from(runtime), runtime_watchdog_policy: runtime_watchdog_policy_from(runtime) ) end |
Instance Method Details
#rule_enabled?(rule_id) ⇒ Boolean
81 82 83 84 |
# File 'lib/fiber_audit/configuration.rb', line 81 def rule_enabled?(rule_id) entry = @rules_config[rule_id] || {} entry.fetch('enabled', true) end |
#severity_override(rule_id) ⇒ Object
Returns the overridden severity for a rule as a validated Symbol, or nil when no override is configured.
88 89 90 91 92 93 94 |
# File 'lib/fiber_audit/configuration.rb', line 88 def severity_override(rule_id) entry = @rules_config[rule_id] || {} sev = entry['severity'] return nil unless sev coerce_severity(sev, "rules.#{rule_id}.severity") end |