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

Update Global Settings #87

Merged
merged 3 commits into from
Nov 4, 2014
Merged

Conversation

erran
Copy link
Contributor

@erran erran commented Nov 3, 2014

@mdaines-r7 (@defndaines) Can you check this PR out? I'd like to get it merged for some automated tests I'm working on right now.

@erran erran force-pushed the controls-scanning-setting branch from 9b8fcca to 8dcc26a Compare November 3, 2014 20:45
@erran-r7
Copy link
Contributor

erran-r7 commented Nov 3, 2014

# Before updating the Nexpose gem
When(/^I (disable|enable) the global setting for Controls Scanning$/) do |action|
  state_for_action =
    case action
    when 'disable' then '0'
    when 'enable' then '1'
    end

  global_settings_response = Nexpose::AJAX.get(@nexpose_client, '/data/admin/global-settings')
  global_settings = REXML::Document.new(global_settings_response)

  controls_scan = REXML::XPath.first(global_settings, 'GlobalSettings/ControlsScan')
  enable_controls_scan = REXML::XPath.first(controls_scan, 'enableControlsScan')

  enable_controls_scan.add_attribute('enabled', state_for_action)
  # This would fail for some reason.
  Nexpose::AJAX.post(@nexpose_client, '/data/admin/global-settings', global_settings)
end
# After (without #87)
When(/^I (disable|enable) the global setting for Controls Scanning$/) do |action|
  global_settings = Nexpose::GlobalSettings.load(@nexpose_client)

  case action
  when 'disable'
    global_settings._set_controls_scanning(global_settings.xml, false)
  when 'enable'
    global_settings._set_controls_scanning(global_settings.xml, true)
  end

  global_settings.save(@nexpose_client)
end
# After (with #87)
When(/^I (disable|enable) the global setting for Controls Scanning$/) do |action|
  global_settings = @nexpose_client.global_settings

  case action
  when 'disable'
    global_settings.controls_scanning = false
  when 'enable'
    global_settings.controls_scanning = true
  end

  global_settings.save(@nexpose_client)
end

cc: @nbibinagar-r7

# Internal method for updating exclusions before saving.
def _replace_exclusions(xml, exclusions)
def replace_exclusions(xml, exclusions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change all the names? There a fairly strong convention across the gem to use the underscore to indicate the private methods that are meant for internal utility.

Also, I've had some problems using private methods in the gem. I cannot remember what the problems were, but it's one of the reasons for adding the naming conventions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen similar naming conventions in JS. I knew what was being done but since Ruby provides privacy levels I opt'd to remove the unneeded convention in this particular case.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw this comment come through, so I'll pile on. :) In Ruby, you rarely see folks using the prepended underscore to indicate private methods, since you can enforce method hiding with the private keyword. You are forbidden from calling private methods outside of the class in which they are declared, which could be the cause of the issues you're seeing.

@erran erran force-pushed the controls-scanning-setting branch from bd87264 to 9b17cd5 Compare November 3, 2014 21:54
@erran erran force-pushed the controls-scanning-setting branch from 9b17cd5 to 144c5ca Compare November 4, 2014 18:46
@erran-r7
Copy link
Contributor

erran-r7 commented Nov 4, 2014

@mdaines-r7 I've removed Nexpose::Connection#global_settings

mdaines-r7 added a commit that referenced this pull request Nov 4, 2014
@mdaines-r7 mdaines-r7 merged commit e82647e into rapid7:master Nov 4, 2014
@erran erran deleted the controls-scanning-setting branch November 4, 2014 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants