sparoid 2.1.0 → 2.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df9de779b1b4fcfd29f3f0ad3ad986001ecc39b61fbe3aeff36c9b3cb5409327
4
- data.tar.gz: 56789005516d3c0c2e3b4799f1cf3d6c9873465ff3516b27edee0649b2f5d373
3
+ metadata.gz: e31fd430f74d9eabc1cae19dfe70b1ad40511850ecf77d1e5b436e5dfc206836
4
+ data.tar.gz: 6fc3c4fa8f4a9e0cc2d63e26138e89b03c689481c1a3b42be46493aad653d2ae
5
5
  SHA512:
6
- metadata.gz: ce6cca5c5219a9f7f99fb6fa34b16efee1d60acae4e5f6bf639524e8ebfd5d4cc805953e9df48656aae11211b25aa824b28751478691a8a293ad3704bd464416
7
- data.tar.gz: bc288e38f49a5c54f10f338d943169dd662932f516fbdccc6c7d5dc75857da7e0c73dbf2dcb3e5082ee7e769f70552deb12f23a11f8f5cca7f993cc4d6104ad0
6
+ metadata.gz: c445dc3e34df5a0a51c654d0e8447a7d96cb8ba675d105680bfa74a0b0fdedc98364123a375ac3fe7213e1c17200b1ce1181a19f944d22f4998d2f730239bfdd
7
+ data.tar.gz: 3a91e79c4030419da559578051f4abef33aceaa8e20a3fd1a3202959342030941f5d6bb7c33e31fe1dfa2107dea2b63bcda1719eb2b50cd0551a23630b5f1c78
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sparoid
4
- VERSION = "2.1.0"
4
+ VERSION = "2.1.1"
5
5
  end
data/lib/sparoid.rb CHANGED
@@ -4,7 +4,7 @@ require_relative "sparoid/version"
4
4
  require "socket"
5
5
  require "openssl"
6
6
  require "resolv"
7
- require "timeout"
7
+ require "net/http"
8
8
 
9
9
  # Single Packet Authorisation client
10
10
  module Sparoid # rubocop:disable Metrics/ModuleLength
@@ -182,25 +182,15 @@ module Sparoid # rubocop:disable Metrics/ModuleLength
182
182
  end
183
183
  end
184
184
 
185
- def public_ips(port = 80) # rubocop:disable Metrics/AbcSize
185
+ def public_ips(port = 80)
186
186
  URLS.map do |host|
187
- Timeout.timeout(5) do
188
- Socket.tcp(host, port, connect_timeout: 3, resolv_timeout: 3) do |sock|
189
- sock.sync = true
190
- sock.print "GET / HTTP/1.1\r\nHost: #{host}\r\nConnection: close\r\n\r\n"
191
- status = sock.readline(chomp: true)
192
- raise(ResolvError, "#{host}:#{port} response: #{status}") unless status.start_with? "HTTP/1.1 200 "
193
-
194
- content_length = 0
195
- until (header = sock.readline(chomp: true)).empty?
196
- if (m = header.match(/^Content-Length: (\d+)/))
197
- content_length = m[1].to_i
198
- end
199
- end
200
- ip = sock.read(content_length).chomp
201
- string_to_ip(ip)
202
- end
203
- end
187
+ http = Net::HTTP.new(host, port)
188
+ http.open_timeout = 3
189
+ http.read_timeout = 5
190
+ response = http.get("/")
191
+ raise(ResolvError, "#{host}:#{port} response: #{response.code}") unless response.is_a?(Net::HTTPSuccess)
192
+
193
+ string_to_ip(response.body.chomp)
204
194
  rescue StandardError
205
195
  nil
206
196
  end.compact
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Hörberg