Class: Aikido::Zen::Attack

Inherits:
Object
  • Object
show all
Defined in:
lib/aikido/zen/attack.rb

Overview

Attack objects gather information about a type of detected attack. They can be used in a few ways, like for reporting an attack event to the Aikido server, or can be raised as errors to block requests if blocking_mode is on.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:, sink:, operation:, stack: nil) ⇒ Attack

Returns a new instance of Attack.



13
14
15
16
17
18
19
# File 'lib/aikido/zen/attack.rb', line 13

def initialize(context:, sink:, operation:, stack: nil)
  @context = context
  @operation = operation
  @sink = sink
  @stack = stack
  @blocked = false
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/aikido/zen/attack.rb', line 9

def context
  @context
end

#operationObject (readonly)

Returns the value of attribute operation.



10
11
12
# File 'lib/aikido/zen/attack.rb', line 10

def operation
  @operation
end

#sinkObject

Returns the value of attribute sink.



11
12
13
# File 'lib/aikido/zen/attack.rb', line 11

def sink
  @sink
end

Instance Method Details

#as_jsonObject



45
46
47
48
49
50
51
52
53
# File 'lib/aikido/zen/attack.rb', line 45

def as_json
  {
    kind: kind,
    blocked: blocked?,
    metadata: ,
    operation: @operation,
    stack: @stack
  }.compact.merge(input.as_json)
end

#blocked?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/aikido/zen/attack.rb', line 25

def blocked?
  @blocked
end

#exceptionObject

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/aikido/zen/attack.rb', line 55

def exception(*)
  raise NotImplementedError, "implement in subclasses"
end

#humanized_nameObject

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/aikido/zen/attack.rb', line 29

def humanized_name
  raise NotImplementedError, "implement in subclasses"
end

#inputObject

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/aikido/zen/attack.rb', line 37

def input
  raise NotImplementedError, "implement in subclasses"
end

#kindObject

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/aikido/zen/attack.rb', line 33

def kind
  raise NotImplementedError, "implement in subclasses"
end

#metadataObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/aikido/zen/attack.rb', line 41

def 
  raise NotImplementedError, "implement in subclasses"
end

#will_be_blocked!Object



21
22
23
# File 'lib/aikido/zen/attack.rb', line 21

def will_be_blocked!
  @blocked = true
end