Class: Nexpose::SiloProfile
- Inherits:
-
Object
- Object
- Nexpose::SiloProfile
- Defined in:
- lib/nexpose/silo_profile.rb
Instance Attribute Summary collapse
-
#all_global_engines ⇒ Object
Returns the value of attribute all_global_engines.
-
#all_global_report_templates ⇒ Object
Returns the value of attribute all_global_report_templates.
-
#all_global_scan_templates ⇒ Object
Returns the value of attribute all_global_scan_templates.
-
#all_licensed_modules ⇒ Object
Returns the value of attribute all_licensed_modules.
-
#description ⇒ Object
Returns the value of attribute description.
-
#global_report_templates ⇒ Object
Returns the value of attribute global_report_templates.
-
#global_scan_engines ⇒ Object
Returns the value of attribute global_scan_engines.
-
#global_scan_templates ⇒ Object
Returns the value of attribute global_scan_templates.
-
#id ⇒ Object
Returns the value of attribute id.
-
#licensed_modules ⇒ Object
Returns the value of attribute licensed_modules.
-
#name ⇒ Object
Returns the value of attribute name.
-
#restricted_report_formats ⇒ Object
Returns the value of attribute restricted_report_formats.
-
#restricted_report_sections ⇒ Object
Returns the value of attribute restricted_report_sections.
Class Method Summary collapse
Instance Method Summary collapse
- #as_xml ⇒ Object
-
#create(connection) ⇒ String
Saves a new silo profile to a Nexpose console.
- #delete(connection) ⇒ Object
-
#initialize(&block) ⇒ SiloProfile
constructor
A new instance of SiloProfile.
- #save(connection) ⇒ Object
- #to_xml ⇒ Object
-
#update(connection) ⇒ String
Updates an existing silo profile on a Nexpose console.
Constructor Details
#initialize(&block) ⇒ SiloProfile
Returns a new instance of SiloProfile.
48 49 50 51 52 53 54 55 56 |
# File 'lib/nexpose/silo_profile.rb', line 48 def initialize(&block) instance_eval &block if block_given? @global_report_templates = Array(@global_report_templates) @global_scan_engines = Array(@global_scan_engines) @global_scan_templates = Array(@global_scan_templates) @licensed_modules = Array(@licensed_modules) @restricted_report_formats = Array(@restricted_report_formats) @restricted_report_sections = Array(@restricted_report_sections) end |
Instance Attribute Details
#all_global_engines ⇒ Object
Returns the value of attribute all_global_engines.
38 39 40 |
# File 'lib/nexpose/silo_profile.rb', line 38 def all_global_engines @all_global_engines end |
#all_global_report_templates ⇒ Object
Returns the value of attribute all_global_report_templates.
39 40 41 |
# File 'lib/nexpose/silo_profile.rb', line 39 def all_global_report_templates @all_global_report_templates end |
#all_global_scan_templates ⇒ Object
Returns the value of attribute all_global_scan_templates.
40 41 42 |
# File 'lib/nexpose/silo_profile.rb', line 40 def all_global_scan_templates @all_global_scan_templates end |
#all_licensed_modules ⇒ Object
Returns the value of attribute all_licensed_modules.
37 38 39 |
# File 'lib/nexpose/silo_profile.rb', line 37 def all_licensed_modules @all_licensed_modules end |
#description ⇒ Object
Returns the value of attribute description.
36 37 38 |
# File 'lib/nexpose/silo_profile.rb', line 36 def description @description end |
#global_report_templates ⇒ Object
Returns the value of attribute global_report_templates.
41 42 43 |
# File 'lib/nexpose/silo_profile.rb', line 41 def global_report_templates @global_report_templates end |
#global_scan_engines ⇒ Object
Returns the value of attribute global_scan_engines.
42 43 44 |
# File 'lib/nexpose/silo_profile.rb', line 42 def global_scan_engines @global_scan_engines end |
#global_scan_templates ⇒ Object
Returns the value of attribute global_scan_templates.
43 44 45 |
# File 'lib/nexpose/silo_profile.rb', line 43 def global_scan_templates @global_scan_templates end |
#id ⇒ Object
Returns the value of attribute id.
34 35 36 |
# File 'lib/nexpose/silo_profile.rb', line 34 def id @id end |
#licensed_modules ⇒ Object
Returns the value of attribute licensed_modules.
44 45 46 |
# File 'lib/nexpose/silo_profile.rb', line 44 def licensed_modules @licensed_modules end |
#name ⇒ Object
Returns the value of attribute name.
35 36 37 |
# File 'lib/nexpose/silo_profile.rb', line 35 def name @name end |
#restricted_report_formats ⇒ Object
Returns the value of attribute restricted_report_formats.
45 46 47 |
# File 'lib/nexpose/silo_profile.rb', line 45 def restricted_report_formats @restricted_report_formats end |
#restricted_report_sections ⇒ Object
Returns the value of attribute restricted_report_sections.
46 47 48 |
# File 'lib/nexpose/silo_profile.rb', line 46 def restricted_report_sections @restricted_report_sections end |
Class Method Details
.copy(connection, id) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/nexpose/silo_profile.rb', line 58 def self.copy(connection, id) profile = load(connection, id) profile.id = nil profile.name = nil profile end |
.load(connection, id) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/nexpose/silo_profile.rb', line 65 def self.load(connection, id) r = connection.execute(connection.make_xml('SiloProfileConfigRequest', {'silo-profile-id' => id}), '1.2') if r.success r.res.elements.each('SiloProfileConfigResponse/SiloProfileConfig') do |config| return SiloProfile.parse(config) end end nil end |
.parse(xml) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/nexpose/silo_profile.rb', line 76 def self.parse(xml) new do |profile| profile.id = xml.attributes['id'] profile.name = xml.attributes['name'] profile.description = xml.attributes['description'] profile.all_licensed_modules = xml.attributes['all-licensed-modules'].to_s.chomp.eql?('true') profile.all_global_engines = xml.attributes['all-global-engines'].to_s.chomp.eql?('true') profile.all_global_report_templates = xml.attributes['all-global-report-templates'].to_s.chomp.eql?('true') profile.all_global_scan_templates = xml.attributes['all-global-scan-templates'].to_s.chomp.eql?('true') profile.global_report_templates = [] xml.elements.each('GlobalReportTemplates/GlobalReportTemplate') { |template| profile.global_report_templates << template.attributes['name'] } profile.global_scan_engines = [] xml.elements.each('GlobalScanEngines/GlobalScanEngine') { |engine| profile.global_scan_engines << engine.attributes['name'] } profile.global_scan_templates = [] xml.elements.each('GlobalScanTemplates/GlobalScanTemplate') { |template| profile.global_scan_templates << template.attributes['name'] } profile.licensed_modules = [] xml.elements.each('LicensedModules/LicensedModule') { |license_module| profile.licensed_modules << license_module.attributes['name'] } profile.restricted_report_formats = [] xml.elements.each('RestrictedReportFormats/RestrictedReportFormat') { |format| profile.restricted_report_formats << format.attributes['name'] } profile.restricted_report_sections = [] xml.elements.each('RestrictedReportSections/RestrictedReportSection') { |section| profile.restricted_report_sections << section.attributes['name'] } end end |
Instance Method Details
#as_xml ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/nexpose/silo_profile.rb', line 143 def as_xml xml = REXML::Element.new('SiloProfileConfig') xml.add_attributes({'id' => @id, 'name' => @name, 'description' => @description, 'all-licensed-modules' => @all_licensed_modules, 'all-global-engines' => @all_global_engines, 'all-global-report-templates' => @all_global_report_templates, 'all-global-scan-templates' => @all_global_scan_templates}) unless @global_report_templates.empty? templates = xml.add_element('GlobalReportTemplates') @global_report_templates.each do |template| templates.add_element('GlobalReportTemplate', {'name' => template}) end end unless @global_scan_engines.empty? engines = xml.add_element('GlobalScanEngines') @global_scan_engines.each do |engine| engines.add_element('GlobalScanEngine', {'name' => engine}) end end unless @global_scan_templates.empty? templates = xml.add_element('GlobalScanTemplates') @global_scan_templates.each do |template| templates.add_element('GlobalScanTemplate', {'name' => template}) end end unless @licensed_modules.empty? licensed_modules = xml.add_element('LicensedModules') @licensed_modules.each do |licensed_module| licensed_modules.add_element('LicensedModule', {'name' => licensed_module}) end end unless @restricted_report_formats.empty? formats = xml.add_element('RestrictedReportFormats') @restricted_report_formats.each do |format| formats.add_element('RestrictedReportFormat', {'name' => format}) end end unless @restricted_report_sections.empty? sections = xml.add_element('RestrictedReportSections') @restricted_report_sections.each do |section| sections.add_element('RestrictedReportSection', {'name' => section}) end end xml end |
#create(connection) ⇒ String
Saves a new silo profile to a Nexpose console.
132 133 134 135 136 137 |
# File 'lib/nexpose/silo_profile.rb', line 132 def create(connection) xml = connection.make_xml('SiloProfileCreateRequest') xml.add_element(as_xml) r = connection.execute(xml, '1.2') @id = r.attributes['silo-profile-id'] if r.success end |
#delete(connection) ⇒ Object
139 140 141 |
# File 'lib/nexpose/silo_profile.rb', line 139 def delete(connection) connection.delete_silo_profile(@id) end |
#save(connection) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/nexpose/silo_profile.rb', line 106 def save(connection) begin update(connection) rescue APIError => error raise error unless (error. =~ /silo profile(\S*|.*?)does not exist/i) create(connection) end end |
#to_xml ⇒ Object
198 199 200 |
# File 'lib/nexpose/silo_profile.rb', line 198 def to_xml as_xml.to_s end |
#update(connection) ⇒ String
Updates an existing silo profile on a Nexpose console.
120 121 122 123 124 125 |
# File 'lib/nexpose/silo_profile.rb', line 120 def update(connection) xml = connection.make_xml('SiloProfileUpdateRequest') xml.add_element(as_xml) r = connection.execute(xml, '1.2') @id = r.attributes['silo-profile-id'] if r.success end |