Class: IPAddr
- Inherits:
-
Object
- Object
- IPAddr
- Defined in:
- lib/azure/storage/common/core/utility.rb
Overview
Code validate private/public IP acceptable ranges.
Class Method Summary collapse
- .address_prefix(ip, cidr) ⇒ Object
- .valid?(ip) ⇒ Boolean
- .validate_address_space(ip) ⇒ Object
- .validate_ip_and_prefix(ip, cidr) ⇒ Object
Instance Method Summary collapse
Class Method Details
.address_prefix(ip, cidr) ⇒ Object
247 248 249 |
# File 'lib/azure/storage/common/core/utility.rb', line 247 def address_prefix(ip, cidr) ip + "/" + cidr.to_s end |
.valid?(ip) ⇒ Boolean
251 252 253 |
# File 'lib/azure/storage/common/core/utility.rb', line 251 def valid?(ip) (IPAddr.new(ip) rescue nil).nil? end |
.validate_address_space(ip) ⇒ Object
239 240 241 242 243 244 245 |
# File 'lib/azure/storage/common/core/utility.rb', line 239 def validate_address_space(ip) if ip.split("/").size != 2 raise "Cidr is invalid for IP #{ip}." elsif valid?(ip) raise "Address space '#{ip}' is invalid." end end |
.validate_ip_and_prefix(ip, cidr) ⇒ Object
229 230 231 232 233 234 235 236 237 |
# File 'lib/azure/storage/common/core/utility.rb', line 229 def validate_ip_and_prefix(ip, cidr) if cidr.to_s.empty? raise "Cidr is missing for IP '#{ip}'." elsif valid?(ip) raise "Ip address '#{ip}' is invalid." elsif !IPAddr.new(ip).private? raise "Ip Address #{ip} must be private." end end |
Instance Method Details
#private? ⇒ Boolean
216 217 218 219 220 221 222 |
# File 'lib/azure/storage/common/core/utility.rb', line 216 def private? return false unless self.ipv4? PRIVATE_RANGES.each do |ipr| return true if ipr.include?(self) end false end |
#public? ⇒ Boolean
224 225 226 |
# File 'lib/azure/storage/common/core/utility.rb', line 224 def public? !private? end |