class Nexpose::DynamicAssetGroup

Dynamic Asset Group object.

Attributes

criteria[RW]

Search criteria that defines which assets this group will aggregate.

description[RW]

Description of this asset group.

id[RW]

Unique identifier of this group.

name[RW]

Unique name of this group.

users[RW]

Array of user IDs who have permission to access this group.

Public Class Methods

load(nsc, id) click to toggle source

Load in an existing Dynamic Asset Group configuration.

@param [Connection] nsc Connection to a security console. @param [Fixnum] id Unique identifier of an existing group. @return [DynamicAssetGroup] Dynamic asset group configuration.

# 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
new(name, criteria = nil, description = nil) click to toggle source
# File lib/nexpose/dag.rb, line 18
def initialize(name, criteria = nil, description = nil)
  @name, @criteria, @description = name, criteria, description
  @users = []
end

Public Instance Methods

_to_entity_details() click to toggle source
# 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) click to toggle source

Save this dynamic asset group to the Nexpose console. Warning, saving this object does not set the id. It must be retrieved independently.

@param [Connection] nsc Connection to a security console. @return [Boolean] Whether the group was successfully saved.

# 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