Class: ActiveAttack::Tactic

Inherits:
ApplicationRecord show all
Defined in:
app/models/active_attack/tactic.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ingest_json(obj) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/active_attack/tactic.rb', line 6

def self.ingest_json(obj)
  xmt = find_or_create_by(stix_id: obj['id'], name: obj['name'])

  if obj.has_key?('created_by_ref')
    xmt.created_by_ref = obj['created_by_ref']
  end

  if obj.has_key?('description')
    xmt.description = obj['description']
  end

  if obj.has_key?('external_references')
    obj['external_references'].each do |er|
      external_reference = ActiveStix::ExternalReference.ingest_json(er, obj['id'])
      xmt.external_references << external_reference unless ActiveStix::ReferenceItem.find_by(external_reference_id: external_reference.id, referrer_id: xmt.id, referrer_type: "ActiveAttack::Tactic")
    end
  end

  if obj.has_key?('object_marking_refs')
    # todo
  end

  if obj.has_key?('x_mitre_shortname')
    xmt.shortname = obj['x_mitre_shortname']
  end

  xmt.save
  xmt
end

Instance Method Details

#convert_to_jsonObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/active_attack/tactic.rb', line 36

def convert_to_json
  external_refs_arr = []
  external_references.each do |x|
    external_refs_arr << x.convert_to_json
  end

  marking_def_arr = []
  marking_definitions.each do |x|
    marking_def_arr << x.convert_to_json
  end

  {
      :external_references => external_refs_arr,
      :object_marking_refs => marking_def_arr,
      :id => stix_id,
      :name => name,
      :created => created_at.to_s,
      :modified => updated_at.to_s,
      :type => "type",
      :created_by_ref => created_by_ref,
      :description => description,
      :x_mitre_shortname => shortnames.first.convert_to_json
  }
end