-
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
Remove asset from range #156
Changes from 3 commits
fbf70b0
f455b92
dcbb04d
b3bb3de
c7f2299
ef98f3e
a9f24c3
a322a17
81040b8
8b13bca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,9 +203,50 @@ def add_ip(ip) | |
# | ||
# @param [String] ip IP address of an asset. | ||
def remove_ip(ip) | ||
@assets = assets.reject { |asset| asset == IPRange.new(ip) } | ||
ip = IPRange.new(ip) | ||
@assets.each do |asset_range| | ||
next if asset_range.is_a?(Nexpose::HostName) | ||
if asset_range.include?(ip) | ||
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. How about an early return ( |
||
asset = split_ip_range(asset_range, ip) | ||
@assets.delete(asset_range) | ||
@assets.push(asset) | ||
@assets.flatten! | ||
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. Instead of calling assets += Array(asset) |
||
end | ||
end | ||
end | ||
|
||
|
||
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 blank line detected. |
||
def split_ip_range(ip_range, split_ip) | ||
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. Assignment Branch Condition size for split_ip_range is too high. [25.16/15] 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. Assignment Branch Condition size for split_ip_range is too high. [25.16/15] |
||
split_ip = IPAddr.new(split_ip.from) | ||
start_ip, end_ip = IPAddr.new(ip_range.from), IPAddr.new(ip_range.to) | ||
all_ip_range = (start_ip..end_ip) | ||
|
||
case split_ip | ||
when all_ip_range.min | ||
new_start = IPAddr.new(start_ip.to_i + 1, start_ip.family).to_s | ||
asset = Nexpose::IPRange.new(new_start, ip_range.to) | ||
when all_ip_range.max | ||
new_end = IPAddr.new(end_ip.to_i - 1, end_ip.family).to_s | ||
asset = Nexpose::IPRange.new(ip_range.from, new_end) | ||
else | ||
asset = ip_range_split_calc(start_ip, end_ip, split_ip) | ||
end | ||
return asset | ||
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 |
||
end | ||
|
||
|
||
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 blank line detected. |
||
def ip_range_split_calc(start_ip, end_ip, split_ip) | ||
low_split = IPAddr.new(split_ip.to_i - 1, start_ip.family).to_s | ||
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. Unnecessary spacing detected. 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. Unnecessary spacing detected. |
||
high_split = IPAddr.new(split_ip.to_i + 1, end_ip.family).to_s | ||
|
||
low_range = Nexpose::IPRange.new(start_ip.to_s, low_split) | ||
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. Unnecessary spacing detected. |
||
high_range = Nexpose::IPRange.new(high_split, end_ip.to_s) | ||
|
||
return [ low_range, high_range ] | ||
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 |
||
end | ||
|
||
|
||
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 blank line detected. |
||
|
||
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 blank line detected. |
||
# Adds assets to this site by IP address range. | ||
# | ||
# @param [String] from Beginning IP address of a range. | ||
|
@@ -725,17 +766,10 @@ def eql?(other) | |
|
||
def include?(single_ip) | ||
return false unless single_ip.respond_to? :from | ||
from = IPAddr.new(@from) | ||
to = @to.nil? ? from : IPAddr.new(@to) | ||
other = IPAddr.new(single_ip) | ||
|
||
if other < from | ||
false | ||
elsif to < other | ||
false | ||
else | ||
true | ||
end | ||
from = IPAddr.new(@from).to_i | ||
to = @to.nil? ? from : IPAddr.new(@to).to_i | ||
other = IPAddr.new(single_ip.from).to_i | ||
(from..to).include?(other) | ||
end | ||
|
||
def hash | ||
|
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.
No reason to use
@assets
instead of theassets
getter method.