Class: Nexpose::Tag
- Inherits:
-
TagSummary
- Object
- TagSummary
- Nexpose::Tag
- Defined in:
- lib/nexpose/tag.rb,
lib/nexpose/tag/criteria.rb
Overview
Tag object containing tag details
Defined Under Namespace
Modules: Type Classes: Criteria, Criterion
Instance Attribute Summary collapse
-
#asset_group_ids ⇒ Object
(also: #group_ids)
Array containing Asset Group IDs to be associated with tag.
-
#asset_ids ⇒ Object
Array containing Asset IDs to be associated with tag.
-
#associated_asset_ids ⇒ Object
Array containing Asset IDs directly associated with the tag.
-
#color ⇒ Object
HEX color code of tag.
-
#risk_modifier ⇒ Object
Risk modifier.
-
#search_criteria ⇒ Object
A TagCriteria.
-
#site_ids ⇒ Object
Array containing Site IDs to be associated with tag.
-
#source ⇒ Object
Creation source.
Attributes inherited from TagSummary
Class Method Summary collapse
-
.load(connection, tag_id) ⇒ Tag
Retrieve detailed description of a single tag.
- .parse(json) ⇒ Object
Instance Method Summary collapse
-
#add_to_asset(connection, asset_id) ⇒ Fixnum
Adds a tag to an asset.
-
#add_to_group(connection, group_id) ⇒ Fixnum
(also: #add_to_asset_group)
Adds a tag to an asset group.
-
#add_to_site(connection, site_id) ⇒ Fixnum
Adds a tag to a site.
-
#delete(connection) ⇒ Object
Delete this tag from Nexpose console.
-
#initialize(name, type, id = -1)) ⇒ Tag
constructor
A new instance of Tag.
-
#save(connection) ⇒ Fixnum
Creates and saves a tag to Nexpose console.
- #to_json ⇒ Object
Methods inherited from TagSummary
Constructor Details
Instance Attribute Details
#asset_group_ids ⇒ Object Also known as: group_ids
Array containing Asset Group IDs to be associated with tag
200 201 202 |
# File 'lib/nexpose/tag.rb', line 200 def asset_group_ids @asset_group_ids end |
#asset_ids ⇒ Object
Array containing Asset IDs to be associated with tag
194 195 196 |
# File 'lib/nexpose/tag.rb', line 194 def asset_ids @asset_ids end |
#associated_asset_ids ⇒ Object
Array containing Asset IDs directly associated with the tag
197 198 199 |
# File 'lib/nexpose/tag.rb', line 197 def associated_asset_ids @associated_asset_ids end |
#color ⇒ Object
HEX color code of tag
185 186 187 |
# File 'lib/nexpose/tag.rb', line 185 def color @color end |
#risk_modifier ⇒ Object
Risk modifier
188 189 190 |
# File 'lib/nexpose/tag.rb', line 188 def risk_modifier @risk_modifier end |
#search_criteria ⇒ Object
A TagCriteria
205 206 207 |
# File 'lib/nexpose/tag.rb', line 205 def search_criteria @search_criteria end |
#site_ids ⇒ Object
Array containing Site IDs to be associated with tag
191 192 193 |
# File 'lib/nexpose/tag.rb', line 191 def site_ids @site_ids end |
#source ⇒ Object
Creation source
182 183 184 |
# File 'lib/nexpose/tag.rb', line 182 def source @source end |
Class Method Details
.load(connection, tag_id) ⇒ Tag
Retrieve detailed description of a single tag
245 246 247 248 |
# File 'lib/nexpose/tag.rb', line 245 def self.load(connection, tag_id) json = JSON.parse(AJAX.get(connection, "/api/2.0/tags/#{tag_id}")) Tag.parse(json) end |
.parse(json) ⇒ Object
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/nexpose/tag.rb', line 279 def self.parse(json) color = json['attributes'].find { |attr| attr['tag_attribute_name'] == 'COLOR' } color = color['tag_attribute_value'] if color source = json['attributes'].find { |attr| attr['tag_attribute_name'] == 'SOURCE' } source = source['tag_attribute_value'] if source tag = Tag.new(json['tag_name'], json['tag_type'], json['tag_id']) tag.color = color tag.source = source tag.asset_ids = json['asset_ids'] if json['tag_config'] tag.site_ids = json['tag_config']['site_ids'] tag.associated_asset_ids = json['tag_config']['tag_associated_asset_ids'] tag.asset_group_ids = json['tag_config']['asset_group_ids'] criteria = json['tag_config']['search_criteria'] tag.search_criteria = criteria ? Criteria.parse(criteria) : nil end modifier = json['attributes'].find { |attr| attr['tag_attribute_name'] == 'RISK_MODIFIER' } if modifier tag.risk_modifier = modifier['tag_attribute_value'].to_i end tag end |
Instance Method Details
#add_to_asset(connection, asset_id) ⇒ Fixnum
Adds a tag to an asset
308 309 310 311 312 |
# File 'lib/nexpose/tag.rb', line 308 def add_to_asset(connection, asset_id) params = _to_json_for_add uri = AJAX.post(connection, "/api/2.0/assets/#{asset_id}/tags", params, AJAX::CONTENT_TYPE::JSON) @id = uri.split('/').last.to_i end |
#add_to_group(connection, group_id) ⇒ Fixnum Also known as: add_to_asset_group
Adds a tag to an asset group
332 333 334 335 336 |
# File 'lib/nexpose/tag.rb', line 332 def add_to_group(connection, group_id) params = _to_json_for_add uri = AJAX.post(connection, "/api/2.0/asset_groups/#{group_id}/tags", params, AJAX::CONTENT_TYPE::JSON) @id = uri.split('/').last.to_i end |
#add_to_site(connection, site_id) ⇒ Fixnum
Adds a tag to a site
320 321 322 323 324 |
# File 'lib/nexpose/tag.rb', line 320 def add_to_site(connection, site_id) params = _to_json_for_add uri = AJAX.post(connection, "/api/2.0/sites/#{site_id}/tags", params, AJAX::CONTENT_TYPE::JSON) @id = uri.split('/').last.to_i end |
#delete(connection) ⇒ Object
Delete this tag from Nexpose console
275 276 277 |
# File 'lib/nexpose/tag.rb', line 275 def delete(connection) connection.delete_tag(@id) end |
#save(connection) ⇒ Fixnum
Creates and saves a tag to Nexpose console
228 229 230 231 232 233 234 235 236 237 |
# File 'lib/nexpose/tag.rb', line 228 def save(connection) params = to_json if @id == -1 uri = AJAX.post(connection, '/api/2.0/tags', params, AJAX::CONTENT_TYPE::JSON) @id = uri.split('/').last.to_i else AJAX.put(connection, "/api/2.0/tags/#{@id}", params, AJAX::CONTENT_TYPE::JSON) end @id end |
#to_json ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/nexpose/tag.rb', line 250 def to_json json = { 'tag_name' => @name, 'tag_type' => @type, 'tag_id' => @id, 'attributes' => [ { 'tag_attribute_name' => 'SOURCE', 'tag_attribute_value' => @source } ], 'tag_config' => { 'site_ids' => @site_ids, 'tag_associated_asset_ids' => @associated_asset_ids, 'asset_group_ids' => @asset_group_ids, 'search_criteria' => @search_criteria ? @search_criteria.to_map : nil } } if @type == Type::Generic::CUSTOM json['attributes'] << { 'tag_attribute_name' => 'COLOR', 'tag_attribute_value' => @color } end JSON.generate(json) end |