-
Notifications
You must be signed in to change notification settings - Fork 103
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
Site api blackouts #150
Changes from 1 commit
dc4d97e
a2e7a3d
4526edb
0ff1790
f16e9d8
aa56ca3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,6 +300,53 @@ module Type | |
end | ||
end | ||
|
||
# Configuration structure for blackouts. | ||
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 | ||
# The repeat interval based upon type. | ||
attr_accessor :interval | ||
# The earliest date to generate the report on (in ISO 8601 format). | ||
attr_accessor :start | ||
# The amount of time, in minutes, a blackout period should last. | ||
attr_accessor :duration | ||
# The timezone in which the blackout will start | ||
attr_accessor :timezone | ||
|
||
def initialize(start, enabled=true, duration, timezone, type, interval) | ||
@blackout_start = start | ||
@enabled =enabled | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surrounding space missing for operator '='. |
||
@blackout_duration = duration.to_i | ||
@blackout_timezone = timezone | ||
@blackout_type = type | ||
@blackout_interval = interval.to_i | ||
end | ||
|
||
def self.from_hash(hash) | ||
repeat_scan_hash = hash[:repeat_scan] | ||
blackout = new(hash[:start], hash[:duration], hash[:timezone]) | ||
blackout.type = repeat_scan_hash[:type] | ||
blackout.interval = repeat_scan_hash[:interval] | ||
blackout | ||
end | ||
|
||
def to_h | ||
blackout_hash = { | ||
start_date: @blackout_start, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is. |
||
enabled: @enabled, | ||
blackout_duration: @blackout_duration, | ||
timezone: @blackout_timezone | ||
} | ||
repeat_hash= { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surrounding space missing for operator '='. |
||
type: @blackout_type, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is. |
||
interval: @blackout_interval } | ||
blackout_hash[:repeat_blackout] = repeat_hash | ||
blackout_hash | ||
end | ||
end | ||
|
||
# Organization configuration, as used in Site and Silo. | ||
class Organization < APIObject | ||
attr_accessor :name | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Nexpose | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at module body beginning. |
||
class Global_Blackout < APIObject | ||
include JsonSerializer | ||
|
||
# [Array] Blackout starting dates, times and duration for blackout periods. | ||
attr_accessor :blackout | ||
|
||
def initialize (blackout) | ||
@global_blackout = Array(blackout) | ||
end | ||
|
||
def save(nsc) | ||
params = to_json | ||
puts params | ||
JSON.parse(AJAX.post(nsc, '/api/2.1/silo_blackout/', params, AJAX::CONTENT_TYPE::JSON)) | ||
end | ||
|
||
def to_h | ||
{ | ||
blackouts: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is. |
||
(@global_blackout || []).map { |blackout| blackout.to_h } | ||
} | ||
end | ||
|
||
def to_json | ||
JSON.generate(to_h) | ||
end | ||
|
||
def self.json_initializer(data) | ||
new(blackout: data) | ||
end | ||
|
||
require 'json' | ||
|
||
def self.load(nsc) | ||
uri = '/api/2.1/silo_blackout/' | ||
resp = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON) | ||
hash = JSON.parse(resp, symbolize_names: true) | ||
blackout = self.json_initializer(hash).deserialize(hash) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant |
||
blackout.blackout = (hash[:blackouts] || []).map { |blackout| Nexpose::Blackout.from_hash(blackout) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shadowing outer local variable - |
||
blackout | ||
end | ||
end | ||
end | ||
|
||
|
||
|
There was a problem hiding this comment.
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.