Module: AwsIpUtilities
- Defined in:
- lib/aws_ip_utilities.rb,
lib/aws_ip_utilities/version.rb
Defined Under Namespace
Modules: RackRequestTrustedProxyOverride
Classes: Prefix
Constant Summary
collapse
- PREFIXES =
JSON.parse(File.read(__dir__ + '/aws_ip_utilities/ip-ranges.json'), symbolize_names: true).fetch(:prefixes).map do |prefix|
ipaddr = IPAddr.new(prefix.fetch(:ip_prefix))
Prefix.new(ipaddr, prefix.fetch(:region), prefix.fetch(:service))
end
- VERSION =
"0.3.1568838788"
- SYNC_TOKEN =
"1568838788"
Class Method Summary
collapse
Class Method Details
.aws_ip?(ip_addr_string) ⇒ Boolean
18
19
20
|
# File 'lib/aws_ip_utilities.rb', line 18
def self.aws_ip?(ip_addr_string)
aws_prefix(ip_addr_string) ? true : false
end
|
.aws_prefix(ip_addr_string) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/aws_ip_utilities.rb', line 22
def self.aws_prefix(ip_addr_string)
ip = IPAddr.new(ip_addr_string)
PREFIXES.find { |subnet| subnet.include?(ip) }
rescue IPAddr::InvalidAddressError
nil
end
|
.make_aws_rack_trusted_proxy! ⇒ Object
41
42
43
44
|
# File 'lib/aws_ip_utilities.rb', line 41
def self.make_aws_rack_trusted_proxy!
require_relative 'aws_ip_utilities/rack_request_trusted_proxy_override'
Rack::Request.prepend(AwsIpUtilities::RackRequestTrustedProxyOverride)
end
|
.region_for(ip_addr_string) ⇒ Object
29
30
31
32
33
|
# File 'lib/aws_ip_utilities.rb', line 29
def self.region_for(ip_addr_string)
if prefix = aws_prefix(ip_addr_string)
prefix.region
end
end
|
.service_for(ip_addr_string) ⇒ Object
35
36
37
38
39
|
# File 'lib/aws_ip_utilities.rb', line 35
def self.service_for(ip_addr_string)
if prefix = aws_prefix(ip_addr_string)
prefix.service
end
end
|