immosquare-constants 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/immosquare-constants/ip.rb +12 -4
- data/lib/immosquare-constants/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6098bdf582ab7d9829fc6e29756d68ef26001a9afdfcfa87b8ad0e3bc3ea2849
|
|
4
|
+
data.tar.gz: 27aef060a5800c610d82e66adefe8fc6337311b6bb66c0fa9188099aec589887
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fb9cc95875219727e1780a8d5cb4e6dfb511ba17a523302e73530b603039e087689b96e040fef396300e7a61a42eec660027cec3ec727b4c5624ff668fc963a7
|
|
7
|
+
data.tar.gz: 12e6b70b66597ac332c504a760a7747d099b1df954690447abcb0046f92431d018dee74d93b363ea95a5c67d79f863f5812d96bd0401c45181bcda5265bdbb6c
|
|
@@ -6,6 +6,7 @@ require "resolv"
|
|
|
6
6
|
|
|
7
7
|
module ImmosquareConstants
|
|
8
8
|
module Ip
|
|
9
|
+
PUBLIC_IP_TIMEOUT = 2
|
|
9
10
|
##============================================================##
|
|
10
11
|
## Simple class to provide dot notation access to IP addresses
|
|
11
12
|
##============================================================##
|
|
@@ -159,14 +160,21 @@ module ImmosquareConstants
|
|
|
159
160
|
|
|
160
161
|
##============================================================##
|
|
161
162
|
## Get public IP address with fallback
|
|
163
|
+
##
|
|
164
|
+
## Callers run inside web requests (Rack middlewares): without
|
|
165
|
+
## explicit timeouts, Net::HTTP waits up to 60s to connect and
|
|
166
|
+
## 60s to read, so a slow checkip endpoint would hold a server
|
|
167
|
+
## thread for two minutes per request.
|
|
162
168
|
##============================================================##
|
|
163
169
|
def get_public_ip_from_aws
|
|
164
170
|
begin
|
|
165
171
|
begin
|
|
166
|
-
uri
|
|
167
|
-
http
|
|
168
|
-
http.use_ssl
|
|
169
|
-
http.verify_mode
|
|
172
|
+
uri = URI.parse("https://checkip.amazonaws.com/")
|
|
173
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
174
|
+
http.use_ssl = true
|
|
175
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
176
|
+
http.open_timeout = PUBLIC_IP_TIMEOUT
|
|
177
|
+
http.read_timeout = PUBLIC_IP_TIMEOUT
|
|
170
178
|
response = http.get(uri.request_uri)
|
|
171
179
|
raise("No IP found") if !response.is_a?(Net::HTTPSuccess)
|
|
172
180
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: immosquare-constants
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.18
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- immosquare
|
|
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
42
|
version: '0'
|
|
43
43
|
requirements: []
|
|
44
|
-
rubygems_version: 4.0.
|
|
44
|
+
rubygems_version: 4.0.21
|
|
45
45
|
specification_version: 4
|
|
46
46
|
summary: ImmosquareConstants is a comprehensive collection of constants useful for
|
|
47
47
|
a variety of applications.
|