Class: Aikido::Zen::Scan
- Inherits:
-
Object
- Object
- Aikido::Zen::Scan
- Defined in:
- lib/aikido/zen/scan.rb
Overview
Scans track information about a single call made by one of our Sinks including whether it was detected as an attack or how long it took.
Instance Attribute Summary collapse
-
#attack ⇒ Aikido::Zen::Attack?
readonly
A detected Attack, or
nil
if the scan was considered safe. -
#context ⇒ Aikido::Zen::Context
readonly
The current Context, wrapping the HTTP request during which this scan was performed.
-
#duration ⇒ Float?
readonly
Duration in (fractional) seconds of the scan.
-
#errors ⇒ Array<Hash>
readonly
List of captured exceptions while scanning.
-
#sink ⇒ Aikido::Zen::Sink
readonly
The originating Sink.
Instance Method Summary collapse
-
#attack? ⇒ Boolean
Whether this scan detected an Attack.
-
#errors? ⇒ Boolean
Whether any errors were caught by this Scan.
-
#initialize(sink:, context:) ⇒ Scan
constructor
A new instance of Scan.
-
#perform ⇒ void
Runs a block of code, capturing its return value as the potential Attack object (or nil, if safe), and how long it took to run.
- #performed? ⇒ Boolean
-
#track_error(error, scanner) ⇒ nil
Keep track of exceptions encountered during scanning.
Constructor Details
#initialize(sink:, context:) ⇒ Scan
Returns a new instance of Scan.
26 27 28 29 30 31 |
# File 'lib/aikido/zen/scan.rb', line 26 def initialize(sink:, context:) @sink = sink @context = context @errors = [] @performed = false end |
Instance Attribute Details
#attack ⇒ Aikido::Zen::Attack? (readonly)
Returns a detected Attack, or nil
if the scan was considered safe.
16 17 18 |
# File 'lib/aikido/zen/scan.rb', line 16 def attack @attack end |
#context ⇒ Aikido::Zen::Context (readonly)
Returns the current Context, wrapping the HTTP request during which this scan was performed.
12 13 14 |
# File 'lib/aikido/zen/scan.rb', line 12 def context @context end |
#duration ⇒ Float? (readonly)
Returns duration in (fractional) seconds of the scan.
19 20 21 |
# File 'lib/aikido/zen/scan.rb', line 19 def duration @duration end |
#errors ⇒ Array<Hash> (readonly)
Returns list of captured exceptions while scanning.
22 23 24 |
# File 'lib/aikido/zen/scan.rb', line 22 def errors @errors end |
#sink ⇒ Aikido::Zen::Sink (readonly)
Returns the originating Sink.
8 9 10 |
# File 'lib/aikido/zen/scan.rb', line 8 def sink @sink end |
Instance Method Details
#attack? ⇒ Boolean
Returns whether this scan detected an Attack.
38 39 40 |
# File 'lib/aikido/zen/scan.rb', line 38 def attack? @attack != nil end |
#errors? ⇒ Boolean
Returns whether any errors were caught by this Scan.
43 44 45 |
# File 'lib/aikido/zen/scan.rb', line 43 def errors? @errors.any? end |
#perform ⇒ void
This method returns an undefined value.
Runs a block of code, capturing its return value as the potential Attack object (or nil, if safe), and how long it took to run.
52 53 54 55 56 57 58 |
# File 'lib/aikido/zen/scan.rb', line 52 def perform @performed = true started_at = monotonic_time @attack = yield ensure @duration = monotonic_time - started_at end |
#performed? ⇒ Boolean
33 34 35 |
# File 'lib/aikido/zen/scan.rb', line 33 def performed? @performed end |
#track_error(error, scanner) ⇒ nil
Keep track of exceptions encountered during scanning.
66 67 68 69 |
# File 'lib/aikido/zen/scan.rb', line 66 def track_error(error, scanner) @errors << {error: error, scanner: scanner} nil end |