Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site.from_hash cannot consume data generated by Site.to_h #168

Closed
abunn-r7 opened this issue May 5, 2015 · 3 comments
Closed

Site.from_hash cannot consume data generated by Site.to_h #168

abunn-r7 opened this issue May 5, 2015 · 3 comments
Labels

Comments

@abunn-r7
Copy link
Contributor

abunn-r7 commented May 5, 2015

When attempting to import/export a site using the to/from hash methods the gem throws an error when importing.

NoMethodError: undefined method `each' for nil:NilClass
        from /home/abunn/.rvm/gems/ruby-2.2.0/gems/nexpose-1.0.0/lib/nexpose/site.rb:440:in `from_hash'
        from (irb):8
        from /home/abunn/.rvm/rubies/ruby-2.2.0/bin/irb:11:in `<main>'

This appears to be due to the Site object in the 1.0 gem changing the :addresses attribute to :included_scan_targets, but the from_hash method not being updated.

@asalazar-r7 asalazar-r7 added the Bug label May 5, 2015
@sgreen-r7
Copy link
Contributor

Prep Export:
# Write the site configuration to a file.
site = Site.load(nsc, site_id)
File.write("site-#{site_id}.bak", site.to_json)

Import from json export into new Site:
site_bak = JSON.parse(File.read("site-#{ARGV[1]}.bak"))
site = Site.from_hash(site_bak)
site.id = -1
# Set to use the local scan engine.
site.engine_id = nsc.engines.find { |e| e.name == 'Local scan engine' }.id
site_id = site.save(nsc)

Failure happens during:
site = Site.from_hash(site_bak)
trying to access key as symbol, but it only responses to string

@sgreen-r7
Copy link
Contributor

For now, the solution could be telling the JSON.parse to symbolize_names
site_bak = JSON.parse(File.read("site-#{ARGV[1]}.bak”), symbolize_names: true)

@sgreen-r7
Copy link
Contributor

@abunn-r7 Planning on just closing this out. Do we need to fix this in the gem or just use the solution provided? site_bak = JSON.parse(File.read("site-#{ARGV[1]}.bak”), symbolize_names: true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants