Class: Workers::Import

Inherits:
Object
  • Object
show all
Includes:
Ronin::App, Sidekiq::Worker
Defined in:
workers/import.rb

Overview

Worker which imports nmap or masscan scan files.

Constant Summary collapse

Params =

The accepted JSON params which will be passed to #perform.

Dry::Schema::JSON() do
  required(:type).filled(Types::Import::TypeType)
  required(:path).filled(:string)
end
IMPORT_TYPES =

Mapping of importer types and the importer modules.

{
  'nmap'    => Ronin::Nmap::Importer,
  'masscan' => Ronin::Masscan::Importer
}

Constants included from Ronin::App

Ronin::App::ROOT, Ronin::App::VERSION

Instance Method Summary collapse

Instance Method Details

#perform(params) ⇒ Object

Processes an import job.

Parameters:

  • params (Hash{String => Object})

    The JSON deserialized params for the job.

Raises:

  • (ArgumentError)

    The params could not be validated or coerced.



60
61
62
63
64
65
66
67
68
69
70
71
# File 'workers/import.rb', line 60

def perform(params)
  kwargs = validate(params)

  type = kwargs[:type]
  path = kwargs[:path]

  importer = IMPORT_TYPES.fetch(type) do
    raise(NotImplementedError,"unsupported import type: #{type.inspect}")
  end

  importer.import_file(path)
end

#validate(params) ⇒ Hash{Symbol => Object}

Validates the given job params.

Parameters:

  • params (Hash{String => Object})

    The JSON deserialized params for the job.

Returns:

  • (Hash{Symbol => Object})

    The validated and coerced params as a Symbol Hash.

Raises:

  • (ArgumentError)

    The params could not be validated or coerced.



85
86
87
88
89
90
91
92
93
# File 'workers/import.rb', line 85

def validate(params)
  result = Params.call(params)

  if result.failure?
    raise(ArgumentError,"invalid import params (#{params.inspect}): #{result.errors.inspect}")
  end

  return result.to_h
end