Class: Nexpose::DynamicAssetGroup
- Inherits:
-
Object
- Object
- Nexpose::DynamicAssetGroup
- Defined in:
- lib/nexpose/dag.rb
Overview
Dynamic Asset Group object.
Instance Attribute Summary collapse
-
#criteria ⇒ Object
Search criteria that defines which assets this group will aggregate.
-
#description ⇒ Object
Description of this asset group.
-
#id ⇒ Object
Unique identifier of this group.
-
#name ⇒ Object
Unique name of this group.
-
#users ⇒ Object
Array of user IDs who have permission to access this group.
Class Method Summary collapse
-
.load(nsc, id) ⇒ DynamicAssetGroup
Load in an existing Dynamic Asset Group configuration.
Instance Method Summary collapse
- #_to_entity_details ⇒ Object
-
#initialize(name, criteria = nil, description = nil) ⇒ DynamicAssetGroup
constructor
A new instance of DynamicAssetGroup.
-
#save(nsc) ⇒ Boolean
Save this dynamic asset group to the Nexpose console.
Constructor Details
#initialize(name, criteria = nil, description = nil) ⇒ DynamicAssetGroup
Returns a new instance of DynamicAssetGroup.
18 19 20 21 |
# File 'lib/nexpose/dag.rb', line 18 def initialize(name, criteria = nil, description = nil) @name, @criteria, @description = name, criteria, description @users = [] end |
Instance Attribute Details
#criteria ⇒ Object
Search criteria that defines which assets this group will aggregate.
10 11 12 |
# File 'lib/nexpose/dag.rb', line 10 def criteria @criteria end |
#description ⇒ Object
Description of this asset group.
14 15 16 |
# File 'lib/nexpose/dag.rb', line 14 def description @description end |
#id ⇒ Object
Unique identifier of this group.
12 13 14 |
# File 'lib/nexpose/dag.rb', line 12 def id @id end |
#name ⇒ Object
Unique name of this group.
8 9 10 |
# File 'lib/nexpose/dag.rb', line 8 def name @name end |
#users ⇒ Object
Array of user IDs who have permission to access this group.
16 17 18 |
# File 'lib/nexpose/dag.rb', line 16 def users @users end |
Class Method Details
.load(nsc, id) ⇒ DynamicAssetGroup
Load in an existing Dynamic Asset Group configuration.
46 47 48 49 50 51 52 53 54 |
# File 'lib/nexpose/dag.rb', line 46 def self.load(nsc, id) json = JSON.parse(AJAX.get(nsc, "/data/assetGroup/loadAssetGroup?entityid=#{id}")) raise APIError.new(json, json['message']) if json['response'] =~ /failure/ raise ArgumentError.new('Not a dynamic asset group.') unless json['dynamic'] dag = new(json['name'], Criteria.parse(json['searchCriteria']), json['description']) dag.id = id dag.users = json['users'] dag end |
Instance Method Details
#_to_entity_details ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/nexpose/dag.rb', line 56 def _to_entity_details obj = { 'searchCriteria' => @criteria.to_h, 'name' => @name, 'description' => @description.nil? ? '' : @description, 'dynamic' => true, 'users' => @users } JSON.generate(obj) end |
#save(nsc) ⇒ Boolean
Save this dynamic asset group to the Nexpose console. Warning, saving this object does not set the id. It must be retrieved independently.
30 31 32 33 34 35 36 37 38 |
# File 'lib/nexpose/dag.rb', line 30 def save(nsc) # load includes admin users, but save will fail if they are included. admins = nsc.users.select { |u| u.is_admin }.map { |u| u.id } @users.reject! { |id| admins.member? id } params = @id ? { 'entityid' => @id, 'mode' => 'edit' } : { 'entityid' => false, 'mode' => false } uri = AJAX.parameterize_uri('/data/assetGroup/saveAssetGroup', params) data = JSON.parse(AJAX.post(nsc, uri, _to_entity_details, AJAX::CONTENT_TYPE::JSON)) data['response'] == 'success.' end |