Class: Nexpose::DynamicAssetGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose/dag.rb

Overview

Dynamic Asset Group object.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#criteriaObject

Search criteria that defines which assets this group will aggregate.



10
11
12
# File 'lib/nexpose/dag.rb', line 10

def criteria
  @criteria
end

#descriptionObject

Description of this asset group.



14
15
16
# File 'lib/nexpose/dag.rb', line 14

def description
  @description
end

#idObject

Unique identifier of this group.



12
13
14
# File 'lib/nexpose/dag.rb', line 12

def id
  @id
end

#nameObject

Unique name of this group.



8
9
10
# File 'lib/nexpose/dag.rb', line 8

def name
  @name
end

#usersObject

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.

Parameters:

  • nsc (Connection)

    Connection to a security console.

  • id (Fixnum)

    Unique identifier of an existing group.

Returns:

Raises:



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_detailsObject



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.

Parameters:

  • nsc (Connection)

    Connection to a security console.

Returns:

  • (Boolean)

    Whether the group was successfully saved.



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