gogetit 0.12.1 → 0.12.2

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
  SHA1:
3
- metadata.gz: 189676ebde7be09dac5cc9fd4758310439c4bd7a
4
- data.tar.gz: a80deb5871078c52242bac81b2c12729ee9db3d1
3
+ metadata.gz: 61751267d26d38a3483ce27309262a216614f6a1
4
+ data.tar.gz: 4ca2a6149614790a782b225786f16f8707f87a86
5
5
  SHA512:
6
- metadata.gz: 8316d03160b682203350a40537b63f98f7bc33b149cef1dbac71704efc902243a071a4723b48da6de0c87083d2f7d9d1af879fd281fc5dd8bb3a188f64db65f5
7
- data.tar.gz: 1cb05e46d94d20c88a4fd86aef25e39d943e27f2d91da42a1eafb336fed0f0a6164d31bea0e8561f0199b8e063e0792a64d9f96d1565220c82a8f800c499ebd2
6
+ metadata.gz: 39493d947b7aa4464abdbcf49770911662b349461a151a2c9584d1f768c929cf17f1c03818b5ba86ee0797265affe056680693f8a156f3b7474cc547ee1f59fa
7
+ data.tar.gz: b90078303ea89a51598197c789b9b6ba8ac8d87da3368c9e0df19abaf7ac5fd724a9461e59375b2b7ad1027acdf06a6ed07bd779115208317ea700ee7c53c6e0
data/lib/gogetit/util.rb CHANGED
@@ -3,6 +3,8 @@ require 'net/ssh'
3
3
  require 'net/http'
4
4
  require 'active_support/core_ext/hash'
5
5
  require 'json'
6
+ require 'socket'
7
+ require 'timeout'
6
8
 
7
9
  module Gogetit
8
10
  module Util
@@ -11,16 +13,40 @@ module Gogetit
11
13
  system(cmd)
12
14
  end
13
15
 
16
+ def is_port_open?(ip, port)
17
+ begin
18
+ Timeout::timeout(1) do
19
+ begin
20
+ s = TCPSocket.new(ip, port)
21
+ s.close
22
+ return true
23
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError
24
+ return false
25
+ end
26
+ end
27
+ rescue Timeout::Error
28
+ end
29
+
30
+ return false
31
+ end
32
+
14
33
  def get_http_content(url)
15
34
  logger.info("Calling <#{__method__.to_s}> to get #{url}")
35
+
16
36
  uri = URI.parse(url)
17
- http = Net::HTTP.new(uri.host, uri.port)
18
- res = http.request_post(uri.path, nil)
19
- if res.code == "200"
20
- res.body
37
+
38
+ if is_port_open?(uri.host, uri.port)
39
+ http = Net::HTTP.new(uri.host, uri.port)
40
+ res = http.request_post(uri.path, nil)
41
+ if res.code == "200"
42
+ res.body
43
+ else
44
+ logger.info("Unable to reach the content of #{url}.")
45
+ false
46
+ end
21
47
  else
22
- logger.info("Unable to reach #{url}.")
23
- nil
48
+ logger.info("Unable to reach the server: #{uri.host} or port: #{uri.port}.")
49
+ false
24
50
  end
25
51
  end
26
52
 
@@ -1,3 +1,3 @@
1
1
  module Gogetit
2
- VERSION = "0.12.1"
2
+ VERSION = "0.12.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gogetit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Don Draper