Class: Aikido::Zen::Scan

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(sink:, context:) ⇒ 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

#attackAikido::Zen::Attack? (readonly)



16
17
18
# File 'lib/aikido/zen/scan.rb', line 16

def attack
  @attack
end

#contextAikido::Zen::Context (readonly)



12
13
14
# File 'lib/aikido/zen/scan.rb', line 12

def context
  @context
end

#durationFloat? (readonly)



19
20
21
# File 'lib/aikido/zen/scan.rb', line 19

def duration
  @duration
end

#errorsArray<Hash> (readonly)



22
23
24
# File 'lib/aikido/zen/scan.rb', line 22

def errors
  @errors
end

#sinkAikido::Zen::Sink (readonly)



8
9
10
# File 'lib/aikido/zen/scan.rb', line 8

def sink
  @sink
end

Instance Method Details

#attack?Boolean



38
39
40
# File 'lib/aikido/zen/scan.rb', line 38

def attack?
  @attack != nil
end

#errors?Boolean



43
44
45
# File 'lib/aikido/zen/scan.rb', line 43

def errors?
  @errors.any?
end

#performvoid

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.

Yield Returns:



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