Class: Karst::Access::Sweep
- Inherits:
-
Object
- Object
- Karst::Access::Sweep
- Defined in:
- lib/karst/access/sweep.rb
Overview
Sequentially observes one concrete local GET using a fresh integration session and a rollback-only transaction for every bounded principal. rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
-
#call ⇒ Object
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/ParameterLists.
-
#initialize(path:, principals:, http_method: "GET", limit: Karst.config.access_sweep_limit, application: nil, candidate_pool_size: nil, sampling_reasons: {}, body_includes: nil) ⇒ Sweep
constructor
sampling_reasons optionally maps a principal (by Ruby equality, so the same Active Record identity even across separate instances) to the Array of reasons it was selected for -- see Access::PrincipalSampler::Candidate/PrincipalSelection.
Constructor Details
#initialize(path:, principals:, http_method: "GET", limit: Karst.config.access_sweep_limit, application: nil, candidate_pool_size: nil, sampling_reasons: {}, body_includes: nil) ⇒ Sweep
sampling_reasons optionally maps a principal (by Ruby equality, so the same Active Record identity even across separate instances) to the Array of reasons it was selected for -- see Access::PrincipalSampler::Candidate/PrincipalSelection. A principal with no entry simply gets an empty Array on its Outcome. rubocop:disable Metrics/ParameterLists rubocop:disable Metrics/MethodLength
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/karst/access/sweep.rb', line 50 def initialize(path:, principals:, http_method: "GET", limit: Karst.config.access_sweep_limit, application: nil, candidate_pool_size: nil, sampling_reasons: {}, body_includes: nil) @path = normalize_path(path) @http_method = http_method.to_s.upcase raise UnsupportedMethod, "access sweeps support GET only" unless @http_method == "GET" raise ArgumentError, "limit exceeds configured access_sweep_limit" unless valid_limit?(limit) @principals = principals @limit = limit @application = application || Rails.application @probe_application = build_probe_application @candidate_pool_size = candidate_pool_size @sampling_reasons = sampling_reasons @body_includes = body_includes end |
Instance Method Details
#call ⇒ Object
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/ParameterLists
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/karst/access/sweep.rb', line 68 def call raise Unavailable, "access sweeps are development-only" unless Rails.env.development? raise Unavailable, "Karst is disabled (config.enabled)" unless Karst.enabled? require "action_dispatch/testing/integration" unless defined?(ActionDispatch::Integration::Session) started = monotonic outcomes = bounded_principals.map { |principal| probe(principal) } Result.new(path: @path, http_method: @http_method, outcomes: outcomes.freeze, elapsed_ms: elapsed(started), aborted_reason: nil, database_isolation: :same_connection_rollback_attempted, candidate_pool_size: @candidate_pool_size) end |