Class: Ronin::Recon::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/recon/config.rb

Overview

Represents configuration for the recon engine.

Defined Under Namespace

Classes: Workers

Constant Summary collapse

DEFAULT_PATH =

The path to the ~/.config/ronin-recon/config.yml file.

File.join(Core::Home.config_dir('ronin-recon'),'config.yml')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workers: Workers.default, params: {}, concurrency: {}) ⇒ Config

Initializes the recon engine configuration.

Parameters:

  • workers (Workers) (defaults to: Workers.default)

    The workers to use.

  • params (Hash{String => Hash{Symbol => Object}}) (defaults to: {})

    The params for individual workers.

  • concurrency (Hash{String => Hash{Symbol => Object}}) (defaults to: {})

    The concurrency values for individual workers.



210
211
212
213
214
# File 'lib/ronin/recon/config.rb', line 210

def initialize(workers: Workers.default, params: {}, concurrency: {})
  @workers     = workers
  @params      = params
  @concurrency = concurrency
end

Instance Attribute Details

#concurrencyHash{String => Integer} (readonly)

Concurrency values for individual workers.

Returns:

  • (Hash{String => Integer})


196
197
198
# File 'lib/ronin/recon/config.rb', line 196

def concurrency
  @concurrency
end

#paramsHash{String => Hash{Symbol => Object}} (readonly)

Params for individual workers.

Returns:

  • (Hash{String => Hash{Symbol => Object}})


189
190
191
# File 'lib/ronin/recon/config.rb', line 189

def params
  @params
end

#workersWorkers

The workers to use.

Returns:



182
183
184
# File 'lib/ronin/recon/config.rb', line 182

def workers
  @workers
end

Class Method Details

.defaultConfig

The default configuration to use.

Returns:



321
322
323
324
325
326
327
# File 'lib/ronin/recon/config.rb', line 321

def self.default
  if File.file?(DEFAULT_PATH)
    load(DEFAULT_PATH)
  else
    new
  end
end

.load(path) ⇒ Object

Loads configuration from a YAML file.

Parameters:

  • path (String)

    The path to the YAML configuration file.

Raises:



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/ronin/recon/config.rb', line 290

def self.load(path)
  yaml = YAML.load_file(path)

  begin
    validate(yaml)
  rescue InvalidConfig => error
    raise(InvalidConfigFile,"invalid config file (#{path.inspect}): #{error.message}")
  end

  workers = if (workers_value = yaml[:workers])
              Workers.new(workers_value)
            else
              Workers.default
            end

  params      = yaml.fetch(:params,{})
  concurrency = yaml.fetch(:concurrency,{})

  return new(workers: workers, params: params, concurrency: concurrency)
end

.validate(data) ⇒ true

Validates the loaded configuration data.

Parameters:

  • data (Object)

    The loaded configuration data.

Returns:

  • (true)

    The configuration data is valid.

Raises:

  • (InvalidConfig)

    The configuration data is not a Hash, does not contain Symbol keys, or does not contain Hashes.



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/ronin/recon/config.rb', line 229

def self.validate(data)
  unless data.kind_of?(Hash)
    raise(InvalidConfig,"must contain a Hash: #{data.inspect}")
  end

  if (workers = data[:workers])
    unless (workers.kind_of?(Hash) || workers.kind_of?(Array))
      raise(InvalidConfig,"workers value must be a Hash or an Array: #{workers.inspect}")
    end
  end

  if (params_value = data[:params])
    unless params_value.kind_of?(Hash)
      raise(InvalidConfig,"params value must be a Hash: #{params_value.inspect}")
    end

    params_value.each do |worker_id,params_hash|
      unless worker_id.kind_of?(String)
        raise(InvalidConfig,"worker ID must be a String: #{worker_id.inspect}")
      end

      unless params_hash.kind_of?(Hash)
        raise(InvalidConfig,"params value for worker (#{worker_id.inspect}) must be a Hash: #{params_hash.inspect}")
      end

      params_hash.each_key do |param_key|
        unless param_key.kind_of?(Symbol)
          raise(InvalidConfig,"param key for worker (#{worker_id.inspect}) must be a Symbol: #{param_key.inspect}")
        end
      end
    end
  end

  if (concurrency_value = data[:concurrency])
    unless concurrency_value.kind_of?(Hash)
      raise(InvalidConfig,"concurrency value must be a Hash: #{concurrency_value.inspect}")
    end

    concurrency_value.each do |worker_id,concurrency|
      unless worker_id.kind_of?(String)
        raise(InvalidConfig,"worker ID must be a String: #{worker_id.inspect}")
      end

      unless concurrency.kind_of?(Integer)
        raise(InvalidConfig,"concurrency value for worker (#{worker_id.inspect}) must be an Integer: #{concurrency.inspect}")
      end
    end
  end

  return true
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Compares the configuration with another object.

Parameters:

  • other (Object)

    The other object.

Returns:

  • (Boolean)


360
361
362
363
364
365
# File 'lib/ronin/recon/config.rb', line 360

def eql?(other)
  self.class == other.class &&
    @workers     == other.workers &&
    @params      == other.params &&
    @concurrency == other.concurrency
end