Class: Workers::Import
- Inherits:
-
Object
- Object
- Workers::Import
- 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
type
s 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
-
#perform(params) ⇒ Object
Processes an
import
job. -
#validate(params) ⇒ Hash{Symbol => Object}
Validates the given job params.
Instance Method Details
#perform(params) ⇒ Object
Processes an import
job.
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.
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 |