Class: Threatinator::EventBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/threatinator/event_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feed_provider, feed_name) ⇒ EventBuilder

Returns a new instance of EventBuilder.

[View source]

10
11
12
13
14
# File 'lib/threatinator/event_builder.rb', line 10

def initialize(feed_provider, feed_name)
  @feed_provider = feed_provider
  @feed_name = feed_name
  self.reset
end

Instance Attribute Details

#type=(value) ⇒ Object (writeonly)

Sets the attribute type

Parameters:

  • value

    the value to set the attribute type to.


8
9
10
# File 'lib/threatinator/event_builder.rb', line 8

def type=(value)
  @type = value
end

Instance Method Details

#add_fqdn(fqdn) ⇒ Object

[View source]

56
57
58
# File 'lib/threatinator/event_builder.rb', line 56

def add_fqdn(fqdn)
  @fqdns << fqdn
end

#add_ipv4(ipv4, opts = {}) ⇒ Object

[View source]

60
61
62
# File 'lib/threatinator/event_builder.rb', line 60

def add_ipv4(ipv4, opts = {})
  @ipv4s << [ipv4, opts]
end

#add_url(url) ⇒ Object

[View source]

64
65
66
# File 'lib/threatinator/event_builder.rb', line 64

def add_url(url)
  @urls << url
end

#buildObject

[View source]

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/threatinator/event_builder.rb', line 23

def build
  opts = {
    feed_provider: @feed_provider,
    feed_name: @feed_name,
  }
  opts[:type] = @type unless @type.nil?

  ret = Threatinator::Event.new(opts)

  @ipv4s.each do |ipv4, opts|
    opts = opts.dup
    if ipv4.is_a?(::String)
      ipv4 = ::IP::V4.parse(ipv4)
    end
    opts[:ipv4] = ipv4
    ret.ipv4s << Threatinator::Model::Observables::Ipv4.new(opts)
  end
  @fqdns.each do |fqdn|
    ret.fqdns << fqdn
  end
  @urls.each do |url|
    url = begin
      ::Addressable::URI.parse(url)
    rescue TypeError => e
      raise Threatinator::Exceptions::EventBuildError, "Failed to parse URL"
    end
    ret.urls << url
  end
  ret
rescue Threatinator::Exceptions::InvalidAttributeError => e
  raise Threatinator::Exceptions::EventBuildError, e.message
end

#resetObject

[View source]

16
17
18
19
20
21
# File 'lib/threatinator/event_builder.rb', line 16

def reset
  @type = nil
  @ipv4s = []
  @fqdns = []
  @urls = []
end