Class: ActiveAttack::Matrix
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ActiveAttack::Matrix
- Defined in:
- app/models/active_attack/matrix.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.ingest_json(obj) ⇒ Object
17 18 19 20 21 22 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 |
# File 'app/models/active_attack/matrix.rb', line 17 def self.ingest_json(obj) xmx = find_or_create_by(stix_id:obj['id'], name:obj['name']) if obj.has_key?('description') xmx.description = obj['description'] end if obj.has_key?('created_by_ref') xmx.created_by_ref = obj['created_by_ref'] end if obj.has_key?('external_references') obj['external_references'].each do |er| external_reference = ActiveStix::ExternalReference.ingest_json(er, obj['id']) xmx.external_references << external_reference unless ActiveStix::ReferenceItem.find_by(external_reference_id:external_reference.id, referrer_id:xmx.id, referrer_type: "ActiveAttack::Matrix") end end if obj.has_key?('object_marking_refs') # todo end if obj.has_key?('tactic_refs') obj['tactic_refs'].each do |tr| tactic_ref = ActiveAttack::Tactic.find_or_create_by(stix_id: tr) xmx.tactics << tactic_ref end end xmx.save xmx end |
Instance Method Details
#convert_to_json ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/active_attack/matrix.rb', line 50 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 tactic_refs_arr = [] x_mitre_tactic_refs.each do | x | tactic_refs_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 => "x-mitre-matrix", :created_by_ref => created_by_ref, :description => description, :tactic_refs => tactic_refs_arr } end |
#ingest_bundle(path) ⇒ Object
9 10 11 12 13 14 |
# File 'app/models/active_attack/matrix.rb', line 9 def ingest_bundle(path) bundle = ActiveStix::Bundle.ingest(path) self.bundle = bundle save bundle end |