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 api blackouts #150

Merged
merged 6 commits into from
Mar 27, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing site and silo blackouts
  • Loading branch information
dmurray-r7 committed Mar 27, 2015
commit f16e9d87a0122a6c6895c9504d4eecedac6f7df3
13 changes: 7 additions & 6 deletions lib/nexpose/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,15 @@ class Blackout < APIObject
# Whether or not this blackout is enabled.
attr_accessor :enabled
# Valid schedule types: daily, hourly, monthly-date, monthly-day, weekly.
attr_accessor :type
attr_accessor :blackout_type
# The repeat interval based upon type.
attr_accessor :interval
attr_accessor :blackout_interval
# The earliest date to generate the report on (in ISO 8601 format).
attr_accessor :start
attr_accessor :blackout_start
# The amount of time, in minutes, a blackout period should last.
attr_accessor :duration
attr_accessor :blackout_duration
# The timezone in which the blackout will start
attr_accessor :timezone
attr_accessor :blackout_timezone

def initialize(start, enabled=true, duration, timezone, type, interval)

Choose a reason for hiding this comment

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

Surrounding space missing in default value assignment.

@blackout_start = start
Expand All @@ -326,7 +326,8 @@ def initialize(start, enabled=true, duration, timezone, type, interval)

def self.from_hash(hash)
repeat_blackout_hash = hash[:repeat_blackout]
blackout = new(hash[:start], hash[:duration], hash[:timezone], repeat_blackout_hash[:type], repeat_blackout_hash[:interval])
blackout = new(hash[:start_date], hash[:blackout_duration], hash[:timezone], repeat_blackout_hash[:type], repeat_blackout_hash[:interval])

Choose a reason for hiding this comment

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

Line is too long. [144/120]

blackout
end

def to_h
Expand Down
1 change: 0 additions & 1 deletion lib/nexpose/global_blackout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def self.json_initializer(data)
def self.load(nsc)
uri = '/api/2.1/silo_blackout/'
resp = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON)
# puts resp
hash = JSON.parse(resp, symbolize_names: true)
blackout = self.json_initializer(hash).deserialize(hash)

Choose a reason for hiding this comment

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

Redundant self detected.

blackout.blackout = (hash[:blackouts] || []).map { |blackout| Nexpose::Blackout.from_hash(blackout) }

Choose a reason for hiding this comment

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

Shadowing outer local variable - blackout.

Expand Down
30 changes: 15 additions & 15 deletions lib/nexpose/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,9 @@ def self.load(nsc, id)
site.alerts = Alert.load_alerts(hash[:alerts])
site.tags = Tag.load_tags(hash[:tags])
site.web_credentials = hash[:web_credentials].map {|webCred| (
webCred[:service] == Nexpose::WebCredentials::WebAppAuthType::HTTP_HEADER ?
Nexpose::WebCredentials::Headers.new(webCred[:name], webCred[:baseURL], webCred[:soft403Pattern], webCred[:id]).object_from_hash(nsc,webCred) :
Nexpose::WebCredentials::HTMLForms.new(webCred[:name], webCred[:baseURL], webCred[:loginURL], webCred[:soft403Pattern], webCred[:id]).object_from_hash(nsc,webCred))}
webCred[:service] == Nexpose::WebCredentials::WebAppAuthType::HTTP_HEADER ?
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not a fan of this whole block here. Needs some better formatting for readability. I'll merge for now, but I want to take another look at this before we release 1.0.

Nexpose::WebCredentials::Headers.new(webCred[:name], webCred[:baseURL], webCred[:soft403Pattern], webCred[:id]).object_from_hash(nsc,webCred) :
Nexpose::WebCredentials::HTMLForms.new(webCred[:name], webCred[:baseURL], webCred[:loginURL], webCred[:soft403Pattern], webCred[:id]).object_from_hash(nsc,webCred))}

site
end
Expand Down Expand Up @@ -556,20 +556,20 @@ def self.copy(connection, id)
# @return [Fixnum] Site ID assigned to this configuration, if successful.
#
def save(connection)
new_site = @id == -1
new_site = @id == -1

if new_site
resp = AJAX.post(connection, '/api/2.1/site_configurations/', to_json, AJAX::CONTENT_TYPE::JSON)
@id = resp.to_i
else
resp = AJAX.put(connection, "/api/2.1/site_configurations/#{@id}", to_json, AJAX::CONTENT_TYPE::JSON)
end
if new_site
resp = AJAX.post(connection, '/api/2.1/site_configurations/', to_json, AJAX::CONTENT_TYPE::JSON)
@id = resp.to_i
else
resp = AJAX.put(connection, "/api/2.1/site_configurations/#{@id}", to_json, AJAX::CONTENT_TYPE::JSON)
end

# Retrieve the scan engine and shared credentials and add them to the site configuration
site_config = Site.load(connection, @id)
@engine_id = site_config.engine_id
@shared_credentials = site_config.shared_credentials
@alerts = site_config.alerts
# Retrieve the scan engine and shared credentials and add them to the site configuration
site_config = Site.load(connection, @id)
@engine_id = site_config.engine_id
@shared_credentials = site_config.shared_credentials
@alerts = site_config.alerts

@id
end
Expand Down