Skip to content
This repository has been archived by the owner on Sep 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from fakenine/refactor_results_model
Browse files Browse the repository at this point in the history
Refactor results model
  • Loading branch information
fwininger committed Dec 14, 2017
2 parents e579d4c + c0f96db commit 3898b84
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 58 deletions.
2 changes: 0 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Style/Documentation:
- 'lib/openvas/client.rb'
- 'lib/openvas/config.rb'
- 'lib/openvas/reports.rb'
- 'lib/openvas/results.rb'
- 'lib/openvas/scans.rb'

# Offense count: 2
# Cop supports --auto-correct.
Expand Down
2 changes: 1 addition & 1 deletion lib/openvas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

require 'openvas/scan'
require 'openvas/reports'
require 'openvas/results'
require 'openvas/result'

module Openvas
extend self
Expand Down
2 changes: 1 addition & 1 deletion lib/openvas/reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize(report)
end

def results
Openvas::Results.find_by_report_id(@id)
Openvas::Result.find_by_report_id(@id)
end
end
end
55 changes: 55 additions & 0 deletions lib/openvas/result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

require 'time'

module Openvas
# Class used to interact with OpenVAS' scans results
class Result
attr_accessor :id, :name, :comment, :description, :host, :user, :port, :severity, :created_at, :updated_at

def initialize(result)
@id = result.at_xpath('@id').value
@name = result.at_xpath('name').text
@comment = result.at_xpath('comment').text
@user = result.at_xpath('owner/name').text
@host = result.at_xpath('host').text
@port = result.at_xpath('port').text
@severity = result.at_xpath('severity').text
@description = result.at_xpath('description').text

@created_at = Time.parse(result.at_xpath('creation_time').text)
@updated_at = Time.parse(result.at_xpath('modification_time').text)
end

def results
Openvas::Result.find_by_report_id(@id)
end

class << self
MAX_RESULTS = 1000

def all
# TODO: implement pagination
query = Nokogiri::XML::Builder.new { get_results(filter: "first=1 rows=#{MAX_RESULTS}") }

query(query).xpath('//get_results_response/result').map do |result|
new(result)
end
end

def find_by_id(id)
query = Nokogiri::XML::Builder.new { get_results(result_id: id) }
new(query(query).at_xpath('//get_results_response/result'))
end

def find_by_report_id(id)
# TODO: implement pagination
query = Nokogiri::XML::Builder.new { get_results(filter: "report_id=#{id} first=1 rows=#{MAX_RESULTS}") }

query(query).xpath('//get_results_response/result').map do |result|
new(result)
end
end
end
end
end
53 changes: 0 additions & 53 deletions lib/openvas/results.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/openvas/scan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def last_report
end

def last_results
Openvas::Results.find_by_report_id(@last_report_id)
Openvas::Result.find_by_report_id(@last_report_id)
end

def finished?
Expand Down

0 comments on commit 3898b84

Please sign in to comment.