Class: MISP::Attribute
Instance Attribute Summary collapse
- #category ⇒ String
- #comment ⇒ String
- #data ⇒ String
- #deleted ⇒ Boolean
- #disable_correlation ⇒ Boolean
- #distribution ⇒ String
- #event_id ⇒ String readonly
- #id ⇒ String readonly
- #shadow_attributes ⇒ Array<MISP::Attribute>
- #sharing_group_id ⇒ String
- #sharing_groups ⇒ Array<MISP::SharingGroup>
- #tags ⇒ Array<MISP::Tag>
- #timestamp ⇒ String
- #to_ids ⇒ Boolean
- #type ⇒ String
- #uuid ⇒ String readonly
- #value ⇒ String
Class Method Summary collapse
- .create(event_id, **attributes) ⇒ Object
- .delete(id) ⇒ Object
- .get(id) ⇒ Object
- .search(**params) ⇒ Object
Instance Method Summary collapse
-
#add_tag(tag) ⇒ MISP::Tag
Add a tag to an attribute.
-
#create(event_id) ⇒ MISP::Attribute
Create an attribute.
-
#delete ⇒ Hash
Delete an attribute.
-
#get ⇒ MISP::Attribute
Get an attribute.
-
#initialize(**attributes) ⇒ Attribute
constructor
A new instance of Attribute.
-
#remove_tag(tag) ⇒ Hash
Remove a tag from an attribute.
-
#search(**params) ⇒ Array<MISP::Attributes>
Search for attributes.
-
#to_h ⇒ Hash
Returns a hash representation of the attribute data.
-
#update(**attrs) ⇒ MISP::Attribute
Update an attribute.
Constructor Details
#initialize(**attributes) ⇒ Attribute
Returns a new instance of Attribute.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/misp/attribute.rb', line 41 def initialize(**attributes) attributes = normalize_attributes(attributes) @id = attributes.dig(:id) @type = attributes.dig(:type) @category = attributes.dig(:category) @to_ids = attributes.dig(:to_ids) @uuid = attributes.dig(:uuid) @event_id = attributes.dig(:event_id) @distribution = attributes.dig(:distribution) @timestamp = attributes.dig(:timestamp) @comment = attributes.dig(:comment) @sharing_group_id = attributes.dig(:sharing_group_id) @deleted = attributes.dig(:deleted) @disable_correlation = attributes.dig(:disable_correlation) @value = attributes.dig(:value) @data = attributes.dig(:data) @sharing_groups = build_plural_attribute(items: attributes.dig(:SharingGroup), klass: SharingGroup) @shadow_attributes = build_plural_attribute(items: attributes.dig(:ShadowAttribute), klass: Attribute ) @tags = build_plural_attribute(items: attributes.dig(:Tag), klass: Tag) end |
Instance Attribute Details
#category ⇒ String
10 11 12 |
# File 'lib/misp/attribute.rb', line 10 def category @category end |
#comment ⇒ String
22 23 24 |
# File 'lib/misp/attribute.rb', line 22 def comment @comment end |
#data ⇒ String
32 33 34 |
# File 'lib/misp/attribute.rb', line 32 def data @data end |
#deleted ⇒ Boolean
26 27 28 |
# File 'lib/misp/attribute.rb', line 26 def deleted @deleted end |
#disable_correlation ⇒ Boolean
28 29 30 |
# File 'lib/misp/attribute.rb', line 28 def disable_correlation @disable_correlation end |
#distribution ⇒ String
18 19 20 |
# File 'lib/misp/attribute.rb', line 18 def distribution @distribution end |
#event_id ⇒ String (readonly)
16 17 18 |
# File 'lib/misp/attribute.rb', line 16 def event_id @event_id end |
#id ⇒ String (readonly)
6 7 8 |
# File 'lib/misp/attribute.rb', line 6 def id @id end |
#shadow_attributes ⇒ Array<MISP::Attribute>
37 38 39 |
# File 'lib/misp/attribute.rb', line 37 def shadow_attributes @shadow_attributes end |
#sharing_group_id ⇒ String
24 25 26 |
# File 'lib/misp/attribute.rb', line 24 def sharing_group_id @sharing_group_id end |
#sharing_groups ⇒ Array<MISP::SharingGroup>
35 36 37 |
# File 'lib/misp/attribute.rb', line 35 def sharing_groups @sharing_groups end |
#timestamp ⇒ String
20 21 22 |
# File 'lib/misp/attribute.rb', line 20 def @timestamp end |
#to_ids ⇒ Boolean
12 13 14 |
# File 'lib/misp/attribute.rb', line 12 def to_ids @to_ids end |
#type ⇒ String
8 9 10 |
# File 'lib/misp/attribute.rb', line 8 def type @type end |
#uuid ⇒ String (readonly)
14 15 16 |
# File 'lib/misp/attribute.rb', line 14 def uuid @uuid end |
#value ⇒ String
30 31 32 |
# File 'lib/misp/attribute.rb', line 30 def value @value end |
Class Method Details
.create(event_id, **attributes) ⇒ Object
186 187 188 |
# File 'lib/misp/attribute.rb', line 186 def create(event_id, **attributes) new(attributes).create(event_id) end |
.delete(id) ⇒ Object
182 183 184 |
# File 'lib/misp/attribute.rb', line 182 def delete(id) new(id: id).delete end |
.get(id) ⇒ Object
178 179 180 |
# File 'lib/misp/attribute.rb', line 178 def get(id) new(id: id).get end |
.search(**params) ⇒ Object
190 191 192 |
# File 'lib/misp/attribute.rb', line 190 def search(**params) new.search params end |
Instance Method Details
#add_tag(tag) ⇒ MISP::Tag
Add a tag to an attribute
158 159 160 161 162 |
# File 'lib/misp/attribute.rb', line 158 def add_tag(tag) tag = Tag.new(tag) unless tag.is_a?(MISP::Tag) payload = { uuid: uuid, tag: tag.name } _post("/tags/attachTagToObject", payload) { |json| Tag.new json } end |
#create(event_id) ⇒ MISP::Attribute
Create an attribute
114 115 116 |
# File 'lib/misp/attribute.rb', line 114 def create(event_id) _post("/attributes/add/#{event_id}", wrap(to_h)) { |attribute| Attribute.new attribute } end |
#delete ⇒ Hash
Delete an attribute
105 106 107 |
# File 'lib/misp/attribute.rb', line 105 def delete _post("/attributes/delete/#{id}") { |json| json } end |
#get ⇒ MISP::Attribute
Get an attribute
96 97 98 |
# File 'lib/misp/attribute.rb', line 96 def get _get("/attributes/#{id}") { |attribute| Attribute.new attribute } end |
#remove_tag(tag) ⇒ Hash
Remove a tag from an attribute
171 172 173 174 175 |
# File 'lib/misp/attribute.rb', line 171 def remove_tag(tag) tag = Tag.new(tag) unless tag.is_a?(MISP::Tag) payload = { uuid: uuid, tag: tag.name } _post("/tags/removeTagFromObject", payload) { |json| json } end |
#search(**params) ⇒ Array<MISP::Attributes>
Search for attributes
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/misp/attribute.rb', line 138 def search(**params) base = { returnFormat: "json", limit: "100", page: "0" } _post("/attributes/restSearch", base.merge(params)) do |json| attributes = json.dig(:response, :Attribute) || [] attributes.map { |attribute| Attribute.new attribute } end end |
#to_h ⇒ Hash
Returns a hash representation of the attribute data.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/misp/attribute.rb', line 69 def to_h { id: id, type: type, category: category, to_ids: to_ids, uuid: uuid, event_id: event_id, distribution: distribution, timestamp: , comment: comment, sharing_group_id: sharing_group_id, deleted: deleted, disable_correlation: disable_correlation, value: value, data: data, SharingGroup: sharing_groups.map(&:to_h), ShadowAttribute: shadow_attributes.map(&:to_h), Tag: .map(&:to_h) }.compact end |
#update(**attrs) ⇒ MISP::Attribute
Update an attribute
125 126 127 128 129 |
# File 'lib/misp/attribute.rb', line 125 def update(**attrs) payload = to_h.merge(attrs) payload[:timestamp] = nil _post("/attributes/edit/#{id}", wrap(payload)) { |json| Attribute.new json.dig(:response, :Attribute) } end |