philae 0.2.7 → 0.2.8

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: e3070e46c6e7ad456cb58aae15d48fb71a9be1ec
4
- data.tar.gz: f725eefd0197db384c7b9f2bbadb24af57572a8a
3
+ metadata.gz: c89dc51a566e3ab1b66da0e01b73f7203a571994
4
+ data.tar.gz: 2c226f8704ce011064bc1d459e3e64dcfc14103f
5
5
  SHA512:
6
- metadata.gz: 221ed7de887838a7f07c526606d8f3f8b4265ad2aee873da6a969302c53dda543044f2f6f7e7604f1be41f3eaa8eef084a91d6ee030ea43ac2da26847c3ca713
7
- data.tar.gz: a9d0f3571f98918907a90a01476d824385768e1f1dfc868ff1af82ed7a50f399c4cd0f3c73f87e069fa0cf4b52c08d18b5c7e34ebe3eb9f53f85895ac7193384
6
+ metadata.gz: 0e7868bab5c1a030919830409f8ed852e0be2a21ed08d6f75578b0ac052161fc416eb7b9d67278673b27d7e9a0ab3b58b294609bf76d49a16733d4ee36a115ab
7
+ data.tar.gz: 4c1dc3bd083e810d0ca158300f3d4b10eaba05624c0012693a1c7c3cfd548229d681bb2775cfb352281b5ae2ce4b8d6716c767e98b932d0f750244cc8b8d5ae8
@@ -1,27 +1,45 @@
1
1
  require 'net/http'
2
+ require 'openssl'
2
3
 
3
4
  module Philae
4
5
  class HttpProbe
5
6
  attr_reader :name
6
7
 
7
- def initialize(name, uri, username = nil, password = nil)
8
+ # tls_context:
9
+ # {
10
+ # cert: "path/to/cert",
11
+ # key: "path/to/key",
12
+ # ca: "path/to/ca"
13
+ # }
14
+ def initialize(name, uri, username = nil, password = nil, tls_context = nil)
8
15
  @name = name
9
16
  @uri = uri
10
17
  @username = username
11
18
  @password = password
19
+ @tls_context = tls_context
12
20
  end
13
21
 
14
22
  def check
15
23
  begin
16
24
  uri = URI(@uri)
25
+ http = Net::HTTP.new(uri.host, uri.port)
26
+ if uri.scheme == "https"
27
+ http.use_ssl = true
28
+ if !@tls_context.nil?
29
+ http.cert = OpenSSL::X509::Certificate.new(File.read(@tls_context[:cert]))
30
+ http.key = OpenSSL::PKey::RSA.new(File.read(@tls_context[:key]))
31
+ http.ca_file = @tls_context[:ca]
32
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
33
+ end
34
+ end
17
35
  req = Net::HTTP::Get.new(uri)
18
36
  req.basic_auth @username, @password if !@username.nil? || !@password.nil?
19
- resp = Net::HTTP.start(uri.hostname, uri.port) do |http|
20
- http.request(req)
37
+ resp = http.start do |httpconn|
38
+ httpconn.request(req)
21
39
  end
22
- return { healthy: false, comment: 'Invalid response code' } if resp.code.to_s[0] != '2' && resp.code.to_s[0] != '3'
23
- rescue
24
- return { healthy: false, comment: 'Unable to contact server' }
40
+ return { healthy: false, comment: 'Invalid response code', code: resp.code.to_s } if resp.code.to_s[0] != '2' && resp.code.to_s[0] != '3'
41
+ rescue => e
42
+ return { healthy: false, comment: 'Unable to contact server', error: "#{e.class}: #{e.message}" }
25
43
  end
26
44
  { healthy: true, comment: '' }
27
45
  end
@@ -2,9 +2,14 @@ require File.join File.dirname(__FILE__), 'http_probe.rb'
2
2
 
3
3
  module Philae
4
4
  class NSQProbe < HttpProbe
5
- def initialize(name, host, port = 4151)
5
+ def initialize(name, host, port = 4151, tls_context = nil)
6
6
  @name = name
7
- @uri = "http://#{host}:#{port}/ping"
7
+ scheme = "http"
8
+ if !tls_context.nil?
9
+ scheme = "https"
10
+ end
11
+ @uri = "#{scheme}://#{host}:#{port}/ping"
12
+ @tls_context = tls_context
8
13
  end
9
14
  end
10
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - leo@scalingo.com
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.6.11
106
+ rubygems_version: 2.6.13
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Provide an health check api