Class: ActiveStix::Campaign
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ActiveStix::Campaign
- Defined in:
- app/models/active_stix/campaign.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_stix ⇒ Object
- #attack_pattern_relationships ⇒ Object
- #attack_patterns ⇒ Object
- #convert_to_json ⇒ Object
- #indicator_relationships ⇒ Object
- #type ⇒ Object
Class Method Details
.ingest_json(obj) ⇒ Object
5 6 7 8 |
# File 'app/models/active_stix/campaign.rb', line 5 def self.ingest_json(obj) camp = find_or_create_by(stix_id: obj['id'], name: obj['name'], description: obj['description'], first_seen: obj['first_seen'], last_seen: obj['last_seen']) camp end |
Instance Method Details
#as_stix ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/active_stix/campaign.rb', line 40 def as_stix as_json(only: []).tap do |hash| hash["id"] = stix_id hash["type"] = type hash["created"] = created_at.rfc3339(3) hash["modified"] = updated_at.rfc3339(3) hash["first_seen"] = created_at.rfc3339(3) hash["last_seen"] = updated_at.rfc3339(3) hash["name"] = name hash["description"] = description end end |
#attack_pattern_relationships ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/models/active_stix/campaign.rb', line 24 def attack_pattern_relationships relationships = [] ActiveStix::Relationship.where(source: self, relationship_type: "uses", target_type: "ActiveStix::AttackPattern").each do |rel| relationships << rel end relationships end |
#attack_patterns ⇒ Object
20 21 22 |
# File 'app/models/active_stix/campaign.rb', line 20 def attack_patterns attack_pattern_relationships.map(&:target) end |
#convert_to_json ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/active_stix/campaign.rb', line 53 def convert_to_json { :type => "campaign", :id => stix_id, :created => created_at.to_s, :modified => updated_at.to_s, :name => name, :description => description, :first_seen => first_seen, :last_seen => last_seen } end |
#indicator_relationships ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/models/active_stix/campaign.rb', line 32 def indicator_relationships relationships = [] ActiveStix::Relationship.where(source_type: "ActiveStix::Indicator", relationship_type: "indicates", target: self).each do |rel| relationships << rel end relationships end |
#type ⇒ Object
15 16 17 |
# File 'app/models/active_stix/campaign.rb', line 15 def type 'campaign' end |