Class: Nexpose::Silo

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

Defined Under Namespace

Classes: Address, Merchant, Organization

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Silo

Returns a new instance of Silo.



47
48
49
# File 'lib/nexpose/silo.rb', line 47

def initialize(&block)
  instance_eval &block if block_given?
end

Instance Attribute Details

#descriptionObject

Optional fields



43
44
45
# File 'lib/nexpose/silo.rb', line 43

def description
  @description
end

#idObject

Required fields



35
36
37
# File 'lib/nexpose/silo.rb', line 35

def id
  @id
end

#max_assetsObject

Returns the value of attribute max_assets.



38
39
40
# File 'lib/nexpose/silo.rb', line 38

def max_assets
  @max_assets
end

#max_hosted_assetsObject

Returns the value of attribute max_hosted_assets.



40
41
42
# File 'lib/nexpose/silo.rb', line 40

def max_hosted_assets
  @max_hosted_assets
end

#max_usersObject

Returns the value of attribute max_users.



39
40
41
# File 'lib/nexpose/silo.rb', line 39

def max_users
  @max_users
end

#merchantObject

Returns the value of attribute merchant.



44
45
46
# File 'lib/nexpose/silo.rb', line 44

def merchant
  @merchant
end

#nameObject

Returns the value of attribute name.



37
38
39
# File 'lib/nexpose/silo.rb', line 37

def name
  @name
end

#organizationObject

Returns the value of attribute organization.



45
46
47
# File 'lib/nexpose/silo.rb', line 45

def organization
  @organization
end

#profile_idObject

Returns the value of attribute profile_id.



36
37
38
# File 'lib/nexpose/silo.rb', line 36

def profile_id
  @profile_id
end

Class Method Details

.copy(connection, id) ⇒ Silo

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

Parameters:

  • connection (Connection)

    Connection to the security console.

  • id (String)

    Silo ID of an existing silo.

Returns:

  • (Silo)

    Silo configuration loaded from a Nexpose console.



58
59
60
61
62
63
# 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) ⇒ Silo

Load an existing configuration from a Nexpose instance.

Parameters:

  • connection (Connection)

    Connection to console where site exists.

  • id (String)

    Silo ID of an existing silo.

Returns:

  • (Silo)

    Silo configuration loaded from a Nexpose console.



71
72
73
74
75
76
77
78
79
80
# 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

.parse(xml) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/nexpose/silo.rb', line 131

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

Instance Method Details

#as_xmlObject



119
120
121
122
123
124
125
# File 'lib/nexpose/silo.rb', line 119

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) ⇒ String

Saves a new silo to a Nexpose console.

Parameters:

  • connection (Connection)

    Connection to console where this silo will be saved.

Returns:

  • (String)

    Silo ID assigned to this configuration, if successful.



108
109
110
111
112
113
# File 'lib/nexpose/silo.rb', line 108

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) ⇒ Object



115
116
117
# File 'lib/nexpose/silo.rb', line 115

def delete(connection)
  connection.delete_silo(@id)
end

#save(connection) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/nexpose/silo.rb', line 82

def save(connection)
  begin
    update(connection)
  rescue APIError => error
    raise error unless (error.message =~ /A silo .* does not exist./)
    create(connection)
  end
end

#to_xmlObject



127
128
129
# File 'lib/nexpose/silo.rb', line 127

def to_xml
  as_xml.to_s
end

#update(connection) ⇒ String

Updates this silo on a Nexpose console.

Parameters:

  • connection (Connection)

    Connection to console where this silo will be saved.

Returns:

  • (String)

    Silo ID assigned to this configuration, if successful.



96
97
98
99
100
101
# File 'lib/nexpose/silo.rb', line 96

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