class Nexpose::Wait

Attributes

error_message[R]
polling_interval[R]
ready[R]
retry_count[R]
timeout[R]

Public Class Methods

new(retry_count: nil, timeout: nil, polling_interval: nil) click to toggle source
# File lib/nexpose/wait.rb, line 6
def initialize(retry_count: nil, timeout: nil, polling_interval: nil)
  @error_message    = 'Default General Failure in Nexpose::Wait'
  @ready            = false
  @retry_count      = retry_count.to_i
  @timeout          = timeout
  @polling_interval = polling_interval
end

Public Instance Methods

for_integration(nexpose_connection:, scan_id:, status: 'finished') click to toggle source
# File lib/nexpose/wait.rb, line 34
def for_integration(nexpose_connection:, scan_id:, status: 'finished')
  poller = Nexpose::Poller.new(timeout: @timeout, polling_interval: @polling_interval)
  poller.wait(integration_status_proc(nexpose_connection: nexpose_connection, scan_id: scan_id, status: status))
  @ready = true
rescue Timeout::Error
  @ready = false
  retry if timeout_retry?
  @error_message = "Timeout Waiting for Integration Status of '#{status}' - Scan ID: #{scan_id}"
rescue Nexpose::APIError => error
  @ready = false
  @error_message = "API Error Waiting for Integration Scan ID: #{scan_id} :: #{error.req.error}"
end
for_judgment(proc:, desc:) click to toggle source
# File lib/nexpose/wait.rb, line 47
def for_judgment(proc:, desc:)
  poller = Nexpose::Poller.new(timeout: @timeout, polling_interval: @polling_interval)
  poller.wait(proc)
  @ready = true
rescue Timeout::Error
  @ready = false
  retry if timeout_retry?
  @error_message = "Timeout Waiting for Judgment to Judge. #{desc}"
end
for_report(nexpose_connection:, report_id:) click to toggle source
# File lib/nexpose/wait.rb, line 18
def for_report(nexpose_connection:, report_id:)
  poller = Nexpose::Poller.new(timeout: @timeout, polling_interval: @polling_interval)
  poller.wait(report_status_proc(nexpose_connection: nexpose_connection, report_id: report_id))
  @ready = true
rescue Timeout::Error
  @ready = false
  retry if timeout_retry?
  @error_message = "Timeout Waiting for Report to Generate - Report Config ID: #{report_id}"
rescue NoMethodError => error
  @ready = false
  @error_message = "Error Report Config ID: #{report_id} :: Report Probably Does Not Exist :: #{error}"
rescue => error
  @ready = false
  @error_message = "Error Report Config ID: #{report_id} :: #{error}"
end
ready?() click to toggle source
# File lib/nexpose/wait.rb, line 14
def ready?
  @ready
end

Private Instance Methods

integration_status_proc(nexpose_connection:, scan_id:, status:) click to toggle source
# File lib/nexpose/wait.rb, line 63
def integration_status_proc(nexpose_connection:, scan_id:, status:)
  proc { nexpose_connection.scan_status(scan_id).downcase == status.downcase }
end
report_status_proc(nexpose_connection:, report_id:) click to toggle source
# File lib/nexpose/wait.rb, line 59
def report_status_proc(nexpose_connection:, report_id:)
  proc { nexpose_connection.last_report(report_id).status == 'Generated' }
end
timeout_retry?() click to toggle source
# File lib/nexpose/wait.rb, line 67
def timeout_retry?
  if @retry_count > 0
    @retry_count -= 1
    true
  else
    false
  end
end