class Metascan::Scan
A single scan on the Metascan
service. Initialized with the parameters to scan, exposes methods to inspect the scan results.
Attributes
data_id[R]
filename[R]
Public Class Methods
new(filename, client, archivepwd: nil)
click to toggle source
# File lib/metascan/scan.rb, line 13 def initialize(filename, client, archivepwd: nil) @filename = filename @client = client @archivepwd = archivepwd end
Public Instance Methods
clean?(poll: false)
click to toggle source
Returns true iff the Metascan
virus scan found no threats. If POLL is true (false by default) then retrieve_results
first.
# File lib/metascan/scan.rb, line 47 def clean?(poll: false) if self.results(poll: poll)["scan_results"]["progress_percentage"] < 100 then nil else self.results(poll: poll)["scan_results"]["scan_all_result_i"] == 0 end end
request()
click to toggle source
Construct and return the request I use, for the purpose of queueing in a Typhoeus::Hydra.
# File lib/metascan/scan.rb, line 26 def request request = Typhoeus::Request.new( Metascan::PATHS[:scan_file], headers: { 'filename' => @filename, 'archivepwd' => @archivepwd, 'apikey' => @client.api_key }.select { |k, v| !v.nil? }, method: :post, body: { file: File.open(@filename, "r") } ) request.on_complete do |r| @data_id = JSON.parse(r.body)["data_id"] @rest_ip = JSON.parse(r.body)["rest_ip"].split(":")[0] + '/v2/file' end request end
results(poll: false)
click to toggle source
Return the results of my scan. If the optional argument “poll” is set to true, then attempt to requery Metascan
for the results before returning them.
# File lib/metascan/scan.rb, line 63 def results(poll: false) if poll and (!@results or @results["scan_results"]["progress_percentage"] < 100) then retrieve_results.run end @results end
results=(results)
click to toggle source
Only useful for testing.
# File lib/metascan/scan.rb, line 56 def results=(results) @results = results end
retrieve_results()
click to toggle source
Returns a HTTP request to retrieve the latest scan results for me. Fails if called before @data_id is set (when self.run is called, or my Batch
runs me)
# File lib/metascan/scan.rb, line 74 def retrieve_results request = Typhoeus::Request.new( @rest_ip + '/' + @data_id, headers: { 'apikey' => @client.api_key }, method: :get ) request.on_complete do |r| @results = JSON.parse(r.body) end request end
run()
click to toggle source
Initiate a scan of @filename
# File lib/metascan/scan.rb, line 20 def run self.request.run end