Class: Ronin::Recon::Config
- Inherits:
-
Object
- Object
- Ronin::Recon::Config
- 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
-
#concurrency ⇒ Hash{String => Integer}
readonly
Concurrency values for individual workers.
-
#params ⇒ Hash{String => Hash{Symbol => Object}}
readonly
Params for individual workers.
-
#workers ⇒ Workers
The workers to use.
Class Method Summary collapse
-
.default ⇒ Config
The default configuration to use.
-
.load(path) ⇒ Object
Loads configuration from a YAML file.
-
.validate(data) ⇒ true
Validates the loaded configuration data.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
Compares the configuration with another object.
-
#initialize(workers: Workers.default, params: {}, concurrency: {}) ⇒ Config
constructor
Initializes the recon engine configuration.
Constructor Details
#initialize(workers: Workers.default, params: {}, concurrency: {}) ⇒ Config
Initializes the recon engine configuration.
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
#concurrency ⇒ Hash{String => Integer} (readonly)
Concurrency values for individual workers.
196 197 198 |
# File 'lib/ronin/recon/config.rb', line 196 def concurrency @concurrency end |
#params ⇒ Hash{String => Hash{Symbol => Object}} (readonly)
Params for individual workers.
189 190 191 |
# File 'lib/ronin/recon/config.rb', line 189 def params @params end |
#workers ⇒ Workers
The workers to use.
182 183 184 |
# File 'lib/ronin/recon/config.rb', line 182 def workers @workers end |
Class Method Details
.default ⇒ Config
The default configuration to use.
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.
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.}") 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.
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.
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 |