Class: ActiveStix::Campaign

Inherits:
ApplicationRecord show all
Defined in:
app/models/active_stix/campaign.rb

Class Method Summary collapse

Instance Method Summary collapse

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_stixObject



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_relationshipsObject



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_patternsObject



20
21
22
# File 'app/models/active_stix/campaign.rb', line 20

def attack_patterns
  attack_pattern_relationships.map(&:target)
end

#convert_to_jsonObject



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_relationshipsObject



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

#typeObject



15
16
17
# File 'app/models/active_stix/campaign.rb', line 15

def type
  'campaign'
end