class Nexpose::Silo

Attributes

description[RW]

Optional fields

id[RW]

Required fields

max_assets[RW]
max_hosted_assets[RW]
max_users[RW]
merchant[RW]
name[RW]
organization[RW]
profile_id[RW]

Public Class Methods

copy(connection, id) click to toggle source

Copy an existing configuration from a Nexpose instance. Returned object will reset the silo ID and name

@param [Connection] connection Connection to the security console. @param [String] id Silo ID of an existing silo. @return [Silo] Silo configuration loaded from a Nexpose console.

# File lib/nexpose/silo.rb, line 58
def self.copy(connection, id)
  silo      = load(connection, id)
  silo.id   = nil
  silo.name = nil
  silo
end
load(connection, id) click to toggle source

Load an existing configuration from a Nexpose instance.

@param [Connection] connection Connection to console where site exists. @param [String] id Silo ID of an existing silo. @return [Silo] Silo configuration loaded from a Nexpose console.

# File lib/nexpose/silo.rb, line 71
def self.load(connection, id)
  r = connection.execute(connection.make_xml('SiloConfigRequest', { 'silo-id' => id }), '1.2')

  if r.success
    r.res.elements.each('SiloConfigResponse/SiloConfig') do |config|
      return Silo.parse(config)
    end
  end
  nil
end
new(&block) click to toggle source
# File lib/nexpose/silo.rb, line 47
def initialize(&block)
  instance_eval(&block) if block_given?
end
parse(xml) click to toggle source
# File lib/nexpose/silo.rb, line 130
def self.parse(xml)
  new do |silo|
    silo.id                = xml.attributes['id']
    silo.profile_id        = xml.attributes['silo-profile-id']
    silo.name              = xml.attributes['name']
    silo.max_assets        = xml.attributes['max-assets'].to_i
    silo.max_users         = xml.attributes['max-users'].to_i
    silo.max_hosted_assets = xml.attributes['max-hosted-assets'].to_i
    silo.description       = xml.attributes['description']

    xml.elements.each('Merchant') do |merchant|
      silo.merchant = Merchant.parse(merchant)
    end

    xml.elements.each('Organization') do |organization|
      silo.organization = Organization.parse(organization)
    end
  end
end

Public Instance Methods

as_xml() click to toggle source
# File lib/nexpose/silo.rb, line 117
def as_xml
  xml = REXML::Element.new('SiloConfig')
  xml.add_attributes({ 'description' => @description, 'name' => @name, 'id' => @id, 'silo-profile-id' => @profile_id,
                       'max-assets' => @max_assets, 'max-users' => @max_users, 'max-hosted-assets' => @max_hosted_assets })
  xml.add(@merchant.as_xml) if @merchant
  xml.add(@organization.as_xml) if @organization
  xml
end
create(connection) click to toggle source

Saves a new silo to a Nexpose console.

@param [Connection] connection Connection to console where this silo will be saved. @return [String] Silo ID assigned to this configuration, if successful.

# File lib/nexpose/silo.rb, line 106
def create(connection)
  xml = connection.make_xml('SiloCreateRequest')
  xml.add_element(as_xml)
  r = connection.execute(xml, '1.2')
  @id = r.attributes['id'] if r.success
end
delete(connection) click to toggle source
# File lib/nexpose/silo.rb, line 113
def delete(connection)
  connection.delete_silo(@id)
end
save(connection) click to toggle source
# File lib/nexpose/silo.rb, line 82
def save(connection)
  update(connection)
rescue APIError => error
  raise error unless error.message =~ /A silo .* does not exist./
  create(connection)
end
to_xml() click to toggle source
# File lib/nexpose/silo.rb, line 126
def to_xml
  as_xml.to_s
end
update(connection) click to toggle source

Updates this silo on a Nexpose console.

@param [Connection] connection Connection to console where this silo will be saved. @return [String] Silo ID assigned to this configuration, if successful.

# File lib/nexpose/silo.rb, line 94
def update(connection)
  xml = connection.make_xml('SiloUpdateRequest')
  xml.add_element(as_xml)
  r = connection.execute(xml, '1.2')
  @id = r.attributes['id'] if r.success
end