Class: Hachi::Models::Artifact

Inherits:
Base
  • Object
show all
Defined in:
lib/hachi/models/artifact.rb

Constant Summary collapse

DATA_TYPES =
%w(filename file fqdn hash uri_path ip domain mail autonomous-system registry mail_subject regexp user-agent other url).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, data_type:, message: nil, tlp: nil, tags: nil) ⇒ Artifact

Returns a new instance of Artifact.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hachi/models/artifact.rb', line 10

def initialize(data:, data_type:, message: nil, tlp: nil, tags: nil)
  @data = data
  @data_type = data_type
  @message = message
  @tlp = tlp
  @tags = tags

  raise(ArgumentError, "data is required") unless data
  raise(ArgumentError, "data_type is required") unless data_type
  raise(ArgumentError, "invalid data type") unless DATA_TYPES.include?(data_type)

  validate_tags if tags
  validate_tlp if tlp
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/hachi/models/artifact.rb', line 8

def data
  @data
end

#data_typeObject (readonly)

Returns the value of attribute data_type.



8
9
10
# File 'lib/hachi/models/artifact.rb', line 8

def data_type
  @data_type
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/hachi/models/artifact.rb', line 8

def message
  @message
end

#tagsObject (readonly)

Returns the value of attribute tags.



8
9
10
# File 'lib/hachi/models/artifact.rb', line 8

def tags
  @tags
end

#tlpObject (readonly)

Returns the value of attribute tlp.



8
9
10
# File 'lib/hachi/models/artifact.rb', line 8

def tlp
  @tlp
end

Instance Method Details

#payloadObject



25
26
27
28
29
30
31
32
33
# File 'lib/hachi/models/artifact.rb', line 25

def payload
  {
    data: data,
    dataType: data_type,
    message: message,
    tlp: tlp,
    tags: tags
  }.compact
end

#validate_for_creationObject

Raises:

  • (ArgumentError)


35
36
37
# File 'lib/hachi/models/artifact.rb', line 35

def validate_for_creation
  raise(ArgumentError, "message or tags is requried for artifact creation") unless message || tags
end