Skip to content

Commit

Permalink
Add Ronin::Recon::Config#to_yaml method
Browse files Browse the repository at this point in the history
  • Loading branch information
moozzi committed Aug 31, 2024
1 parent 2338010 commit aecf45e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/ronin/recon/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ def eql?(other)

alias == eql?

#
# Converts workers ids to array
#
# @return [Array<String>]
#
# @since 0.2.0
#
def as_yaml
@ids.to_a
end

end

# The workers to use.
Expand Down Expand Up @@ -366,6 +377,25 @@ def eql?(other)

alias == eql?

#
# Converts config into YAML string.
#
# @params [Hash{Symbol => Object}] options
# Additional options for Object#to_yaml.
#
# @return [String]
#
# @since 0.2.0
#
def to_yaml(options={})
data = {}

data[:params] = @params unless @params.empty?
data[:concurrency] = @concurrency unless @concurrency.empty?
data[:workers] = @workers.as_yaml if @workers

data.to_yaml(options)
end
end
end
end
10 changes: 10 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,14 @@
end
end
end

describe "#to_yaml" do
let(:expected_yml) { File.join(fixtures_dir,'with_params_and_workers.yml') }

subject { described_class.load(expected_yml) }

it "must convert Config into YAML string" do
expect(subject.to_yaml).to eq(File.read(expected_yml))
end
end
end
24 changes: 24 additions & 0 deletions spec/fixtures/config/with_params_and_workers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
:params:
test/worker1:
:foo: a
:bar: b
test/worker2:
:foo: x
:bar: "y"
:workers:
- dns/lookup
- dns/mailservers
- dns/nameservers
- dns/reverse_lookup
- dns/srv_enum
- dns/subdomain_enum
- dns/suffix_enum
- net/ip_range_enum
- net/port_scan
- net/service_id
- ssl/cert_grab
- ssl/cert_enum
- web/dir_enum
- web/email_addresses
- web/spider

0 comments on commit aecf45e

Please sign in to comment.